Add method to fetch all runs of a workflow

[MAILPOET-4731]
This commit is contained in:
David Remer
2022-10-24 13:06:02 +03:00
committed by Jan Jakeš
parent 7aa1a5f4ba
commit 57548b579f
2 changed files with 19 additions and 1 deletions

View File

@@ -2,6 +2,7 @@
namespace MailPoet\Automation\Engine\Storage;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Data\WorkflowRun;
use MailPoet\Automation\Engine\Exceptions;
use wpdb;
@@ -34,6 +35,23 @@ class WorkflowRunStorage {
return $result ? WorkflowRun::fromArray((array)$result) : null;
}
/**
* @param Workflow $workflow
* @return WorkflowRun[]
* @throws Exceptions\InvalidStateException
*/
public function getWorkflowRunsForWorkflow(Workflow $workflow): array {
$table = esc_sql($this->table);
$query = (string)$this->wpdb->prepare("SELECT * FROM $table WHERE workflow_id = %d", $workflow->getId());
$result = $this->wpdb->get_results($query, ARRAY_A);
return is_array($result) ? array_map(
function(array $runData): WorkflowRun {
return WorkflowRun::fromArray($runData);
},
$result
) : [];
}
public function updateStatus(string $status, int ...$ids): void {
if (!$ids) {
return;