From 7987f2d873d02e3e4426c51a25aae1e996565846 Mon Sep 17 00:00:00 2001 From: Pavel Dohnal Date: Wed, 17 Mar 2021 12:03:18 +0100 Subject: [PATCH] Pause old tasks [MAILPOET-3481] --- lib/Config/Populator.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index 7425af7d42..897789de93 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -166,6 +166,7 @@ class Populator { $this->updateLastSubscribedAt(); $this->enableStatsNotificationsForAutomatedEmails(); $this->updateSentUnsubscribeLinksToInstantUnsubscribeLinks(); + $this->pauseTasksForPausedNewsletters(); $this->scheduleUnsubscribeTokens(); $this->scheduleSubscriberLinkTokens(); @@ -689,6 +690,22 @@ class Populator { )); } + private function pauseTasksForPausedNewsletters() { + if (version_compare($this->settings->get('db_version', '3.60.5'), '3.60.4', '>')) { + return; + } + global $wpdb; + $wpdb->query( + 'UPDATE `' . ScheduledTask::$_table . '` t ' . + 'JOIN `' . SendingQueue::$_table . '` q ON t.`id` = q.`task_id` ' . + 'JOIN `' . Newsletter::$_table . '` n ON n.`id` = q.`newsletter_id` ' . + 'SET t.`status` = "' . ScheduledTask::STATUS_PAUSED . '" ' . + 'WHERE ' . + ' t.`status` = "' . ScheduledTask::STATUS_SCHEDULED . '" ' . + ' AND n.`status` = "' . Newsletter::STATUS_DRAFT . '" ' + ); + } + private function addPlacementStatusToForms() { if (version_compare($this->settings->get('db_version', '3.49.0'), '3.48.1', '>')) { return;