-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync and clean statistics #2041 for magento 2.4
- Loading branch information
1 parent
c71467e
commit 720d303
Showing
5 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Ebizmarts\MailChimp\Cron; | ||
|
||
use Ebizmarts\MailChimp\Helper\Data as MailChimpHelper; | ||
use Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification\CollectionFactory as MailchimpNotificationCollectionFactory; | ||
class SyncStatistics | ||
{ | ||
private $helper; | ||
private $mailchimpNotificationCollectionFactory; | ||
public function __construct( | ||
MailChimpHelper $helper, | ||
MailchimpNotificationCollectionFactory $mailchimpNotificationCollectionFactory | ||
) | ||
{ | ||
$this->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() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification; | ||
|
||
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection | ||
{ | ||
protected function _construct() | ||
{ | ||
$this->_init( | ||
\Ebizmarts\MailChimp\Model\MailchimpNotification::class, | ||
\Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification::class | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters