Add author to Workflow
[MAILPOET-4417]
This commit is contained in:
@@ -19,6 +19,9 @@ class Workflow {
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
|
/** @var \WP_User */
|
||||||
|
private $author;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $status = self::STATUS_DRAFT;
|
private $status = self::STATUS_DRAFT;
|
||||||
|
|
||||||
@@ -38,11 +41,13 @@ class Workflow {
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
string $name,
|
string $name,
|
||||||
array $steps,
|
array $steps,
|
||||||
|
\WP_User $author,
|
||||||
int $id = null,
|
int $id = null,
|
||||||
int $versionId = null
|
int $versionId = null
|
||||||
) {
|
) {
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->steps = [];
|
$this->steps = [];
|
||||||
|
$this->author = $author;
|
||||||
foreach ($steps as $step) {
|
foreach ($steps as $step) {
|
||||||
$this->steps[$step->getId()] = $step;
|
$this->steps[$step->getId()] = $step;
|
||||||
}
|
}
|
||||||
@@ -92,6 +97,10 @@ class Workflow {
|
|||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAuthor(): \WP_User {
|
||||||
|
return $this->author;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUpdatedAt(): DateTimeImmutable {
|
public function getUpdatedAt(): DateTimeImmutable {
|
||||||
return $this->updatedAt;
|
return $this->updatedAt;
|
||||||
}
|
}
|
||||||
@@ -142,6 +151,7 @@ class Workflow {
|
|||||||
return [
|
return [
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
|
'author' => $this->author->ID,
|
||||||
'created_at' => $this->createdAt->format(DateTimeImmutable::W3C),
|
'created_at' => $this->createdAt->format(DateTimeImmutable::W3C),
|
||||||
'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C),
|
'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C),
|
||||||
'activated_at' => $this->activatedAt ? $this->activatedAt->format(DateTimeImmutable::W3C) : null,
|
'activated_at' => $this->activatedAt ? $this->activatedAt->format(DateTimeImmutable::W3C) : null,
|
||||||
@@ -167,7 +177,11 @@ class Workflow {
|
|||||||
|
|
||||||
public static function fromArray(array $data): self {
|
public static function fromArray(array $data): self {
|
||||||
// TODO: validation
|
// 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->id = (int)$data['id'];
|
||||||
$workflow->versionId = (int)$data['version_id'];
|
$workflow->versionId = (int)$data['version_id'];
|
||||||
$workflow->status = $data['status'];
|
$workflow->status = $data['status'];
|
||||||
|
@@ -25,6 +25,7 @@ class Migrator {
|
|||||||
CREATE TABLE {$this->prefix}workflows (
|
CREATE TABLE {$this->prefix}workflows (
|
||||||
id int(11) unsigned NOT NULL AUTO_INCREMENT,
|
id int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
name varchar(255) NOT NULL,
|
name varchar(255) NOT NULL,
|
||||||
|
author bigint NOT NULL,
|
||||||
status varchar(255) NOT NULL,
|
status varchar(255) NOT NULL,
|
||||||
created_at timestamp NOT NULL,
|
created_at timestamp NOT NULL,
|
||||||
updated_at timestamp NOT NULL,
|
updated_at timestamp NOT NULL,
|
||||||
|
@@ -44,7 +44,8 @@ class WorkflowBuilder {
|
|||||||
$steps = array_reverse($steps);
|
$steps = array_reverse($steps);
|
||||||
return new Workflow(
|
return new Workflow(
|
||||||
$name,
|
$name,
|
||||||
$steps
|
$steps,
|
||||||
|
wp_get_current_user()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ class WorkflowStorageTest extends \MailPoetTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function createEmptyWorkflow(string $name="test"): Workflow {
|
private function createEmptyWorkflow(string $name="test"): Workflow {
|
||||||
$workflow = new Workflow($name, []);
|
$workflow = new Workflow($name, [], new \WP_User());
|
||||||
$workflowId = $this->testee->createWorkflow($workflow);
|
$workflowId = $this->testee->createWorkflow($workflow);
|
||||||
$workflow = $this->testee->getWorkflow($workflowId);
|
$workflow = $this->testee->getWorkflow($workflowId);
|
||||||
if (! $workflow) {
|
if (! $workflow) {
|
||||||
|
@@ -61,7 +61,7 @@ class SendEmailActionTest extends \MailPoetTest {
|
|||||||
|
|
||||||
$this->email = (new Newsletter())->withAutomationType()->create();
|
$this->email = (new Newsletter())->withAutomationType()->create();
|
||||||
$this->step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $this->email->getId()]);
|
$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() {
|
public function testItKnowsWhenItHasAllRequiredSubjects() {
|
||||||
@@ -98,7 +98,7 @@ class SendEmailActionTest extends \MailPoetTest {
|
|||||||
$email = (new Newsletter())->withAutomationType()->create();
|
$email = (new Newsletter())->withAutomationType()->create();
|
||||||
|
|
||||||
$step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]);
|
$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);
|
$run = new WorkflowRun(1, 1, 'trigger-key', $subjects);
|
||||||
|
|
||||||
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
||||||
@@ -120,7 +120,7 @@ class SendEmailActionTest extends \MailPoetTest {
|
|||||||
$email = (new Newsletter())->withAutomationType()->create();
|
$email = (new Newsletter())->withAutomationType()->create();
|
||||||
|
|
||||||
$step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]);
|
$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);
|
$run = new WorkflowRun(1, 1, 'trigger-key', $subjects);
|
||||||
|
|
||||||
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
||||||
@@ -152,7 +152,7 @@ class SendEmailActionTest extends \MailPoetTest {
|
|||||||
$email = (new Newsletter())->withAutomationType()->create();
|
$email = (new Newsletter())->withAutomationType()->create();
|
||||||
|
|
||||||
$step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]);
|
$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);
|
$run = new WorkflowRun(1, 1, 'trigger-key', $subjects);
|
||||||
|
|
||||||
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
||||||
@@ -181,7 +181,7 @@ class SendEmailActionTest extends \MailPoetTest {
|
|||||||
$email = (new Newsletter())->withAutomationType()->create();
|
$email = (new Newsletter())->withAutomationType()->create();
|
||||||
|
|
||||||
$step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]);
|
$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);
|
$run = new WorkflowRun(1, 1, 'trigger-key', $subjects);
|
||||||
|
|
||||||
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
||||||
@@ -219,7 +219,7 @@ class SendEmailActionTest extends \MailPoetTest {
|
|||||||
$email = (new Newsletter())->withAutomationType()->create();
|
$email = (new Newsletter())->withAutomationType()->create();
|
||||||
|
|
||||||
$step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]);
|
$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);
|
$run = new WorkflowRun(1, 1, 'trigger-key', $subjects);
|
||||||
|
|
||||||
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
||||||
@@ -248,7 +248,7 @@ class SendEmailActionTest extends \MailPoetTest {
|
|||||||
$email = (new Newsletter())->withAutomationType()->create();
|
$email = (new Newsletter())->withAutomationType()->create();
|
||||||
|
|
||||||
$step = new Step('step-id', Step::TYPE_ACTION, 'step-key', null, ['email_id' => $email->getId()]);
|
$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);
|
$run = new WorkflowRun(1, 1, 'trigger-key', $subjects);
|
||||||
|
|
||||||
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
$scheduled = $this->scheduledTasksRepository->findByNewsletterAndSubscriberId($email, (int)$subscriber->getId());
|
||||||
|
Reference in New Issue
Block a user