We need to send notification emails when entries of a particular type are created, updated, or enabled/disabled. The entrypoint for this happens in a module's init()
method:
Event::on(Elements::class, Elements::EVENT_AFTER_SAVE_ELEMENT, function (Event $event) {
// do stuff
}
We recently updated to Craft 3.3.0, which resulted in many many many emails being sent. I think these have something to do with queue tasks that are generated as a result of system updates. During the update, the craft_queue
table contains many rows. The first row's description
is "Updating entry drafts and revisions" and the many subsequent rows show a description
value of "Updating element slugs and URIs".
First, is it correct to assume that some system updates trigger queued resaves of all entries?
Second, we need to prevent the notification emails from being sent unless the save event is triggered as the result of a user action. I see the sender
property of ElementEvent
, but it seems that that has to do with the current method and doesn't bubble up the event chain.
We've thought about disabling versions on these entries, but that feels more like a bandaid.
Is there a way to determine the originating source of an ElementEvent's save event? If so, is that the best way to gain more control over when these notification emails are sent? In general, I'm wondering if we can detect whether an element is being saved as the result of a system update/queue task vs a manual user action.