From 77003f35e40fed6f1b170739aeeae49be5581d05 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Wed, 14 Aug 2024 11:27:42 +1200 Subject: [PATCH] API Deprecate Versioned::canArchive() --- src/GridFieldArchiveAction.php | 11 ++++++++--- src/Versioned.php | 8 +++++++- src/VersionedGridFieldItemRequest.php | 6 ++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/GridFieldArchiveAction.php b/src/GridFieldArchiveAction.php index 7ac62cb4..e6fee484 100644 --- a/src/GridFieldArchiveAction.php +++ b/src/GridFieldArchiveAction.php @@ -3,6 +3,7 @@ namespace SilverStripe\Versioned; use SilverStripe\Control\Controller; +use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField_ActionMenuItem; use SilverStripe\Forms\GridField\GridField_ActionProvider; @@ -176,7 +177,8 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat return; } - if (!$item->canArchive()) { + $canArchive = !Deprecation::withNoReplacement(fn() => $item->canArchive()); + if ($canArchive) { throw new ValidationException( _t(__CLASS__ . '.ArchivePermissionsFailure', "No archive permissions") ); @@ -196,8 +198,11 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat public function getArchiveAction($gridField, $record) { /* @var DataObject|Versioned $record */ - if (!$record->hasMethod('canArchive') || !$record->canArchive()) { - return null; + if (!$record->hasMethod('canArchive')) { + $canArchive = !Deprecation::withNoReplacement(fn() => $record->canArchive()); + if ($canArchive) { + return null; + } } $title = _t(__CLASS__ . '.Archive', "Archive"); diff --git a/src/Versioned.php b/src/Versioned.php index 2f756266..fc40f2b2 100644 --- a/src/Versioned.php +++ b/src/Versioned.php @@ -1498,16 +1498,18 @@ protected function extendCanUnpublish() * * @param Member $member * @return bool + * @deprecated 5.3.0 Use canDelete() instead. */ public function canArchive($member = null) { + Deprecation::notice('5.3.0', 'Use canDelete() instead.'); if (!$member) { $member = Security::getCurrentUser(); } // Standard mechanism for accepting permission changes from extensions $owner = $this->owner; - $extended = $owner->extendedCan('canArchive', $member); + $extended = Deprecation::withNoReplacement(fn() => $owner->extendedCan('canArchive', $member)); if ($extended !== null) { return $extended; } @@ -1530,8 +1532,12 @@ public function canArchive($member = null) return true; } + /** + * @deprecated 5.3.0 Will be removed without equivalent functionality. + */ protected function extendCanArchive() { + Deprecation::notice('5.3.0', 'Will be removed without equivalent functionality.'); // Prevent canArchive() extending itself return null; } diff --git a/src/VersionedGridFieldItemRequest.php b/src/VersionedGridFieldItemRequest.php index 0ec3ecf8..9f23d801 100644 --- a/src/VersionedGridFieldItemRequest.php +++ b/src/VersionedGridFieldItemRequest.php @@ -5,6 +5,7 @@ use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\Control\HTTPResponse; use SilverStripe\Core\Convert; +use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; @@ -118,7 +119,8 @@ public function doArchive($data, $form) { /** @var Versioned|DataObject $record */ $record = $this->getRecord(); - if (!$record->canArchive()) { + $canArchive = Deprecation::withNoReplacement(fn() => $record->canArchive()); + if (!$canArchive) { return $this->httpError(403); } @@ -293,7 +295,7 @@ protected function addVersionedButtons(DataObject $record, FieldList $actions) $canPublish = $record->canPublish(); $canUnpublish = $record->canUnpublish(); $canEdit = $record->canEdit(); - $canArchive = $record->canArchive(); + $canArchive = Deprecation::withNoReplacement(fn() => $record->canArchive()); // "save", supports an alternate state that is still clickable, but notifies the user that the action is not needed. $noChangesClasses = 'btn-outline-primary font-icon-tick';