You are not logged in.
Pages: 1
I've been tasked with sending a notification email once a new item is added through a Module.
I used the Publish hook, before realizing that it will run the thing any time it's published, so each subsequent update, which we don't want.
I'm thinking I just need to check for existence of the record before, but that brings me to a question about how the records work: when you go to add a new item in a Module, does it create the record in that moment, then after filling out the form, it uses an Update action rather than Create? And even still, is there any hook I can use only for Create, and not for Update?
Offline
It does not create a record upon hitting the form, but it does create it prior to the publish hook being run. If you're only interested in sending an email on the initial creation, I would check for the presence of an "update" in the audit trail. Something like this in your publish hook:
$created = !SQL::exists("SELECT * FROM bigtree_audit_trail WHERE `table` = ? AND `entry` = ? AND `type` = 'updated'", $table, $id);
Then you could just send the email if $created.
Offline
I just realized you might not be running > 4.2.21 or whenever the SQL class was introduced, but you could do the same thing using sqlrows(sqlquery( to check the number of rows returned from a query.
Offline
I actually did end up upgrading them to 4.2.23 so I should be good there. I'll try something like that, thanks a ton!
Offline
Pages: 1