Add method to fetch all runs of a workflow
[MAILPOET-4731]
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user