diff --git a/mailpoet/lib/Automation/Engine/Builder/UpdateAutomationController.php b/mailpoet/lib/Automation/Engine/Builder/UpdateAutomationController.php index 1de186e0bd..1d263ed89f 100644 --- a/mailpoet/lib/Automation/Engine/Builder/UpdateAutomationController.php +++ b/mailpoet/lib/Automation/Engine/Builder/UpdateAutomationController.php @@ -2,8 +2,10 @@ namespace MailPoet\Automation\Engine\Builder; +use ActionScheduler_Store; use MailPoet\Automation\Engine\Control\ActionScheduler; use MailPoet\Automation\Engine\Data\Automation; +use MailPoet\Automation\Engine\Data\AutomationRun; use MailPoet\Automation\Engine\Data\Step; use MailPoet\Automation\Engine\Exceptions; use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException; @@ -161,11 +163,13 @@ class UpdateAutomationController { $runIds = []; $runs = $this->automationRunStorage->getAutomationRunsForAutomation($automation); foreach ($runs as $run) { + if ($run->getStatus() === AutomationRun::STATUS_RUNNING) { + $this->automationRunStorage->updateStatus($run->getId(), AutomationRun::STATUS_CANCELLED); + } $runIds[$run->getId()] = $run; } - $actions = $this->actionScheduler->getScheduledActions(['hook' => Hooks::AUTOMATION_STEP, 'status' => \ActionScheduler_Store::STATUS_PENDING]); - + $actions = $this->actionScheduler->getScheduledActions(['hook' => Hooks::AUTOMATION_STEP, 'status' => ActionScheduler_Store::STATUS_PENDING]); foreach ($actions as $action) { $args = $action->get_args(); $automationArgs = reset($args);