We just updated to 3.2 and for some reason the after entry save event was triggered seven times for a disabled entry with the event saying the entry was new. This in turn triggered an email to be sent 7 times to _a lot_ of people referencing this disabled entry.
It would be really useful to have a config option that would prevent emails from being sent in certain environments, as a precaution against accidentally sending emails from development sites!
@Tam Would testtoemailaddress not work for you? You can set it to a test email for your dev sites.
Configures Craft to send all system emails to a single email address, or an array of email addresses for testing purposes.
https://docs.craftcms.com/v3/config/config-settings.html#testtoemailaddress
@john-henry It absolutely does! Don't know how I missed that, thanks!
Most likely those new entries were drafts/revisions being created for existing entries, as all drafts & revisions in 3.2 are stored as actual elements.
In your afterSave handler, you can check whether the entry is a draft/revision by calling ElementHelper::isDraftOrRevision():
use craft\helpers\ElementHelper;
// ...
if (ElementHelper::isDraftOrRevision($entry) {
return;
}
Thanks @brandonkelly!
Most helpful comment
Most likely those new entries were drafts/revisions being created for existing entries, as all drafts & revisions in 3.2 are stored as actual elements.
In your
afterSavehandler, you can check whether the entry is a draft/revision by calling ElementHelper::isDraftOrRevision():