From 57cf547a8a57762a5d7fe4bc8ec227224c0bbf53 Mon Sep 17 00:00:00 2001 From: John Oleksowicz Date: Mon, 12 Sep 2022 12:40:18 -0500 Subject: [PATCH] Only expose log in post-step hook The log has step ID and workflow run ID in case an integration needs to retrieve them. [MAILPOET-4463] --- .../Automation/Engine/Control/StepHandler.php | 2 +- mailpoet/lib/Automation/Engine/Hooks.php | 4 ++-- .../Engine/Data/WorkflowRunLogTest.php | 21 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/mailpoet/lib/Automation/Engine/Control/StepHandler.php b/mailpoet/lib/Automation/Engine/Control/StepHandler.php index 0db884ccd7..591e16cc23 100644 --- a/mailpoet/lib/Automation/Engine/Control/StepHandler.php +++ b/mailpoet/lib/Automation/Engine/Control/StepHandler.php @@ -130,7 +130,7 @@ class StepHandler { throw $e; } finally { try { - $this->hooks->doWorkflowStepAfterRun($step, $log); + $this->hooks->doWorkflowStepAfterRun($log); } catch (Exception $e) { $log->addError($e); } diff --git a/mailpoet/lib/Automation/Engine/Hooks.php b/mailpoet/lib/Automation/Engine/Hooks.php index f751c77da6..1e36e73c09 100644 --- a/mailpoet/lib/Automation/Engine/Hooks.php +++ b/mailpoet/lib/Automation/Engine/Hooks.php @@ -41,7 +41,7 @@ class Hooks { $this->wordPress->doAction(self::WORKFLOW_STEP_BEFORE_SAVE . '/key=' . $step->getKey(), $step); } - public function doWorkflowStepAfterRun(Step $step, WorkflowRunLog $workflowRunLog): void { - $this->wordPress->doAction(self::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, $step, $workflowRunLog); + public function doWorkflowStepAfterRun(WorkflowRunLog $workflowRunLog): void { + $this->wordPress->doAction(self::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, $workflowRunLog); } } diff --git a/mailpoet/tests/integration/Automation/Engine/Data/WorkflowRunLogTest.php b/mailpoet/tests/integration/Automation/Engine/Data/WorkflowRunLogTest.php index 0b357728fd..bb106d48dd 100644 --- a/mailpoet/tests/integration/Automation/Engine/Data/WorkflowRunLogTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Data/WorkflowRunLogTest.php @@ -59,9 +59,9 @@ class WorkflowRunLogTest extends \MailPoetTest { } public function testItGetsExposedViaAction(): void { - $this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(Step $step, WorkflowRunLog $log) { + $this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(WorkflowRunLog $log) { $log->setData('test', 'value'); - }, 10, 2); + }); $workflowRunLogs = $this->getLogsForAction(); expect($workflowRunLogs)->count(1); $log = $workflowRunLogs[0]; @@ -69,9 +69,9 @@ class WorkflowRunLogTest extends \MailPoetTest { } public function testBadActionIntegrationsCannotDerailStepFromRunning() { - $this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(Step $step, WorkflowRunLog $log) { + $this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(WorkflowRunLog $log) { throw new \Exception('bad integration'); - }, 9, 2); + }); $workflowRunLogs = $this->getLogsForAction(); expect($workflowRunLogs)->count(1); $log = $workflowRunLogs[0]; @@ -99,21 +99,17 @@ class WorkflowRunLogTest extends \MailPoetTest { } public function testItLogsCompletedStatusCorrectly(): void { - $workflowRunLogs = $this->getLogsForAction(function() { - return true; - }); + $workflowRunLogs = $this->getLogsForAction(); expect($workflowRunLogs)->count(1); $log = $workflowRunLogs[0]; expect($log->getStatus())->equals('completed'); } public function testItAddsCompletedAtTimestampAfterRunningSuccessfully(): void { - $this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(Step $step, WorkflowRunLog $log) { + $this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(WorkflowRunLog $log) { expect($log->getCompletedAt())->null(); - }, 10, 2); - $workflowRunLogs = $this->getLogsForAction(function() { - return true; }); + $workflowRunLogs = $this->getLogsForAction(); expect($workflowRunLogs)->count(1); $log = $workflowRunLogs[0]; expect($log->getCompletedAt())->isInstanceOf(\DateTimeImmutable::class); @@ -171,6 +167,9 @@ class WorkflowRunLogTest extends \MailPoetTest { } private function getLogsForAction($callback = null) { + if ($callback === null) { + $callback = function() { return true; }; + } $testAction = $this->getRegisteredTestAction($callback); $actionStep = new Step('action-step-id', Step::TYPE_ACTION, $testAction->getKey()); $workflow = new Workflow('test_workflow', [$actionStep], new \WP_User());