2

So I have a FeedMe task that runs and updates a custom field for a select amount of entries.

In my notification email, I have a custom rule like so:

{% if object.customField | length and object.customField == 'hello' %}{{true}} {{else}} {{false}}{% endif %}

When I run the FeedMe task, the email doesn't get sent but I can see the entries get updated. If I go into the entries and save one manually, then the email sends so it seems that the rule works.

I also went in a plugin and set up the following event listener:

Event::on(
    Elements::class,
    Elements::EVENT_AFTER_SAVE_ELEMENT,
    function(ElementEvent $event) {
        if ($event->element instanceof Entry) {
            $entry = $event->element;

            Craft::info('Entry being updated: ' . $entry->title, __METHOD__);
        }
    }
);

and after I run the FeedMe task again, I check the logs and every entry that was updated by the task is logged as being saved.

In conclusion, I know the entries are being updated and saved by the FeedMe task but the notification email custom rule doesn't trigger unless I manually save the entries.

2
  • 1
    I'll have to look closer at this. My initial guess would be that we are not triggering emails in the task scenario by default because they would also trigger in scenarios such as any ResaveElements task run by Craft or another plugin (say, updating an Entry Title Format and accidentally triggering an email for every entry being resaved in a Section). I will take a closer look and see if this isn't a bug but this may be a scenario where you would need to consider a custom event to target your specific scenario. – Ben Parizek Dec 20 '19 at 14:26
  • @BenParizek Gotcha, thanks for looking into it! – Mr.Smithyyy Dec 20 '19 at 14:35
1

To confirm the behavior here, Sprout Notification Emails only get triggered on web requests and are suppressed for console requests and during updates and migrations. Notification Emails could get triggered in other contexts but you would need to do so programmatically.

Notification Events don't run for console requests

$request = Craft::$app->getRequest();

// Only handle notifications on web requests
if ($request->getIsConsoleRequest()) {
    return false;
}

Notification Events don't run during migrations

if ($request->getIsActionRequest()) {
    $actionSegments = $request->getActionSegments();
    if (
        ArrayHelper::firstValue($actionSegments) === 'updater' ||
        $actionSegments === ['app', 'migrate'] ||
        $actionSegments === ['pluginstore', 'install', 'migrate']
    ) {
        return false;
    }
}

Code examples from Sprout Base Email v1.2.7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.