We have a Form plugin and an Email plugin. Users can setup the Email Plugin to send off notification emails when a particular Event happens. Some users setup a notification email to be sent when a Form is submitted from the Form plugin.
In a recent upgrade, we needed to migrate all content to the Form plugins entries table. We did so using the
saveFormEntry method in the Form plugin service layer. This means, that each time that we call
saveFormEntry in the migration, if somebody has the Email plugin to send out a notification when a Form Entry is saved, the Event fires and the Email plugin tries to do it's thing.
In our case, this just killed the migration script. Setting the Email plugin to disabled before running the Form migration get's around the issue.
So, what is the best way to handle Events that get triggered during a migration?
One method we've thought of is to just programmatically set the Email plugin to disabled before running our migration. That might work for us, but what if other plugins need to do the same? Do we then need to somehow try to communicate this to everyone who might trigger an email event in a migration?
Another idea we've discussed is what if Craft had something like devMode for while migrations were running. So we could just plan into our Email plugin to only run events when migrationMode = false.
As a general question, are there any benefits to having Events enabled during migrations? Are there any benefits to having plugins enabled during migrations? I'm sure this isn't simply a black and white question, but I'm new to thinking about the complexity of having multiple plugins triggering behaviors in other plugins and don't really like the idea that somebody could accidentally trigger several emails to be sent out while trying to run a migration.
Any thoughts on where this is best handled and if we can take any steps to make our code more robust in handling scenarios like these would be appreciated.