Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Jun 16, 2020
2 parents bf6dda0 + 7eac672 commit 9444320
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
16 changes: 11 additions & 5 deletions Cron/ClearLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ public function execute()
foreach ($hookCollection as $hook) {
$historyCollection = $this->historyFactory->create()->getCollection()
->addFieldToFilter('hook_id', $hook->getId());
if ($historyCollection->getSize() > $limit) {
$count = $historyCollection->getSize() - $limit;
$historyCollection->getConnection()->query(
"DELETE FROM {$historyCollection->getMainTable()} WHERE `hook_id`='{$hook->getId()}' LIMIT {$count} ORDER BY `id` DESC"
);
if ($historyCollection->count() > $limit) {
$count = $historyCollection->count() - $limit;
$historyCollection->setOrder('id');

foreach ($historyCollection->getItems() as $history) {
if ($count <= 0) {
break;
}
$history->delete();
$count--;
}
}
}
} catch (Exception $e) {
Expand Down
15 changes: 13 additions & 2 deletions Observer/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

use Exception;
use Magento\Framework\Event\Observer;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Newsletter\Model\Subscriber as SubscriberMagento;
use Magento\Store\Model\Store;
use Mageplaza\Webhook\Model\Config\Source\HookType;
use Mageplaza\Webhook\Model\Config\Source\Schedule;
Expand All @@ -41,11 +43,18 @@ class Subscriber extends AfterSave
/**
* @param Observer $observer
*
* @throws Exception
* @return $this|void
* @throws NoSuchEntityException
*/
public function execute(Observer $observer)
{
$item = $observer->getEvent()->getSubscriber();
$item = $observer->getEvent()->getSubscriber();
$subscriberStatus = $item->getSubscriberStatus();

if ($subscriberStatus === SubscriberMagento::STATUS_UNSUBSCRIBED) {
return $this;
}

if ($this->helper->getCronSchedule() !== Schedule::DISABLE) {
$hookCollection = $this->hookFactory->create()->getCollection()
->addFieldToFilter('hook_type', $this->hookType)
Expand Down Expand Up @@ -73,5 +82,7 @@ public function execute(Observer $observer)
} else {
$this->helper->send($item, $this->hookType);
}

return $this;
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "mageplaza/module-webhook",
"description": "Magento 2 Webhook Extension",
"require": {
"mageplaza/module-core": "^1.4.4",
"mageplaza/module-core": "^1.4.5",
"liquid/liquid": "^1.4.8"
},
"type": "magento2-module",
"version": "1.1.1",
"version": "1.1.2",
"license": "proprietary",
"authors": [
{
Expand Down
3 changes: 3 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<abandoned_time>10</abandoned_time>
<keep_log>10</keep_log>
</general>
<cron>
<schedule>0</schedule>
</cron>
</mp_webhook>
</default>
</config>

0 comments on commit 9444320

Please sign in to comment.