From e093edb5f217b1316ae16d14603a33897dc20eae Mon Sep 17 00:00:00 2001 From: Adeel Qamar Date: Tue, 23 Apr 2019 12:29:29 +0000 Subject: [PATCH 1/3] Merged PR 13225: get campaigns older than 2 hour and expire them Problem: Campaigns can be stuck in "Processing" state in Magento if their status in EC has not changed from "Sending" to "Sent". This prevents further campaigns to send out. Solution: Expire campaigns that are in "Processing" state for more than 2 hours. To Test: - Campaigns are expired that are in "Processing" state for more than 2 hours. Related work items: #86248 --- code/Dotdigitalgroup/Email/Model/Campaign.php | 31 +++++++++++++++++++ .../Email/Model/Resource/Campaign.php | 19 ++++++++++++ 2 files changed, 50 insertions(+) diff --git a/code/Dotdigitalgroup/Email/Model/Campaign.php b/code/Dotdigitalgroup/Email/Model/Campaign.php index 6c82bd7ae..9d55b15f0 100755 --- a/code/Dotdigitalgroup/Email/Model/Campaign.php +++ b/code/Dotdigitalgroup/Email/Model/Campaign.php @@ -97,6 +97,7 @@ public function loadByQuoteId($quoteId, $storeId) */ protected function _checkSendStatus($website) { + $this->expireExpiredCampaigns($website->getStoreIds()); $campaigns = $this->_getEmailCampaigns($website->getStoreIds(), self::PROCESSING, true); foreach ($campaigns as $campaign) { $client = Mage::helper('ddg')->getWebsiteApiClient($website); @@ -113,6 +114,19 @@ protected function _checkSendStatus($website) } } + /** + * @param array $storeIds + */ + private function expireExpiredCampaigns($storeIds) + { + $expiredCampaigns = $this->getExpiredEmailCampaignsByStoreIds($storeIds); + $ids = $expiredCampaigns->getColumnValues('id'); + if (! empty($ids)) { + $this->getResource()->expireCampaigns($ids); + } + } + + /** * Sending the campaigns. * @@ -268,4 +282,21 @@ protected function _getEmailCampaigns($storeIds, $sendStatus = 0, $sendIdCheck = //@codingStandardsIgnoreEnd return $emailCollection; } + + /** + * @param array $storeIds + * @return Dotdigitalgroup_Email_Model_Resource_Campaign_Collection + */ + private function getExpiredEmailCampaignsByStoreIds($storeIds) + { + $time = Zend_Date::now(Mage::app()->getLocale()->getLocale())->subHour(2); + $campaignCollection = $this->getCollection() + ->addFieldToFilter('campaign_id', array('notnull' => true)) + ->addFieldToFilter('send_status', Dotdigitalgroup_Email_Model_Campaign::PROCESSING) + ->addFieldToFilter('store_id', array('in' => $storeIds)) + ->addFieldToFilter('send_id', array('notnull' => true)) + ->addFieldToFilter('updated_at', array('lt' => $time->toString('yyyy-MM-dd HH:mm'))); + + return $campaignCollection; + } } \ No newline at end of file diff --git a/code/Dotdigitalgroup/Email/Model/Resource/Campaign.php b/code/Dotdigitalgroup/Email/Model/Resource/Campaign.php index 6545aaa68..98a0c0d6e 100755 --- a/code/Dotdigitalgroup/Email/Model/Resource/Campaign.php +++ b/code/Dotdigitalgroup/Email/Model/Resource/Campaign.php @@ -182,4 +182,23 @@ public function setProcessing($ids, $sendId) Mage::logException($e); } } + + /** + * @param array $ids + */ + public function expireCampaigns($ids) + { + $now = Mage::getSingleton('core/date')->gmtDate(); + $bind = array( + 'send_status' => Dotdigitalgroup_Email_Model_Campaign::SENT, + 'message' => 'Check sending status in Engagement Cloud', + 'updated_at' => $now + ); + $this->_getWriteAdapter() + ->update( + $this->getMainTable(), + $bind, + array("id in (?)" => $ids) + ); + } } \ No newline at end of file From 0a9f7400ec31d76208b51c4286189d6d2d823f8e Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Tue, 23 Apr 2019 14:14:10 +0100 Subject: [PATCH 2/3] Update to v6.4.14 --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 588115f77..540d28651 100755 --- a/README.md +++ b/README.md @@ -34,6 +34,11 @@ You are welcome to contribute to Engagement Cloud for Magento! You can either: - Fix a bug: please fork this repo and submit the Pull Request to our [Develop branch](https://github.com/dotmailer/dotmailer-magento-extension/tree/develop) Request a feature on our [roadmap](https://roadmap.dotdigital.com) +# V6.4.14 + +##### Bug Fixes +- We've fixed a problem with scheduled campaign sends, arising from campaigns stuck in a "Processing" state on Engagement Cloud. In such cases, we will expire campaigns that have been "Processing" for longer than two hours. + # V6.4.13 ##### Bug Fixes From b038cad65e97e27e140c7fcd37414427286e83c9 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Wed, 24 Apr 2019 11:07:58 +0100 Subject: [PATCH 3/3] Update version number --- code/Dotdigitalgroup/Email/etc/config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Dotdigitalgroup/Email/etc/config.xml b/code/Dotdigitalgroup/Email/etc/config.xml index 8b9ef48a0..26720188f 100755 --- a/code/Dotdigitalgroup/Email/etc/config.xml +++ b/code/Dotdigitalgroup/Email/etc/config.xml @@ -2,7 +2,7 @@ - 6.4.13 + 6.4.14