Deactivate action scheduler actions when another method is active
[MAILPOET-4274]
This commit is contained in:
committed by
Veljko V
parent
138354cfd8
commit
b525f9f876
@@ -7,7 +7,6 @@ use MailPoet\AutomaticEmails\AutomaticEmails;
|
||||
use MailPoet\Automation\Engine\Engine;
|
||||
use MailPoet\Automation\Engine\Hooks as AutomationHooks;
|
||||
use MailPoet\Automation\Integrations\MailPoet\MailPoetIntegration;
|
||||
use MailPoet\Cron\ActionScheduler\ActionScheduler;
|
||||
use MailPoet\Cron\CronTrigger;
|
||||
use MailPoet\Cron\DaemonActionSchedulerRunner;
|
||||
use MailPoet\Features\FeaturesController;
|
||||
@@ -107,8 +106,8 @@ class Initializer {
|
||||
/** @var PersonalDataExporters */
|
||||
private $personalDataExporters;
|
||||
|
||||
/** @var ActionScheduler */
|
||||
private $actionScheduler;
|
||||
/** @var DaemonActionSchedulerRunner */
|
||||
private $actionSchedulerRunner;
|
||||
|
||||
const INITIALIZED = 'MAILPOET_INITIALIZED';
|
||||
|
||||
@@ -139,7 +138,7 @@ class Initializer {
|
||||
MailPoetIntegration $automationMailPoetIntegration,
|
||||
FeaturesController $featuresController,
|
||||
PersonalDataExporters $personalDataExporters,
|
||||
ActionScheduler $actionScheduler
|
||||
DaemonActionSchedulerRunner $actionSchedulerRunner
|
||||
) {
|
||||
$this->rendererFactory = $rendererFactory;
|
||||
$this->accessControl = $accessControl;
|
||||
@@ -167,7 +166,7 @@ class Initializer {
|
||||
$this->automationMailPoetIntegration = $automationMailPoetIntegration;
|
||||
$this->featuresController = $featuresController;
|
||||
$this->personalDataExporters = $personalDataExporters;
|
||||
$this->actionScheduler = $actionScheduler;
|
||||
$this->actionSchedulerRunner = $actionSchedulerRunner;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
@@ -456,9 +455,7 @@ class Initializer {
|
||||
}
|
||||
|
||||
public function runDeactivation() {
|
||||
// Unschedule recurring action scheduler actions
|
||||
$this->actionScheduler->unscheduleAction(DaemonActionSchedulerRunner::DAEMON_RUN_SCHEDULER_ACTION);
|
||||
$this->actionScheduler->unscheduleAction(DaemonActionSchedulerRunner::DAEMON_TRIGGER_SCHEDULER_ACTION);
|
||||
$this->actionSchedulerRunner->deactivate();
|
||||
}
|
||||
|
||||
private function setupWoocommerceTransactionalEmails() {
|
||||
|
@@ -42,10 +42,14 @@ class CronTrigger {
|
||||
public function init() {
|
||||
$currentMethod = $this->settings->get(self::SETTING_NAME . '.method');
|
||||
try {
|
||||
if ($currentMethod === self::METHOD_ACTION_SCHEDULER) {
|
||||
$this->cronActionScheduler->init();
|
||||
return true;
|
||||
} else {
|
||||
$this->cronActionScheduler->deactivate();
|
||||
}
|
||||
if ($currentMethod === self::METHOD_WORDPRESS) {
|
||||
return $this->wordpressTrigger->run();
|
||||
} elseif ($currentMethod === self::METHOD_ACTION_SCHEDULER) {
|
||||
$this->cronActionScheduler->init();
|
||||
}
|
||||
return false;
|
||||
} catch (\Exception $e) {
|
||||
|
@@ -49,6 +49,11 @@ class DaemonActionSchedulerRunner {
|
||||
}
|
||||
}
|
||||
|
||||
public function deactivate() {
|
||||
$this->actionScheduler->unscheduleAction(self::DAEMON_TRIGGER_SCHEDULER_ACTION);
|
||||
$this->actionScheduler->unscheduleAction(self::DAEMON_RUN_SCHEDULER_ACTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* In regular intervals checks if there are scheduled tasks to execute.
|
||||
* In case there are tasks it spawns a recurring action.
|
||||
|
@@ -58,7 +58,7 @@ class CronTriggerTest extends \MailPoetUnitTest {
|
||||
DaemonActionSchedulerRunner $actionSchedulerRunner = null
|
||||
) {
|
||||
$wordpressTrigger = $wordpressTrigger ?: $this->make(WordPress::class, ['run' => true]);
|
||||
$actionSchedulerRunner = $actionSchedulerRunner ?: $this->make(DaemonActionSchedulerRunner::class, ['init' => true]);
|
||||
$actionSchedulerRunner = $actionSchedulerRunner ?: $this->make(DaemonActionSchedulerRunner::class, ['init' => true, 'deactivate' => true]);
|
||||
return new CronTrigger($wordpressTrigger, $settings, $actionSchedulerRunner);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user