diff --git a/Cron/SyncStatistics.php b/Cron/SyncStatistics.php new file mode 100644 index 00000000..25b2cb22 --- /dev/null +++ b/Cron/SyncStatistics.php @@ -0,0 +1,57 @@ +helper = $helper; + $this->mailchimpNotificationCollectionFactory = $mailchimpNotificationCollectionFactory; + } + public function execute() + { + $this->helper->log("Sync statistics started"); + if ($this->helper->isSupportEnabled()) + { + $collection = $this->getCollection(); + /** + * @var $collectionItem \Ebizmarts\MailChimp\Model\MailChimpNotification + */ + foreach ($collection as $collectionItem) + { + $this->syncData($collectionItem->getNotificationData()); + $collectionItem->setProcessed(true); + $collectionItem->setSyncedAt($this->helper->getGmtDate()); + $collectionItem->getResource()->save($collectionItem); + } + } else { + $this->helper->log("Support is off"); + } + + $this->helper->log("Sync statistics finished"); + } + private function getCollection() + { + $collection = $this->mailchimpNotificationCollectionFactory->create(); + $collection->addFieldToFilter('processed', 0); + $collection->setOrder('generated_at', 'ASC'); + + return $collection; + } + private function syncData($data) + { + $this->helper->log($data); + } + private function cleanData() + { + + } +} diff --git a/Helper/Data.php b/Helper/Data.php index e091d768..4c0d8a3e 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -54,6 +54,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper const XML_POPUP_FORM = 'mailchimp/general/popup_form'; const XML_POPUP_URL = 'mailchimp/general/popup_url'; const XML_CLEAN_ERROR_MONTHS = 'mailchimp/ecommerce/clean_errors_months'; + const XML_ENABLE_SUPPORT = 'mailchimp/general/enable_support'; const ORDER_STATE_OK = 'complete'; @@ -284,6 +285,10 @@ public function isMailChimpEnabled($store = null) { return $this->getConfigValue(self::XML_PATH_ACTIVE, $store); } + public function isSupportEnabled() + { + return $this->getConfigValue(self::XML_ENABLE_SUPPORT); + } /** * @param null $store diff --git a/Model/ResourceModel/MailchimpNotification/Collection.php b/Model/ResourceModel/MailchimpNotification/Collection.php new file mode 100644 index 00000000..c8f4d8e8 --- /dev/null +++ b/Model/ResourceModel/MailchimpNotification/Collection.php @@ -0,0 +1,14 @@ +_init( + \Ebizmarts\MailChimp\Model\MailchimpNotification::class, + \Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification::class + ); + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 8a7b3bff..ca171448 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -122,7 +122,7 @@ 1 - + this]]> diff --git a/etc/crontab.xml b/etc/crontab.xml index 06f16b54..a928c16d 100644 --- a/etc/crontab.xml +++ b/etc/crontab.xml @@ -30,7 +30,10 @@ 0 * * * * - 0 */6 * * * + */5 * * * * + + + */5 * * * *