When unscheduling automation run actions, cancel related runs

[MAILPOET-6131]
This commit is contained in:
Jan Jakes
2024-07-04 09:17:54 +02:00
committed by Aschepikov
parent 45592114bd
commit b7cee657c7

View File

@@ -2,8 +2,10 @@
namespace MailPoet\Automation\Engine\Builder; namespace MailPoet\Automation\Engine\Builder;
use ActionScheduler_Store;
use MailPoet\Automation\Engine\Control\ActionScheduler; use MailPoet\Automation\Engine\Control\ActionScheduler;
use MailPoet\Automation\Engine\Data\Automation; use MailPoet\Automation\Engine\Data\Automation;
use MailPoet\Automation\Engine\Data\AutomationRun;
use MailPoet\Automation\Engine\Data\Step; use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Exceptions; use MailPoet\Automation\Engine\Exceptions;
use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException; use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException;
@@ -161,11 +163,13 @@ class UpdateAutomationController {
$runIds = []; $runIds = [];
$runs = $this->automationRunStorage->getAutomationRunsForAutomation($automation); $runs = $this->automationRunStorage->getAutomationRunsForAutomation($automation);
foreach ($runs as $run) { foreach ($runs as $run) {
if ($run->getStatus() === AutomationRun::STATUS_RUNNING) {
$this->automationRunStorage->updateStatus($run->getId(), AutomationRun::STATUS_CANCELLED);
}
$runIds[$run->getId()] = $run; $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) { foreach ($actions as $action) {
$args = $action->get_args(); $args = $action->get_args();
$automationArgs = reset($args); $automationArgs = reset($args);