silverstripe / silverstripe-versioned

Versioning for Silverstripe model
BSD 3-Clause "New" or "Revised" License
8 stars 36 forks source link

GridField action for deleting/archiving a versioned item #78

Closed kinglozzer closed 6 years ago

kinglozzer commented 6 years ago

This has come up a few times on Slack recently. The default GridFieldDeleteAction doesn’t handle versioning and will remove records from stage but not live, meaning that records are removed from the CMS but still visible on the live site. CMS users are left with no way to recover/remove them as they don’t show up anywhere in the CMS (not sure if/how this might tie into the history viewer).

The obvious solution is to omit the action entirely and force users to click to edit, then choose the appropriate delete type. But given that GridFieldConfig_RecordEditor (and presumably therefore ModelAdmin, though I haven’t checked) provide that action by default, I think we should do something to help out developers as it’s not immediately obvious.

Haven’t thought about it in any great detail, but perhaps if versioned_gridfield_extensions is set we could remove GridFieldDeleteAction and push GridFieldVersionedState instead?

PRs

tractorcow commented 6 years ago

Good idea, related to https://github.com/silverstripe/silverstripe-versioned/issues/71 also for other UX considerations.

chillu commented 6 years ago

We've got tickets for "view archived records" now as well: https://github.com/silverstripe/silverstripe-versioned/issues/38 https://github.com/silverstripe/silverstripe-versioned/issues/91

cwchong commented 6 years ago

I would think its usable if, when versioned_gridfield_extensions is detected, to replace GridFieldDeleteAction with another that has handleAction that simply does $item->deleteFromStage(Versioned::LIVE); before $item->delete();

This way the convenience of a grid delete button is not lost and is consistent with non-versioned grids

dhensby commented 6 years ago

Wasn't there a PR to fix this a while ago which meant that we added GridFieldVersionedState by default to versioned gridfields?

MightyMerio commented 6 years ago

For a temporary solution to my own project right now, can anyone supply an example of how to remove just the delete button from the gridfield columns ? I am attempting this: $conf->removeComponentsByType(GridFieldDeleteAction::class); but to no avail. I would love to just hide teh button for now.

cwchong commented 6 years ago

For a temporary solution to my own project right now, can anyone supply an example of how to remove just the delete button from the gridfield columns ? I am attempting this: $conf->removeComponentsByType(GridFieldDeleteAction::class); but to no avail. I would love to just hide teh button for now.

Looks correct, did you import the class? use SilverStripe\Forms\GridField\GridFieldDeleteAction;

chillu commented 6 years ago

I've just moved this up the backlog, sorry this has dropped off the radar for so long.

MightyMerio commented 6 years ago

Yep. Adding use SilverStripe\Forms\GridField\GridFieldDeleteAction; fixed it! thanks :-)

KINKCreative commented 6 years ago

How about just tapping into the onBeforeDelete() on a versioned DO and archiving it in https://github.com/silverstripe/silverstripe-versioned/blob/1/src/Versioned.php ?

E.g.

public function onBeforeDelete() {
    $this->owner->doArchive();
}
tractorcow commented 6 years ago

The problem is that archiving itself also calls a delete. It would be an infinite loop.

tractorcow commented 6 years ago

Bump. We should be updating GridFieldDeleteAction so that it automatically renamed the delete button as "Archive" for versioned records, and internally called archive.

This component also automatically detects unlink for many_many, so it feels natural to support a third archive mode.

thats4shaw commented 6 years ago

I'm assuming removing GridFieldDeleteAction is still the best work around for this? That's the approach I took a few months back but now struck another case within a ModelAdmin.

axllent commented 6 years ago

I've hit this issue now too - deleted or unlinked records being removed from the CMS (eg ObjectTable) but remaining in ObjectTable_Live. At this point there is no way to remove those stray items. As far as I can the safest solution here is to remove GridFieldDeleteAction but that is just a work-around, not a solution.

thats4shaw commented 6 years ago

Nice little nugget from @tractorcow in https://github.com/silverstripe/silverstripe-versioned/issues/116. Add cascade_deletes to help resolve those stray items on publish.