Discrepancy in event triggering when deleting/undeleting resources

Hello,

Not too sure this is the appropriate place to post this, so if it’s not I’d appreciate you telling me where to go to :smiley:

First and foremost, I’m working on the french translation of Modx so I apologize if I’m not using the proper english translations in my descriptions, but I do hope it’ll still be understandable.

I was working on some plugins using the Resources events, and I noticed something that bothers me.
There is a clear discrepancy in the way events are triggered depending on how you delete/undelete a resource, here is what I’ve jotted down about the behaviours:

  • First, the setup. A parent resource, containing a few child resources (but behaviour seems to be the same with more parent-children levels).
  1. If you right click on the parent, then click Delete (or go in the form then click the Delete button)

    • Event OnDocFormDelete triggered on the parent resource
    • Event OnResourceDelete triggered on the parent
    • Absolutely NO Event triggered on the child resources, yet they still get marked as deleted (?)
  2. If you right click on the parent then click Undelete (or go in the trash and choose to restore the parent resource)

    • Event OnResourceUndelete triggered on the parent
    • Absolutely NO Event triggered on the child resources, yet they still get undeleted (?)
  3. Go into the parent resource’s form, Parameters tab then check Deleted then save the resource

    • Event OnResourceDelete triggered on the parent
    • Event OnDocFormSave triggered on the parent
    • No OnDocFormDelete event triggered on the parent (?)
    • No Event triggered on child resources, which I suppose is the intended behaviour.
    • No effect on the child resources as well (not deleted), which I suppose is the intended behaviour
  4. Go into the parent resource’s form, Parameters tab then uncheck Deleted then save the resource

    • Event OnResourceUndelete triggered on the parent
    • Event OnDocFormSave triggered on the parent
    • No Event triggered on child resources, which I suppose is the intended behaviour.
    • No effect on the child resources as well (not undeleted if they were marked as deleted), which I suppose is the intended behaviour

Another thing of note, there seems to be no information about which action was performed on the resources, contrary to every other type of object (unless I’ve missed something, there is an “action” property in the plugin/snippet/chunk… objects)

I don’t really know how to end this post, just wanted to ask for thoughts or insights as to why all this functions that way?

Edit:
Since it seems that OnDocFormDelete is the event corresponding to the cascading delete (empyrically, but I might be wrong), I guess what bothers me the most is the following question: How are you supposed to differentiate cases 2 & 4? Go & check each and every child ‘deleted’ state? Am I missing something?

Edit 2: I am working on 2.8.3, will try this on modx 3

Edit 3: Same behaviour on modx 3

The OnResourceDelete has a “children” parameter with the ids of the deleted children.

Maybe a “children” parameter could also be added to the OnResourceUndelete to indicate if any children were undeleted as well.


There is a similar issue on github.

It’s seems that the code was changed. Not sure why the parameter is still missing in the current MODX version.

After checking in the code of the current version, it seems it has never been included into the main branch of modx ?

You’re right. This pull-request wasn’t correct and then the issue was closed without resolving it.

I think for a proper solution you’d have to keep track of which resources are actually undeleted in the unDeleteChildren() function.