private function handleStep(array $args): void { $automationRunId = $args['automation_run_id']; $stepId = $args['step_id']; $automationRun = $this->automationRunStorage->getAutomationRun($automationRunId); if (!$automationRun) { throw Exceptions::automationRunNotFound($automationRunId); } if ($automationRun->getStatus() !== AutomationRun::STATUS_RUNNING) { throw Exceptions::automationRunNotRunning($automationRunId, $automationRun->getStatus()); } $automation = $this->automationStorage->getAutomation($automationRun->getAutomationId(), $automationRun->getVersionId()); if (!$automation) { throw Exceptions::automationVersionNotFound($automationRun->getAutomationId(), $automationRun->getVersionId()); } if (!in_array($automation->getStatus(), [Automation::STATUS_ACTIVE, Automation::STATUS_DEACTIVATING], true)) { throw Exceptions::automationNotActive($automationRun->getAutomationId()); } // complete automation run if (!$stepId) { $this->automationRunStorage->updateStatus($automationRunId, AutomationRun::STATUS_COMPLETE); return; } $stepData = $automation->getStep($stepId); if (!$stepData) { throw Exceptions::automationStepNotFound($stepId); } $step = $this->registry->getStep($stepData->getKey()); $stepType = $stepData->getType(); if (isset($this->stepRunners[$stepType])) { $log = new AutomationRunLog($automationRun->getId(), $stepData->getId()); try { $requiredSubjects = $step instanceof Action ? $step->getSubjectKeys() : []; $subjectEntries = $this->getSubjectEntries($automationRun, $requiredSubjects); $args = new StepRunArgs($automation, $automationRun, $stepData, $subjectEntries); $validationArgs = new StepValidationArgs($automation, $stepData, array_map(function (SubjectEntry $entry) { return $entry->getSubject(); }, $subjectEntries)); $this->stepRunners[$stepType]->run($args, $validationArgs); $log->markCompletedSuccessfully(); } catch (Throwable $e) { $log->markFailed(); $log->setError($e); throw $e; } finally { try { $this->hooks->doAutomationStepAfterRun($log); } catch (Throwable $e) { // Ignore integration errors } $this->automationRunLogStorage->createAutomationRunLog($log); } } else { throw new InvalidStateException(); } $nextStep = $stepData->getNextSteps()[0] ?? null; $nextStepArgs = [ [ 'automation_run_id' => $automationRunId, 'step_id' => $nextStep ? $nextStep->getId() : null, ], ]; $this->automationRunStorage->updateNextStep($automationRunId, $nextStep ? $nextStep->getId() : null); // next step scheduled by action if ($this->actionScheduler->hasScheduledAction(Hooks::AUTOMATION_STEP, $nextStepArgs)) { return; } // no need to schedule a new step if the next step is null, complete the run if (!$nextStep) { $this->automationRunStorage->updateStatus($automationRunId, AutomationRun::STATUS_COMPLETE); return; } // enqueue next step $this->actionScheduler->enqueue(Hooks::AUTOMATION_STEP, $nextStepArgs); // TODO: allow long-running steps (that are not done here yet) } /** @return SubjectEntry>[] */ private function getSubjectEntries(AutomationRun $automationRun, array $requiredSubjectKeys): array { $subjectDataMap = []; foreach ($automationRun->getSubjects() as $data) { $subjectDataMap[$data->getKey()] = array_merge($subjectDataMap[$data->getKey()] ?? [], [$data]); } $subjectEntries = []; foreach ($requiredSubjectKeys as $key) { $subjectData = $subjectDataMap[$key] ?? null; if (!$subjectData) { throw Exceptions::subjectDataNotFound($key, $automationRun->getId()); } } foreach ($subjectDataMap as $subjectData) { foreach ($subjectData as $data) { $subjectEntries[] = $this->subjectLoader->getSubjectEntry($data); } } return $subjectEntries; } private function postProcessAutomationRun(int $automationRunId): void { $automationRun = $this->automationRunStorage->getAutomationRun($automationRunId); if (!$automationRun) { return; } $automation = $this->automationStorage->getAutomation($automationRun->getAutomationId()); if (!$automation) { return; } $this->postProcessAutomation($automation); } private function postProcessAutomation(Automation $automation): void { if ($automation->getStatus() === Automation::STATUS_DEACTIVATING) { $activeRuns = $this->automationRunStorage->getCountForAutomation($automation, AutomationRun::STATUS_RUNNING); // Set a deactivating Automation to draft once all automation runs are finished. if ($activeRuns === 0) { $automation->setStatus(Automation::STATUS_DRAFT); $this->automationStorage->updateAutomation($automation); } } } }
Fatal error: Uncaught Error: Class "MailPoet\Automation\Engine\Control\StepHandler" not found in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php:1405 Stack trace: #0 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(1519): MailPoetGenerated\FreeCachedContainer->getStepHandlerService() #1 /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php(2276): MailPoetGenerated\FreeCachedContainer->getEngineService() #2 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(122): MailPoetGenerated\FreeCachedContainer->getInitializerService() #3 /htdocs/wp-content/plugins/mailpoet/vendor-prefixed/symfony/dependency-injection/Container.php(110): MailPoetVendor\Symfony\Component\DependencyInjection\Container->make('MailPoet\\Config...', 1) #4 /htdocs/wp-content/plugins/mailpoet/lib/DI/ContainerWrapper.php(39): MailPoetVendor\Symfony\Component\DependencyInjection\Container->get('MailPoet\\Config...') #5 /htdocs/wp-content/plugins/mailpoet/mailpoet_initializer.php(89): MailPoet\DI\ContainerWrapper->get('MailPoet\\Config...') #6 /htdocs/wp-content/plugins/mailpoet/mailpoet.php(206): require_once('/htdocs/wp-cont...') #7 /htdocs/wp-settings.php(462): include_once('/htdocs/wp-cont...') #8 /htdocs/wp-config.php(96): require_once('/htdocs/wp-sett...') #9 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #10 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #11 /htdocs/index.php(17): require('/htdocs/wp-blog...') #12 {main} thrown in /htdocs/wp-content/plugins/mailpoet/generated/FreeCachedContainer.php on line 1405