Skip to content

Commit

Permalink
Merge pull request #487 from mailchimp/Issue486-2.2
Browse files Browse the repository at this point in the history
close #486
  • Loading branch information
gonzaloebiz committed Nov 26, 2018
2 parents 05cab67 + 89d1a22 commit 9383d62
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Cron/WebhookClean.php
@@ -0,0 +1,50 @@
<?php
/**
* MailChimp Magento Component
*
* @category Ebizmarts
* @package MailChimp
* @author Ebizmarts Team <info@ebizmarts.com>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 22/11/18 10:02 AM
* @file: WebhookClean.php
*/
namespace Ebizmarts\MailChimp\Cron;

class WebhookClean
{
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
protected $helper;
/**
* @var \Ebizmarts\MailChimp\Model\MailChimpWebhookRequest
*/
protected $webhooks;

/**
* WebhookClean constructor.
* @param \Ebizmarts\MailChimp\Helper\Data $helper
* @param \Ebizmarts\MailChimp\Model\MailChimpWebhookRequest $webhookRequest
*/
public function __construct(
\Ebizmarts\MailChimp\Helper\Data $helper,
\Ebizmarts\MailChimp\Model\MailChimpWebhookRequest $webhookRequest
)
{
$this->helper = $helper;
$this->webhooks = $webhookRequest;
}
public function execute()
{
try {
$connection = $this->webhooks->getResource()->getConnection();
$tableName = $this->webhooks->getResource()->getMainTable();
$quoteInto = $connection->quoteInto('processed = ? and date_add(fired_at, interval 1 month) < now()',1);
$connection->delete($tableName, $quoteInto);
} catch( \Exception $e) {
$this->helper->log($e->getMessage());
}
}
}
3 changes: 3 additions & 0 deletions etc/crontab.xml
Expand Up @@ -20,5 +20,8 @@
<job name="ebizmarts_webhooks" instance="Ebizmarts\MailChimp\Cron\Webhook" method="execute">
<schedule>*/5 * * * *</schedule>
</job>
<job name="ebizmarts_clean_webhooks" instance="Ebizmarts\MailChimp\Cron\WebhookClean" method="execute">
<schedule>0 * * * *</schedule>
</job>
</group>
</config>

0 comments on commit 9383d62

Please sign in to comment.