Skip to content

Commit

Permalink
remove data from notification older than 1 week #2041 for magento 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Nov 27, 2024
1 parent adc2d85 commit 3d4e489
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions Cron/SyncStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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()
Expand All @@ -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());
}
}
}
2 changes: 1 addition & 1 deletion etc/crontab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<schedule>*/5 * * * *</schedule>
</job>
<job name="ebizmarts_sync_statistics" instance="Ebizmarts\MailChimp\Cron\SyncStatistics" method="execute">
<schedule>*/5 * * * *</schedule>
<schedule>*/10 * * * *</schedule>
</job>
</group>
</config>

0 comments on commit 3d4e489

Please sign in to comment.