42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?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;
|
|
}
|
|
|
|
static public function bootUserPermanentlyDeletable()
|
|
{
|
|
static::deleting(function ($user) {
|
|
if (!$user->preventActivityPurge()) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
});
|
|
}
|
|
} |