Introduce template storage and rebuild create form template endpoint

[MAILPOET-4538]
This commit is contained in:
David Remer
2022-08-18 09:30:08 +03:00
committed by Veljko V
parent 1140ee3129
commit baa4d369af
11 changed files with 146 additions and 138 deletions

View File

@@ -4,6 +4,7 @@ namespace MailPoet\Automation\Engine\Builder;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
use MailPoet\Automation\Engine\Storage\WorkflowTemplateStorage;
use MailPoet\Automation\Integrations\MailPoet\Templates\WorkflowBuilder;
use MailPoet\UnexpectedValueException;
@@ -11,33 +12,25 @@ class CreateWorkflowFromTemplateController {
/** @var WorkflowStorage */
private $storage;
/** @var WorkflowBuilder */
private $templates;
/** @var WorkflowTemplateStorage */
private $templateStorage;
public function __construct(
WorkflowStorage $storage,
WorkflowBuilder $templates
WorkflowTemplateStorage $templateStorage
) {
$this->storage = $storage;
$this->templates = $templates;
$this->templateStorage = $templateStorage;
}
public function createWorkflow(array $data): Workflow {
$name = $data['name'];
$template = $data['template'];
public function createWorkflow(string $slug): Workflow {
switch ($template) {
case 'delayed-email-after-signup':
$workflow = $this->templates->delayedEmailAfterSignupWorkflow($name);
break;
case 'welcome-email-sequence':
$workflow = $this->templates->welcomeEmailSequence($name);
break;
default:
throw UnexpectedValueException::create()->withMessage('Template not found.');
$template = $this->templateStorage->getTemplateBySlug($slug);
if (! $template) {
throw UnexpectedValueException::create()->withMessage('Template not found.');
}
$this->storage->createWorkflow($workflow);
return $workflow;
$this->storage->createWorkflow($template->getWorkflow());
return $template->getWorkflow();
}
}