[MAILPOET-4731]
This commit is contained in:
David Remer
2022-10-24 14:16:03 +03:00
committed by Jan Jakeš
parent 9bdb32c073
commit 2c57251bae
2 changed files with 5 additions and 9 deletions

View File

@@ -100,7 +100,7 @@ class StepHandler {
$this->handleStep($args); $this->handleStep($args);
} catch (Throwable $e) { } catch (Throwable $e) {
$status = $e instanceof InvalidStateException && $e->getErrorCode() === 'mailpoet_automation_workflow_not_active' ? WorkflowRun::STATUS_CANCELLED : WorkflowRun::STATUS_FAILED; $status = $e instanceof InvalidStateException && $e->getErrorCode() === 'mailpoet_automation_workflow_not_active' ? WorkflowRun::STATUS_CANCELLED : WorkflowRun::STATUS_FAILED;
$this->workflowRunStorage->updateStatus($status, (int)$args['workflow_run_id']); $this->workflowRunStorage->updateStatus((int)$args['workflow_run_id'], $status);
$this->postProcessWorkflowRun((int)$args['workflow_run_id']); $this->postProcessWorkflowRun((int)$args['workflow_run_id']);
if (!$e instanceof Exception) { if (!$e instanceof Exception) {
throw new Exception($e->getMessage(), intval($e->getCode()), $e); throw new Exception($e->getMessage(), intval($e->getCode()), $e);
@@ -133,7 +133,7 @@ class StepHandler {
// complete workflow run // complete workflow run
if (!$stepId) { if (!$stepId) {
$this->workflowRunStorage->updateStatus(WorkflowRun::STATUS_COMPLETE, $workflowRunId); $this->workflowRunStorage->updateStatus($workflowRunId, WorkflowRun::STATUS_COMPLETE);
return; return;
} }
@@ -185,7 +185,7 @@ class StepHandler {
// no need to schedule a new step if the next step is null, complete the run // no need to schedule a new step if the next step is null, complete the run
if (!$nextStep) { if (!$nextStep) {
$this->workflowRunStorage->updateStatus(WorkflowRun::STATUS_COMPLETE, $workflowRunId); $this->workflowRunStorage->updateStatus($workflowRunId, WorkflowRun::STATUS_COMPLETE);
return; return;
} }

View File

@@ -52,13 +52,9 @@ class WorkflowRunStorage {
) : []; ) : [];
} }
public function updateStatus(string $status, int ...$ids): void { public function updateStatus(int $id, string $status): void {
if (!$ids) {
return;
}
$table = esc_sql($this->table); $table = esc_sql($this->table);
$ids = esc_sql(implode(',', $ids)); $query = (string)$this->wpdb->prepare("UPDATE $table SET status = %s WHERE id = %d", $status, $id);
$query = (string)$this->wpdb->prepare("UPDATE $table SET status = %s WHERE id IN ($ids)", $status);
$result = $this->wpdb->query($query); $result = $this->wpdb->query($query);
if ($result === false) { if ($result === false) {
throw Exceptions::databaseError($this->wpdb->last_error); throw Exceptions::databaseError($this->wpdb->last_error);