diff --git a/mailpoet/lib/Automation/Engine/Data/Workflow.php b/mailpoet/lib/Automation/Engine/Data/Workflow.php index 543bf7d769..baa416d149 100644 --- a/mailpoet/lib/Automation/Engine/Data/Workflow.php +++ b/mailpoet/lib/Automation/Engine/Data/Workflow.php @@ -19,6 +19,9 @@ class Workflow { /** @var string */ private $name; + /** @var \WP_User */ + private $author; + /** @var string */ private $status = self::STATUS_DRAFT; @@ -38,11 +41,13 @@ class Workflow { public function __construct( string $name, array $steps, + \WP_User $author, int $id = null, int $versionId = null ) { $this->name = $name; $this->steps = []; + $this->author = $author; foreach ($steps as $step) { $this->steps[$step->getId()] = $step; } @@ -92,6 +97,10 @@ class Workflow { return $this->createdAt; } + public function getAuthor(): \WP_User { + return $this->author; + } + public function getUpdatedAt(): DateTimeImmutable { return $this->updatedAt; } @@ -142,6 +151,7 @@ class Workflow { return [ 'name' => $this->name, 'status' => $this->status, + 'author' => $this->author->ID, 'created_at' => $this->createdAt->format(DateTimeImmutable::W3C), 'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C), 'activated_at' => $this->activatedAt ? $this->activatedAt->format(DateTimeImmutable::W3C) : null, @@ -167,7 +177,11 @@ class Workflow { public static function fromArray(array $data): self { // TODO: validation - $workflow = new self($data['name'], self::parseSteps(Json::decode($data['steps']))); + $workflow = new self( + $data['name'], + self::parseSteps(Json::decode($data['steps'])), + new \WP_User((int)$data['author']) + ); $workflow->id = (int)$data['id']; $workflow->versionId = (int)$data['version_id']; $workflow->status = $data['status']; diff --git a/mailpoet/lib/Automation/Engine/Migrations/Migrator.php b/mailpoet/lib/Automation/Engine/Migrations/Migrator.php index 3e33ce411e..773f327afd 100644 --- a/mailpoet/lib/Automation/Engine/Migrations/Migrator.php +++ b/mailpoet/lib/Automation/Engine/Migrations/Migrator.php @@ -25,6 +25,7 @@ class Migrator { CREATE TABLE {$this->prefix}workflows ( id int(11) unsigned NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, + author bigint NOT NULL, status varchar(255) NOT NULL, created_at timestamp NOT NULL, updated_at timestamp NOT NULL, diff --git a/mailpoet/lib/Automation/Integrations/MailPoet/Templates/WorkflowBuilder.php b/mailpoet/lib/Automation/Integrations/MailPoet/Templates/WorkflowBuilder.php index 00e865f2d0..cd62eda8d4 100644 --- a/mailpoet/lib/Automation/Integrations/MailPoet/Templates/WorkflowBuilder.php +++ b/mailpoet/lib/Automation/Integrations/MailPoet/Templates/WorkflowBuilder.php @@ -44,7 +44,8 @@ class WorkflowBuilder { $steps = array_reverse($steps); return new Workflow( $name, - $steps + $steps, + wp_get_current_user() ); } diff --git a/mailpoet/tests/integration/Automation/Engine/Storage/WorkflowStorageTest.php b/mailpoet/tests/integration/Automation/Engine/Storage/WorkflowStorageTest.php index 4ffb5aaf2e..148382fd84 100644 --- a/mailpoet/tests/integration/Automation/Engine/Storage/WorkflowStorageTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Storage/WorkflowStorageTest.php @@ -74,7 +74,7 @@ class WorkflowStorageTest extends \MailPoetTest } private function createEmptyWorkflow(string $name="test"): Workflow { - $workflow = new Workflow($name, []); + $workflow = new Workflow($name, [], new \WP_User()); $workflowId = $this->testee->createWorkflow($workflow); $workflow = $this->testee->getWorkflow($workflowId); if (! $workflow) { diff --git a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php index 32e7797fda..ae127238dc 100644 --- a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php +++ b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php @@ -61,7 +61,7 @@ class SendEmailActionTest extends \MailPoetTest { $this->email = (new Newsletter())->withAutomationType()->create(); $this->step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $this->email->getId()]); - $this->workflow = new Workflow('test-workflow', []); + $this->workflow = new Workflow('test-workflow', [], new \WP_User()); } public function testItKnowsWhenItHasAllRequiredSubjects() { @@ -98,7 +98,7 @@ class SendEmailActionTest extends \MailPoetTest { $email = (new Newsletter())->withAutomationType()->create(); $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); - $workflow = new Workflow('some-workflow', [$step]); + $workflow = new Workflow('some-workflow', [$step], new \WP_User()); $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); @@ -120,7 +120,7 @@ class SendEmailActionTest extends \MailPoetTest { $email = (new Newsletter())->withAutomationType()->create(); $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); - $workflow = new Workflow('some-workflow', [$step]); + $workflow = new Workflow('some-workflow', [$step], new \WP_User()); $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); @@ -152,7 +152,7 @@ class SendEmailActionTest extends \MailPoetTest { $email = (new Newsletter())->withAutomationType()->create(); $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); - $workflow = new Workflow('some-workflow', [$step]); + $workflow = new Workflow('some-workflow', [$step], new \WP_User()); $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); @@ -181,7 +181,7 @@ class SendEmailActionTest extends \MailPoetTest { $email = (new Newsletter())->withAutomationType()->create(); $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); - $workflow = new Workflow('some-workflow', [$step]); + $workflow = new Workflow('some-workflow', [$step], new \WP_User()); $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); @@ -219,7 +219,7 @@ class SendEmailActionTest extends \MailPoetTest { $email = (new Newsletter())->withAutomationType()->create(); $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); - $workflow = new Workflow('some-workflow', [$step]); + $workflow = new Workflow('some-workflow', [$step], new \WP_User()); $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId()); @@ -248,7 +248,7 @@ class SendEmailActionTest extends \MailPoetTest { $email = (new Newsletter())->withAutomationType()->create(); $step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]); - $workflow = new Workflow('some-workflow', [$step]); + $workflow = new Workflow('some-workflow', [$step], new \WP_User()); $run = new WorkflowRun(1, 1, 'trigger-key', $subjects); $scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());