Introduce step run args to simplify step run arguments

[MAILPOET-4629]
This commit is contained in:
Jan Jakes
2022-09-19 13:52:12 +02:00
committed by David Remer
parent 460cbd9e12
commit 68b5bab9cc
6 changed files with 80 additions and 23 deletions

View File

@ -5,6 +5,7 @@ namespace MailPoet\Automation\Engine\Control;
use Exception;
use MailPoet\Automation\Engine\Control\Steps\ActionStepRunner;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Data\StepRunArgs;
use MailPoet\Automation\Engine\Data\SubjectEntry;
use MailPoet\Automation\Engine\Data\WorkflowRun;
use MailPoet\Automation\Engine\Data\WorkflowRunLog;
@ -133,7 +134,8 @@ class StepHandler {
try {
$requiredSubjects = $step instanceof Action ? $step->getSubjectKeys() : [];
$subjectEntries = $this->getSubjectEntries($workflowRun, $requiredSubjects);
$this->stepRunners[$stepType]->run($workflow, $workflowRun, $step, $subjectEntries);
$args = new StepRunArgs($workflow, $workflowRun, $step, $subjectEntries);
$this->stepRunners[$stepType]->run($args);
$log->markCompletedSuccessfully();
} catch (Throwable $e) {
$log->markFailed();

View File

@ -2,12 +2,8 @@
namespace MailPoet\Automation\Engine\Control;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Data\SubjectEntry;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Data\WorkflowRun;
use MailPoet\Automation\Engine\Data\StepRunArgs;
interface StepRunner {
/** @var SubjectEntry[] $subjectEntries */
public function run(Step $step, Workflow $workflow, WorkflowRun $workflowRun, array $subjectEntries): void;
public function run(StepRunArgs $args): void;
}

View File

@ -3,10 +3,7 @@
namespace MailPoet\Automation\Engine\Control\Steps;
use MailPoet\Automation\Engine\Control\StepRunner;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Data\SubjectEntry;
use MailPoet\Automation\Engine\Data\Workflow;
use MailPoet\Automation\Engine\Data\WorkflowRun;
use MailPoet\Automation\Engine\Data\StepRunArgs;
use MailPoet\Automation\Engine\Exceptions\InvalidStateException;
use MailPoet\Automation\Engine\Registry;
@ -20,15 +17,14 @@ class ActionStepRunner implements StepRunner {
$this->registry = $registry;
}
/** @param SubjectEntry[] $subjectEntries */
public function run(Step $step, Workflow $workflow, WorkflowRun $workflowRun, array $subjectEntries): void {
$action = $this->registry->getAction($step->getKey());
public function run(StepRunArgs $args): void {
$action = $this->registry->getAction($args->getStep()->getKey());
if (!$action) {
throw new InvalidStateException();
}
if (!$action->isValid($workflowRun->getSubjects(), $step, $workflow)) {
if (!$action->isValid($args->getWorkflowRun()->getSubjects(), $args->getStep(), $args->getWorkflow())) {
throw new InvalidStateException();
}
$action->run($workflow, $workflowRun, $step);
$action->run($args);
}
}