diff --git a/mailpoet/lib/Automation/Engine/Control/StepHandler.php b/mailpoet/lib/Automation/Engine/Control/StepHandler.php index f71bb4753f..cda283e681 100644 --- a/mailpoet/lib/Automation/Engine/Control/StepHandler.php +++ b/mailpoet/lib/Automation/Engine/Control/StepHandler.php @@ -100,7 +100,7 @@ class StepHandler { $this->handleStep($args); } catch (Throwable $e) { $status = $e instanceof InvalidStateException && $e->getErrorCode() === 'mailpoet_automation_workflow_not_active' ? WorkflowRun::STATUS_CANCELLED : WorkflowRun::STATUS_FAILED; - $this->workflowRunStorage->updateStatus((int)$args['workflow_run_id'], $status); + $this->workflowRunStorage->updateStatus($status, (int)$args['workflow_run_id']); if (!$e instanceof Exception) { throw new Exception($e->getMessage(), intval($e->getCode()), $e); } @@ -131,7 +131,7 @@ class StepHandler { // complete workflow run if (!$stepId) { - $this->workflowRunStorage->updateStatus($workflowRunId, WorkflowRun::STATUS_COMPLETE); + $this->workflowRunStorage->updateStatus(WorkflowRun::STATUS_COMPLETE, $workflowRunId); return; } @@ -183,7 +183,7 @@ class StepHandler { // no need to schedule a new step if the next step is null, complete the run if (!$nextStep) { - $this->workflowRunStorage->updateStatus($workflowRunId, WorkflowRun::STATUS_COMPLETE); + $this->workflowRunStorage->updateStatus(WorkflowRun::STATUS_COMPLETE, $workflowRunId); return; } diff --git a/mailpoet/lib/Automation/Engine/Storage/WorkflowRunStorage.php b/mailpoet/lib/Automation/Engine/Storage/WorkflowRunStorage.php index 65620b4444..de706f7c20 100644 --- a/mailpoet/lib/Automation/Engine/Storage/WorkflowRunStorage.php +++ b/mailpoet/lib/Automation/Engine/Storage/WorkflowRunStorage.php @@ -34,9 +34,13 @@ class WorkflowRunStorage { return $result ? WorkflowRun::fromArray((array)$result) : null; } - public function updateStatus(int $id, string $status): void { + public function updateStatus(string $status, int ...$ids): void { + if (!$ids) { + return; + } $table = esc_sql($this->table); - $query = (string)$this->wpdb->prepare("UPDATE $table SET status = %s WHERE id = %d", $status, $id); + $ids = esc_sql(implode(',', $ids)); + $query = (string)$this->wpdb->prepare("UPDATE $table SET status = %s WHERE id IN ($ids)", $status); $result = $this->wpdb->query($query); if ($result === false) { throw Exceptions::databaseError($this->wpdb->last_error);