wp = $wp; $this->automationRunStorage = $automationRunStorage; } public function init(): void { $this->wp->addAction(Hooks::AUTOMATION_RUN_CREATE, [$this, 'createAutomationRun'], 5, 2); } public function createAutomationRun(bool $result, StepRunArgs $args): bool { if (!$result) { return $result; } $automation = $args->getAutomation(); $runOnlyOnce = $automation->getMeta('mailpoet:run-once-per-subscriber'); if (!$runOnlyOnce) { return true; } $subscriberSubject = $args->getAutomationRun()->getSubjects(SubscriberSubject::KEY); if (!$subscriberSubject) { return true; } return $this->automationRunStorage->getCountByAutomationAndSubject($automation, current($subscriberSubject)) === 0; } }