From 3d4e4896115f6360d9b57008b1df53fc72421dce Mon Sep 17 00:00:00 2001 From: gonzalo Date: Wed, 27 Nov 2024 14:46:42 -0300 Subject: [PATCH] remove data from notification older than 1 week #2041 for magento 2.4 --- Cron/SyncStatistics.php | 25 ++++++++++++++++++++++--- etc/crontab.xml | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Cron/SyncStatistics.php b/Cron/SyncStatistics.php index 25b2cb22..5e2b306d 100644 --- a/Cron/SyncStatistics.php +++ b/Cron/SyncStatistics.php @@ -4,17 +4,30 @@ use Ebizmarts\MailChimp\Helper\Data as MailChimpHelper; use Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification\CollectionFactory as MailchimpNotificationCollectionFactory; +use Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification; class SyncStatistics { + /** + * @var MailChimpHelper + */ private $helper; + /** + * @var MailchimpNotificationCollectionFactory + */ private $mailchimpNotificationCollectionFactory; + /** + * @var MailchimpNotification + */ + private $mailchimpNotification; public function __construct( MailChimpHelper $helper, - MailchimpNotificationCollectionFactory $mailchimpNotificationCollectionFactory + MailchimpNotificationCollectionFactory $mailchimpNotificationCollectionFactory, + MailchimpNotification $mailchimpNotification ) { $this->helper = $helper; $this->mailchimpNotificationCollectionFactory = $mailchimpNotificationCollectionFactory; + $this->mailchimpNotification = $mailchimpNotification; } public function execute() { @@ -35,7 +48,7 @@ public function execute() } else { $this->helper->log("Support is off"); } - + $this->cleanData(); $this->helper->log("Sync statistics finished"); } private function getCollection() @@ -52,6 +65,12 @@ private function syncData($data) } private function cleanData() { - + try { + $connection = $this->mailchimpNotification->getConnection(); + $tableName = $this->mailchimpNotification->getMainTable(); + $connection->delete($tableName, ['date_add(generated_at , interval 1 week) <= NOW()']); + } catch (\Exception $e) { + $this->helper->log($e->getMessage()); + } } } diff --git a/etc/crontab.xml b/etc/crontab.xml index a928c16d..eea22334 100644 --- a/etc/crontab.xml +++ b/etc/crontab.xml @@ -33,7 +33,7 @@ */5 * * * * - */5 * * * * + */10 * * * *