Trigger automation email sent hook for automation emails
[MAILPOET-4977]
This commit is contained in:
@@ -541,12 +541,30 @@ class SendingQueue {
|
||||
|
||||
// log statistics
|
||||
$this->statisticsNewslettersRepository->createMultiple($statistics);
|
||||
|
||||
// update the sent count
|
||||
$this->mailerTask->updateSentCount();
|
||||
|
||||
// enforce execution limits if queue is still being processed
|
||||
if ($task->getStatus() !== ScheduledTaskEntity::STATUS_COMPLETED) {
|
||||
$this->enforceSendingAndExecutionLimits($timer);
|
||||
}
|
||||
|
||||
// trigger automation email sent hook for automation emails
|
||||
if (
|
||||
$task->getStatus() === ScheduledTaskEntity::STATUS_COMPLETED
|
||||
&& isset($task->getMeta()['automation'])
|
||||
) {
|
||||
try {
|
||||
$this->wp->doAction('mailpoet_automation_email_sent', $task->getMeta()['automation']);
|
||||
} catch (Throwable $e) {
|
||||
$this->loggerFactory->getLogger(LoggerFactory::TOPIC_NEWSLETTERS)->error(
|
||||
'Error while executing "mailpoet_automation_email_sent action" hook',
|
||||
['task_id' => $task->getId(), 'error' => $e->getMessage()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->throttlingHandler->processSuccess();
|
||||
}
|
||||
|
||||
|
@@ -1424,6 +1424,22 @@ class SendingQueueTest extends \MailPoetTest {
|
||||
verify($this->entityManager->find(NewsletterEntity::class, $newsletter->getId()))->null();
|
||||
}
|
||||
|
||||
public function testItTriggersAutomationEmailSentHook(): void {
|
||||
$hookTriggered = false;
|
||||
$hook = function() use (&$hookTriggered) {
|
||||
$hookTriggered = true;
|
||||
};
|
||||
$this->wp->addAction('mailpoet_automation_email_sent', $hook, 1);
|
||||
|
||||
$this->scheduledTask->setMeta(['automation' => ['id' => 1, 'run_id' => 1, 'step_id' => 'abc', 'run_number' => 1]]);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$sendingQueueWorker = $this->getSendingQueueWorker();
|
||||
$sendingQueueWorker->process();
|
||||
|
||||
$this->assertSame(true, $hookTriggered);
|
||||
}
|
||||
|
||||
private function createNewsletter(string $type, $subject, string $status = NewsletterEntity::STATUS_DRAFT): NewsletterEntity {
|
||||
$newsletter = new NewsletterEntity();
|
||||
$newsletter->setType($type);
|
||||
|
Reference in New Issue
Block a user