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 * * * *