diff --git a/code/SoftDeletable.php b/code/SoftDeletable.php index 486d3d6..7132292 100644 --- a/code/SoftDeletable.php +++ b/code/SoftDeletable.php @@ -6,11 +6,12 @@ use SilverStripe\Forms\FieldList; use SilverStripe\Security\Member; use SilverStripe\ORM\DataExtension; +use SilverStripe\Security\Security; use LeKoala\CmsActions\CustomAction; use SilverStripe\Control\Controller; -use SilverStripe\Core\Config\Configurable; use SilverStripe\Forms\CheckboxField; use SilverStripe\ORM\Queries\SQLSelect; +use SilverStripe\Core\Config\Configurable; /** * Soft delete extension @@ -254,8 +255,12 @@ public function softDelete() throw new LogicException("DataObject::softDelete() called on a DataObject without an ID"); } + $member = Security::getCurrentUser(); + $this->owner->Deleted = date('Y-m-d H:i:s'); - $this->owner->DeletedByID = Member::currentUserID(); + if ($member) { + $this->owner->DeletedByID = $member->ID; + } $this->owner->write(); $this->owner->extend('onAfterSoftDelete', $this->owner); diff --git a/code/SoftDeleteModelAdmin.php b/code/SoftDeleteModelAdmin.php index 687f105..50bf6ea 100644 --- a/code/SoftDeleteModelAdmin.php +++ b/code/SoftDeleteModelAdmin.php @@ -1,6 +1,8 @@ owner->modelClass); + /** @var ModelAdmin|SecurityAdmin $owner */ + $owner = $this->owner; + + // Already done in own extension for SS5 + if ($owner instanceof SecurityAdmin) { + return; + } + if ($singl->hasExtension(SoftDeletable::class)) { /** @var GridField $gridfield */ $gridfield = $form->Fields()->dataFieldByName($this->getSanistedModelClass()); @@ -29,7 +39,7 @@ public function updateEditForm($form) $config = $gridfield->getConfig(); $config->removeComponentsByType(GridFieldDeleteAction::class); - if ($this->owner->config()->softdelete_from_list) { + if ($owner::config()->softdelete_from_list) { $exclude = $this->owner->config()->softdelete_from_list_exclude; if ($exclude && !in_array($this->owner->modelClass, $exclude)) { $config->addComponent(new GridFieldSoftDeleteAction()); diff --git a/code/SoftDeleteSecurityAdmin.php b/code/SoftDeleteSecurityAdmin.php index bdf76c0..111b2be 100644 --- a/code/SoftDeleteSecurityAdmin.php +++ b/code/SoftDeleteSecurityAdmin.php @@ -15,22 +15,9 @@ */ class SoftDeleteSecurityAdmin extends Extension { - protected function getSanistedClass($class) + public function updateEditForm(Form $form) { - return str_replace('\\', '-', $class); - } - - /** - * @return SecurityAdmin - */ - protected function getSecurityAdmin() - { - return $this->owner; - } - - function updateEditForm(Form $form) - { - /* @var $owner SecurityAdmin */ + /** @var SecurityAdmin $owner */ $owner = $this->owner; $memberSingl = singleton(Member::class); @@ -46,7 +33,7 @@ function updateEditForm(Form $form) $config = $gridfield->getConfig(); $config->removeComponentsByType(GridFieldDeleteAction::class); - if ($this->owner->config()->softdelete_from_list) { + if ($owner::config()->softdelete_from_list) { $exclude = $this->owner->config()->softdelete_from_list_exclude; if ($exclude && !in_array($this->owner->modelClass, $exclude)) { $config->addComponent(new GridFieldSoftDeleteAction()); @@ -68,7 +55,7 @@ function updateEditForm(Form $form) $config = $gridfield->getConfig(); $config->removeComponentsByType(GridFieldDeleteAction::class); - if ($this->owner->config()->softdelete_from_list) { + if ($owner::config()->softdelete_from_list) { $config->addComponent(new GridFieldSoftDeleteAction()); } }