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 Delete deprecated canArchive method #460

Merged

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli commented Aug 13, 2024

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() is now to 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.

Note that if the record has stages and is published, we don't allow users to archive if they can't unpublish.

Issue

Comment on lines 198 to 200
/* @var DataObject|Versioned $record */
if (!$record->hasMethod('canArchive') || !$record->canArchive()) {
/** @var ViewableData|Versioned $record */
if (!$record->has_extension(Versioned::class) || !$record->canDelete()) {
Copy link
Member Author

@GuySartorelli GuySartorelli Aug 13, 2024

Choose a reason for hiding this comment

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

Note that the method check used to be there to distinguish between versioned and unversioned records. has_extension() is the correct way to do that, so we're doing it that way instead.

Comment on lines -193 to +194
* @param DataObject $record
* @param ViewableData $record
Copy link
Member Author

@GuySartorelli GuySartorelli Aug 13, 2024

Choose a reason for hiding this comment

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

semi-unrelated PHPDoc fix - gridfield can accept any viewable data. This class is used to replace the delete button when versioned is installed, regardless of whether the gridfield in use has dataobjects or not.

@GuySartorelli GuySartorelli force-pushed the pulls/3/candelete-is-canarchive branch from fade1ca to b8628ef Compare August 15, 2024 03:25
@emteknetnz emteknetnz merged commit 330bc93 into silverstripe:3 Aug 15, 2024
8 checks passed
@emteknetnz emteknetnz deleted the pulls/3/candelete-is-canarchive branch August 15, 2024 23:30
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