Files
piratepoet/mailpoet/lib/Automation/Engine/Engine.php
Jan Jakes 933ee0c8c8 Call "registerHooks" method for all triggers of all active workflows
This is needed so the triggers actually work – their hooks need to be
registered when the triggers are in some active workflows.

[MAILPOET-4136]
2022-03-14 09:36:21 +01:00

53 lines
1.3 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Automation\Engine;
use MailPoet\Automation\Engine\API\API;
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
class Engine {
/** @var API */
private $api;
/** @var Registry */
private $registry;
/** @var WordPress */
private $wordPress;
/** @var WorkflowStorage */
private $workflowStorage;
public function __construct(
API $api,
Registry $registry,
WordPress $wordPress,
WorkflowStorage $workflowStorage
) {
$this->api = $api;
$this->registry = $registry;
$this->wordPress = $wordPress;
$this->workflowStorage = $workflowStorage;
}
public function initialize(): void {
// register Action Scheduler (when behind feature flag, do it only on initialization)
require_once __DIR__ . '/../../../vendor/woocommerce/action-scheduler/action-scheduler.php';
$this->api->initialize();
$this->wordPress->doAction(Hooks::INITIALIZE, [$this->registry]);
$this->registerActiveTriggerHooks();
}
private function registerActiveTriggerHooks(): void {
$triggerKeys = $this->workflowStorage->getActiveTriggerKeys();
foreach ($triggerKeys as $triggerKey) {
$instance = $this->registry->getTrigger($triggerKey);
if ($instance) {
$instance->registerHooks();
}
}
}
}