Hi Suite Forums :cheer:
I have been working with logic hooks and I’m trying to figure out how to abort/cancel deleting a record under certain conditions.
from the looks of it, deleted isn’t set until after the before_delete event
so I have attempted to set deleted to 0 during the after_delete event
after the logic hook has ran though, the record is absent from the listview
and inserting the record uuid into the url parameters results in a blank ‘content’ area
also there are no logs to explain the blank page
I know that flipping deleted from 1 to 0 directly in the database with sql or whatever query language (I think mySQL is the only supported DBMS though) brings the record back so I’m a little confused into what’s going on
do I have to directly use sql instead of the bean object to achieve the desired result?
Then you can stop the deletion of the record by declaring
$bean->abort_mark_deleted = 1;
Inside your before_delete hook
Unfortunately this is not upgrade safe, so you would need to mind this, but it’s the only way to go. Even doing $bean->mark_undeleted($id) does not help because it does not recreate a previously deleted relationships which get destroyed when a record is deleted and even if it did it could potentially fire up another logic hook for when the relationship is recreated which could cause problems. So this solution is probably the best way to go.
If you have the experience that that works well, and doesn’t have any unintended side-effects, I would just make a PR and put that into core. It’s low-risk, since only people who use that flag will actually run any new code.
By the way - about your latest video (keep them coming, they’re great!), you mention the problems with that change not being upgrade-safe, but did you know that the Extension mechanism has a possibility to extend Menu.php, that should probably be used and it will get picked up here. Although I never tried it and I am not sure how to do it.
Glad you liked the videos, I have a lot more planned in the future. May be next one will be on how to arrange documentation when dealing with large projects, that should be helpful to people who’re dealing with something a bit more complex.
I’ll have to check out the extension mechanism, thanks!