Trigger workflow and step before save hooks
[MAILPOET-4515]
This commit is contained in:
@ -5,15 +5,21 @@ namespace MailPoet\Automation\Engine\Builder;
|
|||||||
use MailPoet\Automation\Engine\Data\Step;
|
use MailPoet\Automation\Engine\Data\Step;
|
||||||
use MailPoet\Automation\Engine\Data\Workflow;
|
use MailPoet\Automation\Engine\Data\Workflow;
|
||||||
use MailPoet\Automation\Engine\Exceptions;
|
use MailPoet\Automation\Engine\Exceptions;
|
||||||
|
use MailPoet\Automation\Engine\Hooks;
|
||||||
use MailPoet\Automation\Engine\Registry;
|
use MailPoet\Automation\Engine\Registry;
|
||||||
|
|
||||||
class UpdateStepsController {
|
class UpdateStepsController {
|
||||||
|
/** @var Hooks */
|
||||||
|
private $hooks;
|
||||||
|
|
||||||
/** @var Registry */
|
/** @var Registry */
|
||||||
private $registry;
|
private $registry;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
Hooks $hooks,
|
||||||
Registry $registry
|
Registry $registry
|
||||||
) {
|
) {
|
||||||
|
$this->hooks = $hooks;
|
||||||
$this->registry = $registry;
|
$this->registry = $registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,12 +39,16 @@ class UpdateStepsController {
|
|||||||
if (!$step) {
|
if (!$step) {
|
||||||
throw Exceptions::workflowStepNotFound($key);
|
throw Exceptions::workflowStepNotFound($key);
|
||||||
}
|
}
|
||||||
return new Step(
|
|
||||||
|
$stepData = new Step(
|
||||||
$data['id'],
|
$data['id'],
|
||||||
$data['type'],
|
$data['type'],
|
||||||
$data['key'],
|
$data['key'],
|
||||||
$data['next_step_id'] ?? null,
|
$data['next_step_id'] ?? null,
|
||||||
$data['args'] ?? null
|
$data['args'] ?? null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->hooks->doWorkflowStepBeforeSave($stepData);
|
||||||
|
return $stepData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,13 @@ namespace MailPoet\Automation\Engine\Builder;
|
|||||||
use MailPoet\Automation\Engine\Data\Workflow;
|
use MailPoet\Automation\Engine\Data\Workflow;
|
||||||
use MailPoet\Automation\Engine\Exceptions;
|
use MailPoet\Automation\Engine\Exceptions;
|
||||||
use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException;
|
use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException;
|
||||||
|
use MailPoet\Automation\Engine\Hooks;
|
||||||
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||||
|
|
||||||
class UpdateWorkflowController {
|
class UpdateWorkflowController {
|
||||||
|
/** @var Hooks */
|
||||||
|
private $hooks;
|
||||||
|
|
||||||
/** @var WorkflowStorage */
|
/** @var WorkflowStorage */
|
||||||
private $storage;
|
private $storage;
|
||||||
|
|
||||||
@ -15,9 +19,11 @@ class UpdateWorkflowController {
|
|||||||
private $updateStepsController;
|
private $updateStepsController;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
Hooks $hooks,
|
||||||
WorkflowStorage $storage,
|
WorkflowStorage $storage,
|
||||||
UpdateStepsController $updateStepsController
|
UpdateStepsController $updateStepsController
|
||||||
) {
|
) {
|
||||||
|
$this->hooks = $hooks;
|
||||||
$this->storage = $storage;
|
$this->storage = $storage;
|
||||||
$this->updateStepsController = $updateStepsController;
|
$this->updateStepsController = $updateStepsController;
|
||||||
}
|
}
|
||||||
@ -52,6 +58,7 @@ class UpdateWorkflowController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($changed) {
|
if ($changed) {
|
||||||
|
$this->hooks->doWorkflowBeforeSave($workflow);
|
||||||
$this->storage->updateWorkflow($workflow);
|
$this->storage->updateWorkflow($workflow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user