Deactivate action scheduler recurring actions on plugin deactivation
We need to cleanup these recurring actions otherwise they would be rescheduled indefinitely. [MAILPOET-4274]
This commit is contained in:
committed by
Veljko V
parent
e3fbf2421d
commit
272e875643
@@ -7,7 +7,9 @@ use MailPoet\AutomaticEmails\AutomaticEmails;
|
|||||||
use MailPoet\Automation\Engine\Engine;
|
use MailPoet\Automation\Engine\Engine;
|
||||||
use MailPoet\Automation\Engine\Hooks as AutomationHooks;
|
use MailPoet\Automation\Engine\Hooks as AutomationHooks;
|
||||||
use MailPoet\Automation\Integrations\MailPoet\MailPoetIntegration;
|
use MailPoet\Automation\Integrations\MailPoet\MailPoetIntegration;
|
||||||
|
use MailPoet\Cron\ActionScheduler\ActionScheduler;
|
||||||
use MailPoet\Cron\CronTrigger;
|
use MailPoet\Cron\CronTrigger;
|
||||||
|
use MailPoet\Cron\DaemonActionSchedulerRunner;
|
||||||
use MailPoet\Features\FeaturesController;
|
use MailPoet\Features\FeaturesController;
|
||||||
use MailPoet\InvalidStateException;
|
use MailPoet\InvalidStateException;
|
||||||
use MailPoet\PostEditorBlocks\PostEditorBlock;
|
use MailPoet\PostEditorBlocks\PostEditorBlock;
|
||||||
@@ -102,9 +104,12 @@ class Initializer {
|
|||||||
/** @var FeaturesController */
|
/** @var FeaturesController */
|
||||||
private $featuresController;
|
private $featuresController;
|
||||||
|
|
||||||
/*** @var PersonalDataExporters */
|
/** @var PersonalDataExporters */
|
||||||
private $personalDataExporters;
|
private $personalDataExporters;
|
||||||
|
|
||||||
|
/** @var ActionScheduler */
|
||||||
|
private $actionScheduler;
|
||||||
|
|
||||||
const INITIALIZED = 'MAILPOET_INITIALIZED';
|
const INITIALIZED = 'MAILPOET_INITIALIZED';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -133,7 +138,8 @@ class Initializer {
|
|||||||
Engine $automationEngine,
|
Engine $automationEngine,
|
||||||
MailPoetIntegration $automationMailPoetIntegration,
|
MailPoetIntegration $automationMailPoetIntegration,
|
||||||
FeaturesController $featuresController,
|
FeaturesController $featuresController,
|
||||||
PersonalDataExporters $personalDataExporters
|
PersonalDataExporters $personalDataExporters,
|
||||||
|
ActionScheduler $actionScheduler
|
||||||
) {
|
) {
|
||||||
$this->rendererFactory = $rendererFactory;
|
$this->rendererFactory = $rendererFactory;
|
||||||
$this->accessControl = $accessControl;
|
$this->accessControl = $accessControl;
|
||||||
@@ -161,6 +167,7 @@ class Initializer {
|
|||||||
$this->automationMailPoetIntegration = $automationMailPoetIntegration;
|
$this->automationMailPoetIntegration = $automationMailPoetIntegration;
|
||||||
$this->featuresController = $featuresController;
|
$this->featuresController = $featuresController;
|
||||||
$this->personalDataExporters = $personalDataExporters;
|
$this->personalDataExporters = $personalDataExporters;
|
||||||
|
$this->actionScheduler = $actionScheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
@@ -192,6 +199,15 @@ class Initializer {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// deactivation function
|
||||||
|
$this->wpFunctions->registerDeactivationHook(
|
||||||
|
Env::$file,
|
||||||
|
[
|
||||||
|
$this,
|
||||||
|
'runDeactivation',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$this->wpFunctions->addAction('activated_plugin', [
|
$this->wpFunctions->addAction('activated_plugin', [
|
||||||
new PluginActivatedHook(new DeferredAdminNotices),
|
new PluginActivatedHook(new DeferredAdminNotices),
|
||||||
'action',
|
'action',
|
||||||
@@ -439,6 +455,12 @@ class Initializer {
|
|||||||
return array_merge($tables, $mailpoetTables);
|
return array_merge($tables, $mailpoetTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function runDeactivation() {
|
||||||
|
// Unschedule recurring action scheduler actions
|
||||||
|
$this->actionScheduler->unscheduleAction(DaemonActionSchedulerRunner::DAEMON_RUN_SCHEDULER_ACTION);
|
||||||
|
$this->actionScheduler->unscheduleAction(DaemonActionSchedulerRunner::DAEMON_TRIGGER_SCHEDULER_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
private function setupWoocommerceTransactionalEmails() {
|
private function setupWoocommerceTransactionalEmails() {
|
||||||
$wcEnabled = $this->wcHelper->isWooCommerceActive();
|
$wcEnabled = $this->wcHelper->isWooCommerceActive();
|
||||||
$optInEnabled = $this->settings->get('woocommerce.use_mailpoet_editor', false);
|
$optInEnabled = $this->settings->get('woocommerce.use_mailpoet_editor', false);
|
||||||
|
@@ -397,6 +397,10 @@ class Functions {
|
|||||||
return register_activation_hook($file, $function);
|
return register_activation_hook($file, $function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function registerDeactivationHook($file, $function) {
|
||||||
|
return register_deactivation_hook($file, $function);
|
||||||
|
}
|
||||||
|
|
||||||
public function registerPostType($postType, $args = []) {
|
public function registerPostType($postType, $args = []) {
|
||||||
return register_post_type($postType, $args);
|
return register_post_type($postType, $args);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user