Incorporate the permanent user deletion sprinkle

This commit is contained in:
2023-07-25 14:21:42 +01:00
parent 243987382a
commit 50b8e02839
18 changed files with 934 additions and 66 deletions

View File

@@ -0,0 +1,42 @@
<?php
/*
* AVSDev UF Tweaks (https://avsdev.uk)
*
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
*/
namespace UserFrosting\Sprinkle\UFTweaks\Database\ModelTraits;
trait UserPermanentlyDeletable {
protected function preventActivityPurge() {
/** @var \UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
$classMapper = static::$ci->classMapper;
/** @var \UserFrosting\Support\Repository\Repository $config */
$config = static::$ci->config;
if ($this->isForceDeleting() && !$config['users.purge_activities']) {
// Keep the activity log, but lose the user field
$classMapper->getClassMapping('activity')::query()
->where('user_id', $this->id)
->update(['user_id' => null]);
$this->refresh();
}
return true;
}
public function bootUserPermanentlyDeletable()
{
static::deleting(function ($user) {
if (!$user->preventActivityPurge()) {
return false;
}
return true;
});
}
}