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;
|
namespace MailPoet\Automation\Engine\Storage;
|
||||||
|
|
||||||
|
use MailPoet\Automation\Engine\Data\Workflow;
|
||||||
use MailPoet\Automation\Engine\Data\WorkflowRun;
|
use MailPoet\Automation\Engine\Data\WorkflowRun;
|
||||||
use MailPoet\Automation\Engine\Exceptions;
|
use MailPoet\Automation\Engine\Exceptions;
|
||||||
use wpdb;
|
use wpdb;
|
||||||
@@ -34,6 +35,23 @@ class WorkflowRunStorage {
|
|||||||
return $result ? WorkflowRun::fromArray((array)$result) : null;
|
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 {
|
public function updateStatus(string $status, int ...$ids): void {
|
||||||
if (!$ids) {
|
if (!$ids) {
|
||||||
return;
|
return;
|
||||||
|
@@ -46,7 +46,7 @@ parameters:
|
|||||||
- '/Class Automattic\\WooCommerce\\StoreApi\\Schemas\\ExtendSchema not found./'
|
- '/Class Automattic\\WooCommerce\\StoreApi\\Schemas\\ExtendSchema not found./'
|
||||||
-
|
-
|
||||||
message: "#^Cannot cast string|void to string\\.$#"
|
message: "#^Cannot cast string|void to string\\.$#"
|
||||||
count: 2
|
count: 3
|
||||||
path: ../../lib/Automation/Engine/Storage/WorkflowRunStorage.php
|
path: ../../lib/Automation/Engine/Storage/WorkflowRunStorage.php
|
||||||
-
|
-
|
||||||
message: "#^Cannot cast string|void to string\\.$#"
|
message: "#^Cannot cast string|void to string\\.$#"
|
||||||
|
Reference in New Issue
Block a user