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('run_automation_once'); if (!$runOnlyOnce) { return true; } $subscriberSubject = $args->getAutomationRun()->getSubjects(SubscriberSubject::KEY); if (!$subscriberSubject) { return true; } return $this->automationRunStorage->countRunsForAutomationAndSubject($automation, current($subscriberSubject)) === 0; } }