Incorporate the permanent user deletion sprinkle
This commit is contained in:
42
src/Database/ModelTraits/UserPermanentlyDeletable.php
Normal file
42
src/Database/ModelTraits/UserPermanentlyDeletable.php
Normal 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user