Skip to content

Commit 2f6ef09

Browse files
Merge pull request #205 from magmodules/release/1.15.1
Release/1.15.1
2 parents 9a3c94a + 17dd806 commit 2f6ef09

File tree

6 files changed

+74
-65
lines changed

6 files changed

+74
-65
lines changed

Cron/ItemCleanup.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
<?php
22
/**
3-
* Copyright © 2019 Magmodules.eu. All rights reserved.
3+
* Copyright © Magmodules.eu. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magmodules\Channable\Cron;
89

10+
use Magmodules\Channable\Api\Config\RepositoryInterface as ConfigProvider;
11+
use Magmodules\Channable\Api\Log\RepositoryInterface as LogRepository;
912
use Magmodules\Channable\Model\Item as ItemModel;
10-
use Magmodules\Channable\Helper\Item as ItemHelper;
1113

12-
/**
13-
* Class ItemCleanup
14-
*
15-
* @package Magmodules\Channable\Cron
16-
*/
1714
class ItemCleanup
1815
{
1916

2017
/**
21-
* @var ItemHelper
18+
* @var ConfigProvider
19+
*/
20+
private $configProvider;
21+
/**
22+
* @var LogRepository
2223
*/
23-
private $itemHelper;
24+
private $logRepository;
2425
/**
2526
* @var ItemModel
2627
*/
@@ -29,14 +30,17 @@ class ItemCleanup
2930
/**
3031
* ItemUpdate constructor.
3132
*
32-
* @param ItemModel $itemModel
33-
* @param ItemHelper $itemHelper
33+
* @param ItemModel $itemModel
34+
* @param ConfigProvider $configProvider
35+
* @param LogRepository $logRepository
3436
*/
3537
public function __construct(
3638
ItemModel $itemModel,
37-
ItemHelper $itemHelper
39+
ConfigProvider $configProvider,
40+
LogRepository $logRepository
3841
) {
39-
$this->itemHelper = $itemHelper;
42+
$this->configProvider = $configProvider;
43+
$this->logRepository = $logRepository;
4044
$this->itemModel = $itemModel;
4145
}
4246

@@ -45,14 +49,12 @@ public function __construct(
4549
*/
4650
public function execute()
4751
{
48-
if (!$this->itemHelper->isCronEnabled()) {
49-
return;
50-
}
51-
5252
try {
53-
$this->itemModel->cleanOldEntries();
53+
if ($this->configProvider->isItemCronEnabled()) {
54+
$this->itemModel->cleanOldEntries();
55+
}
5456
} catch (\Exception $e) {
55-
$this->itemHelper->addTolog('Cron ItemCleanup', $e->getMessage());
57+
$this->logRepository->addErrorLog('Cron ItemCleanup', $e->getMessage());
5658
}
5759
}
5860
}

Cron/ItemUpdate.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
<?php
22
/**
3-
* Copyright © 2019 Magmodules.eu. All rights reserved.
3+
* Copyright © Magmodules.eu. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magmodules\Channable\Cron;
89

10+
use Magmodules\Channable\Api\Config\RepositoryInterface as ConfigProvider;
11+
use Magmodules\Channable\Api\Log\RepositoryInterface as LogRepository;
912
use Magmodules\Channable\Model\Item as ItemModel;
10-
use Magmodules\Channable\Helper\Item as ItemHelper;
1113

1214
class ItemUpdate
1315
{
1416

1517
/**
16-
* @var ItemHelper
18+
* @var ConfigProvider
1719
*/
18-
private $itemHelper;
20+
private $configProvider;
21+
/**
22+
* @var LogRepository
23+
*/
24+
private $logRepository;
1925
/**
2026
* @var ItemModel
2127
*/
@@ -24,14 +30,17 @@ class ItemUpdate
2430
/**
2531
* ItemUpdate constructor.
2632
*
27-
* @param ItemModel $itemModel
28-
* @param ItemHelper $itemHelper
33+
* @param ItemModel $itemModel
34+
* @param ConfigProvider $configProvider
35+
* @param LogRepository $logRepository
2936
*/
3037
public function __construct(
3138
ItemModel $itemModel,
32-
ItemHelper $itemHelper
39+
ConfigProvider $configProvider,
40+
LogRepository $logRepository
3341
) {
34-
$this->itemHelper = $itemHelper;
42+
$this->configProvider = $configProvider;
43+
$this->logRepository = $logRepository;
3544
$this->itemModel = $itemModel;
3645
}
3746

@@ -41,14 +50,11 @@ public function __construct(
4150
public function execute()
4251
{
4352
try {
44-
$cronEnabled = $this->itemHelper->isCronEnabled();
45-
if ($cronEnabled) {
53+
if ($this->configProvider->isItemCronEnabled()) {
4654
$this->itemModel->updateAll();
4755
}
4856
} catch (\Exception $e) {
49-
$this->itemHelper->addTolog('Cron ItemUpdate', $e->getMessage());
57+
$this->logRepository->addErrorLog('Cron ItemUpdate', $e->getMessage());
5058
}
51-
52-
return $this;
5359
}
5460
}

Model/Config/Backend/Cron.php

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
<?php
22
/**
3-
* Copyright © 2019 Magmodules.eu. All rights reserved.
3+
* Copyright © Magmodules.eu. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magmodules\Channable\Model\Config\Backend;
89

9-
use Magento\Framework\App\Config\Value;
10-
use Magento\Framework\Model\Context;
11-
use Magento\Framework\Registry;
12-
use Magento\Framework\App\Config\ScopeConfigInterface;
1310
use Magento\Framework\App\Cache\TypeListInterface;
11+
use Magento\Framework\App\Config\ReinitableConfigInterface;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\Config\Value;
1414
use Magento\Framework\App\Config\ValueFactory;
15-
use Magento\Framework\Model\ResourceModel\AbstractResource;
1615
use Magento\Framework\Data\Collection\AbstractDb;
1716
use Magento\Framework\Exception\LocalizedException;
18-
use Magento\Framework\App\Config\ReinitableConfigInterface;
17+
use Magento\Framework\Model\Context;
18+
use Magento\Framework\Model\ResourceModel\AbstractResource;
19+
use Magento\Framework\Registry;
1920

20-
/**
21-
* Class Cron
22-
*
23-
* @package Magmodules\Channable\Model\Config\Backend
24-
*/
2521
class Cron extends Value
2622
{
2723

2824
const CRON_STRING_PATH = 'crontab/default/jobs/channable_item_update/schedule/cron_expr';
25+
2926
/**
3027
* @var ValueFactory
3128
*/
@@ -38,16 +35,16 @@ class Cron extends Value
3835
/**
3936
* Cron constructor.
4037
*
41-
* @param Context $context
42-
* @param Registry $registry
43-
* @param ScopeConfigInterface $config
38+
* @param Context $context
39+
* @param Registry $registry
40+
* @param ScopeConfigInterface $config
4441
* @param ReinitableConfigInterface $reinitConfig
45-
* @param TypeListInterface $cacheTypeList
46-
* @param ValueFactory $configValueFactory
47-
* @param AbstractResource|null $resource
48-
* @param AbstractDb|null $resourceCollection
49-
* @param string $runModelPath
50-
* @param array $data
42+
* @param TypeListInterface $cacheTypeList
43+
* @param ValueFactory $configValueFactory
44+
* @param AbstractResource|null $resource
45+
* @param AbstractDb|null $resourceCollection
46+
* @param string $runModelPath
47+
* @param array $data
5148
*/
5249
public function __construct(
5350
Context $context,
@@ -67,23 +64,17 @@ public function __construct(
6764
}
6865

6966
/**
70-
* @return \Magento\Framework\App\Config\Value
67+
* @return Value
7168
* @throws LocalizedException
7269
*/
73-
public function afterSave()
70+
public function afterSave(): Value
7471
{
75-
$expression = $this->getData('groups/item/fields/cron_frequency/value');
76-
77-
if ($expression == 'custom') {
78-
$expression = trim($this->getData('groups/item/fields/custom_frequency/value'));
79-
}
80-
8172
try {
8273
$this->configValueFactory->create()->load(
8374
self::CRON_STRING_PATH,
8475
'path'
8576
)->setValue(
86-
$expression
77+
$this->getExpression()
8778
)->setPath(
8879
self::CRON_STRING_PATH
8980
)->save();
@@ -94,4 +85,14 @@ public function afterSave()
9485
$this->reinitConfig->reinit();
9586
return parent::afterSave();
9687
}
88+
89+
/**
90+
* @return string|null
91+
*/
92+
private function getExpression(): ?string
93+
{
94+
return $this->getData('groups/item/fields/cron_frequency/value') == 'custom'
95+
? trim($this->getData('groups/item/fields/custom_frequency/value'))
96+
: $this->getData('groups/item/fields/cron_frequency/value');
97+
}
9798
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magmodules/magento2-channable",
33
"description": "Channable integration for Magento 2",
44
"type": "magento2-module",
5-
"version": "1.15.0",
5+
"version": "1.15.1",
66
"license": "BSD-2-Clause",
77
"homepage": "https://github.com/magmodules/magento2-channable",
88
"require": {

etc/adminhtml/system/itemupdates.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<label>Frequency</label>
7474
<source_model>Magmodules\Channable\Model\System\Config\Source\CronFrequency</source_model>
7575
<backend_model>Magmodules\Channable\Model\Config\Backend\Cron</backend_model>
76-
<config_path>magmodules_channable_marketplace/item/cron</config_path>
76+
<config_path>magmodules_channable_marketplace/item/cron_frequency</config_path>
7777
<depends>
7878
<field id="cron">1</field>
7979
</depends>

etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<general>
1313
<enable>0</enable>
1414
<limit>250</limit>
15-
<version>v1.15.0</version>
15+
<version>v1.15.1</version>
1616
</general>
1717
<data>
1818
<name_attribute>name</name_attribute>

0 commit comments

Comments
 (0)