Rule triggering before custom data on Participant create is available
I may be wrong about this, so apologies if so!
I had a rule that said: When Participant is Added with custom_63 = yes, sign them up for the newsletter and send a welcome email. It was working until around end of March, which may be when I upgraded CiviRules or perhaps Civi itself.
I stepped through the code and it seems that Civirules is unable to find the custom_63 data and therefore the condition fails.
I imagine that this is because Civi core has written a participant record but has not yet written the custom data.
I could imagine that this happens in other places too because civirules is very low-level in terms of entities that it reacts to. It would be good if we had some concept of "gather key data while it's happening, but then let things settle before we jump in". i.e. we could hang about gathering participant ID etc. then after Civi core has finished its thing, start our work.
This might also help with things like Contributions, since a contribution page process may make many 'create' and 'update' calls on the various entities during its execution. e.g. "Contribution created with status Completed" should almost never trigger now that the Order API wants us to always create contribs as incomplete, then complete them with payments.
Thinking of solutions, I'm wondering if any of these are appropriate:
-
I can see lots of "xx entity custom data is changed" triggers. Perhaps I need to write one for Participants. But this feels too specific?
-
I wonder whether we could have an action that took all the trigger data available, stored it somewhere in a queue along with a special user entered command option or tag (e.g. I might use
sign_up_participants
). Then add a trigger that always triggers for cron, which processes the queue, and offers a condition on the command option. This could be a general solution to the problem, and it might also help speed things up in the case that many triggering changes were made at once as much of the work is off-loaded to a patient cron user! -
Or, create a "When participant added date reached"; this would basically always trigger by cron after a participant had been added, again, ensuring that custom data has been written etc. Again, this is quite specific.
-
Have things fire on shutdown, instead of post hooks. That way we know Civi is finished.
-
some elegant simple fix that I haven't thought up!
Thanks in advance for thoughts.