Add hook and basic handler for automation triggers
For now trigger keys are stored in the workflow as a JSON array. This is not optimal in case someone has many workflows but as workflows are user-created it's unlinkely someone will have thousands of them. We can consider adding a workflow_triggers table as well. [MAILPOET-4136]
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace MailPoet\Automation\Engine\Storage;
|
||||
|
||||
use MailPoet\Automation\Engine\Exceptions;
|
||||
use MailPoet\Automation\Engine\Workflows\Trigger;
|
||||
use MailPoet\Automation\Engine\Workflows\Workflow;
|
||||
use wpdb;
|
||||
|
||||
@@ -45,4 +46,20 @@ class WorkflowStorage {
|
||||
}
|
||||
return array_unique($triggerKeys);
|
||||
}
|
||||
|
||||
/** @return Workflow[] */
|
||||
public function getActiveWorkflowsByTrigger(Trigger $trigger): array {
|
||||
$query = strval(
|
||||
$this->wpdb->prepare(
|
||||
"SELECT * FROM $this->table WHERE status = %s AND trigger_keys LIKE %s",
|
||||
Workflow::STATUS_ACTIVE,
|
||||
'%' . $this->wpdb->esc_like($trigger->getKey()) . '%'
|
||||
)
|
||||
);
|
||||
|
||||
$data = $this->wpdb->get_results($query, ARRAY_A);
|
||||
return array_map(function (array $workflowData) {
|
||||
return Workflow::fromArray($workflowData);
|
||||
}, (array)$data);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user