diff --git a/mailpoet/lib/Automation/Engine/Control/TriggerHandler.php b/mailpoet/lib/Automation/Engine/Control/TriggerHandler.php index 445415d06e..5a5bf545d4 100644 --- a/mailpoet/lib/Automation/Engine/Control/TriggerHandler.php +++ b/mailpoet/lib/Automation/Engine/Control/TriggerHandler.php @@ -59,7 +59,7 @@ class TriggerHandler { $loadedSubjects[] = $this->subjectLoader->loadSubject($subject['key'], $subject['args']); } - $workflowRun = new WorkflowRun($workflow->getId(), $trigger->getKey(), $loadedSubjects); + $workflowRun = new WorkflowRun($workflow->getId(), $workflow->getVersionId(), $trigger->getKey(), $loadedSubjects); $workflowRunId = $this->workflowRunStorage->createWorkflowRun($workflowRun); $this->actionScheduler->enqueue(Hooks::WORKFLOW_STEP, [ diff --git a/mailpoet/lib/Automation/Engine/Data/WorkflowRun.php b/mailpoet/lib/Automation/Engine/Data/WorkflowRun.php index c8ef078d43..67f9cff0f3 100644 --- a/mailpoet/lib/Automation/Engine/Data/WorkflowRun.php +++ b/mailpoet/lib/Automation/Engine/Data/WorkflowRun.php @@ -20,6 +20,9 @@ class WorkflowRun { /** @var int */ private $workflowId; + /** @var int */ + private $versionId; + /** @var string */ private $triggerKey; @@ -43,11 +46,13 @@ class WorkflowRun { */ public function __construct( int $workflowId, + int $versionId, string $triggerKey, array $subjects, int $id = null ) { $this->workflowId = $workflowId; + $this->versionId = $versionId; $this->triggerKey = $triggerKey; $this->subjects = $subjects; @@ -72,6 +77,10 @@ class WorkflowRun { return $this->workflowId; } + public function getVersionId(): int { + return $this->workflowId; + } + public function getTriggerKey(): string { return $this->triggerKey; } @@ -130,6 +139,7 @@ class WorkflowRun { public function toArray(): array { return [ 'workflow_id' => $this->workflowId, + 'version_id' => $this->versionId, 'trigger_key' => $this->triggerKey, 'status' => $this->status, 'created_at' => $this->createdAt->format(DateTimeImmutable::W3C), @@ -143,7 +153,7 @@ class WorkflowRun { } public static function fromArray(array $data): self { - $workflowRun = new WorkflowRun((int)$data['workflow_id'], $data['trigger_key'], $data['subjects']); + $workflowRun = new WorkflowRun((int)$data['workflow_id'], (int)$data['version_id'], $data['trigger_key'], $data['subjects']); $workflowRun->id = (int)$data['id']; $workflowRun->status = $data['status']; $workflowRun->createdAt = $data['created_at']; diff --git a/mailpoet/lib/Automation/Engine/Migrations/Migrator.php b/mailpoet/lib/Automation/Engine/Migrations/Migrator.php index add328a14e..6c2750d79d 100644 --- a/mailpoet/lib/Automation/Engine/Migrations/Migrator.php +++ b/mailpoet/lib/Automation/Engine/Migrations/Migrator.php @@ -47,6 +47,7 @@ class Migrator { CREATE TABLE {$this->prefix}workflow_runs ( id int(11) unsigned NOT NULL AUTO_INCREMENT, workflow_id int(11) unsigned NOT NULL, + version_id int(11) unsigned NOT NULL, trigger_key varchar(255) NOT NULL, status varchar(255) NOT NULL, created_at timestamp NOT NULL, diff --git a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php index 4674eaceb2..32e7797fda 100644 --- a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php +++ b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php @@ -99,7 +99,7 @@ class SendEmailActionTest extends \MailPoetTest { $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); $workflow = new Workflow('some-workflow', [$step]); - $run = new WorkflowRun(1, 'trigger-key', $subjects); + $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); expect($scheduled)->count(0); @@ -121,7 +121,7 @@ class SendEmailActionTest extends \MailPoetTest { $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); $workflow = new Workflow('some-workflow', [$step]); - $run = new WorkflowRun(1, 'trigger-key', $subjects); + $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); expect($scheduled)->count(0); @@ -153,7 +153,7 @@ class SendEmailActionTest extends \MailPoetTest { $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); $workflow = new Workflow('some-workflow', [$step]); - $run = new WorkflowRun(1, 'trigger-key', $subjects); + $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); expect($scheduled)->count(0); @@ -182,7 +182,7 @@ class SendEmailActionTest extends \MailPoetTest { $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); $workflow = new Workflow('some-workflow', [$step]); - $run = new WorkflowRun(1, 'trigger-key', $subjects); + $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); expect($scheduled)->count(0); @@ -220,7 +220,7 @@ class SendEmailActionTest extends \MailPoetTest { $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); $workflow = new Workflow('some-workflow', [$step]); - $run = new WorkflowRun(1, 'trigger-key', $subjects); + $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); expect($scheduled)->count(0); @@ -249,7 +249,7 @@ class SendEmailActionTest extends \MailPoetTest { $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); $workflow = new Workflow('some-workflow', [$step]); - $run = new WorkflowRun(1, 'trigger-key', $subjects); + $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); expect($scheduled)->count(0);