Save subject data in workflow runs

[MAILPOET-4136]
This commit is contained in:
Jan Jakes
2022-03-07 15:08:25 +01:00
committed by Veljko V
parent 50b889a1bd
commit 716050b7de
2 changed files with 23 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ use MailPoet\Automation\Engine\Hooks;
use MailPoet\Automation\Engine\Storage\WorkflowRunStorage;
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
use MailPoet\Automation\Engine\WordPress;
use MailPoet\Automation\Engine\Workflows\Subject;
use MailPoet\Automation\Engine\Workflows\Trigger;
use MailPoet\Automation\Engine\Workflows\WorkflowRun;
@@ -36,10 +37,11 @@ class TriggerHandler {
}
public function initialize(): void {
$this->wordPress->addAction(Hooks::TRIGGER, [$this, 'processTrigger']);
$this->wordPress->addAction(Hooks::TRIGGER, [$this, 'processTrigger'], 10, 2);
}
public function processTrigger(Trigger $trigger): void {
/** @param Subject[] $subjects */
public function processTrigger(Trigger $trigger, array $subjects): void {
$workflows = $this->workflowStorage->getActiveWorkflowsByTrigger($trigger);
foreach ($workflows as $workflow) {
$step = $workflow->getTrigger($trigger->getKey());
@@ -47,7 +49,7 @@ class TriggerHandler {
throw Exceptions::workflowTriggerNotFound($workflow->getId(), $trigger->getKey());
}
$workflowRun = new WorkflowRun($workflow->getId(), $trigger->getKey());
$workflowRun = new WorkflowRun($workflow->getId(), $trigger->getKey(), $subjects);
$workflowRunId = $this->workflowRunStorage->createWorkflowRun($workflowRun);
$this->actionScheduler->enqueue(Hooks::WORKFLOW_STEP, [