Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Deprecate Versioned::canArchive() #461

Merged

Conversation

GuySartorelli
Copy link
Member

For versioned records, there is no concept of "deleting" the record - it's either being archived, unpublished, or in rare cases removed from draft but left published.

Previously the canDelete() method has been used to check if a record can be removed from draft specifically for versioned records - which is such a rare edge case it almost doesn't bare thinking about, especially given there's no way to do that purely by interacting with the UI, nor with the web API endpoints available in core or supported modules.

Instead, canDelete() should be used to check if the record can be archived. This reduces cognitive load for developers and is a step towards simplifying the overly-complex versioning system. This is also in keeping with other mechanisms, such as cascade_deletes which cascades archiving for versioned records.

Issue

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));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extendedCan() will result in calling extendCanArchive() which is also deprecated, so we need to wrap this call too.

Comment on lines +1535 to +1540
/**
* @deprecated 5.3.0 Will be removed without equivalent functionality.
*/
protected function extendCanArchive()
{
Deprecation::notice('5.3.0', 'Will be removed without equivalent functionality.');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected methods are part of our definition of public API so we need to deprecate this even though nobody is likely to be calling it directly and it's effectively a no-op.

src/GridFieldArchiveAction.php Outdated Show resolved Hide resolved
@GuySartorelli GuySartorelli force-pushed the pulls/2/deprecate-canarchive branch 2 times, most recently from 77003f3 to 3eefaa5 Compare August 14, 2024 03:33
Comment on lines 199 to 205
if (!$record->hasMethod('canArchive') || !$record->canArchive()) {
if (!$record->hasMethod('canArchive')) {
return null;
}
$canArchive = !Deprecation::withNoReplacement(fn() => $record->canArchive());
if ($canArchive) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to separate these conditions to comply with #461 (comment)

src/GridFieldArchiveAction.php Outdated Show resolved Hide resolved
src/GridFieldArchiveAction.php Outdated Show resolved Hide resolved
@GuySartorelli GuySartorelli force-pushed the pulls/2/deprecate-canarchive branch from 3eefaa5 to 07851ca Compare August 15, 2024 00:20
@emteknetnz emteknetnz merged commit 4bc9abd into silverstripe:2 Aug 15, 2024
8 checks passed
@emteknetnz emteknetnz deleted the pulls/2/deprecate-canarchive branch August 15, 2024 02:00
muskie9 added a commit to muskie9/silverstripe-elemental-baseobject that referenced this pull request Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants