1
1
<?php
2
2
/**
3
- * Copyright © 2019 Magmodules.eu. All rights reserved.
3
+ * Copyright © Magmodules.eu. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace Magmodules \Channable \Model \Config \Backend ;
8
9
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 ;
13
10
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 ;
14
14
use Magento \Framework \App \Config \ValueFactory ;
15
- use Magento \Framework \Model \ResourceModel \AbstractResource ;
16
15
use Magento \Framework \Data \Collection \AbstractDb ;
17
16
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 ;
19
20
20
- /**
21
- * Class Cron
22
- *
23
- * @package Magmodules\Channable\Model\Config\Backend
24
- */
25
21
class Cron extends Value
26
22
{
27
23
28
24
const CRON_STRING_PATH = 'crontab/default/jobs/channable_item_update/schedule/cron_expr ' ;
25
+
29
26
/**
30
27
* @var ValueFactory
31
28
*/
@@ -38,16 +35,16 @@ class Cron extends Value
38
35
/**
39
36
* Cron constructor.
40
37
*
41
- * @param Context $context
42
- * @param Registry $registry
43
- * @param ScopeConfigInterface $config
38
+ * @param Context $context
39
+ * @param Registry $registry
40
+ * @param ScopeConfigInterface $config
44
41
* @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
51
48
*/
52
49
public function __construct (
53
50
Context $ context ,
@@ -67,23 +64,17 @@ public function __construct(
67
64
}
68
65
69
66
/**
70
- * @return \Magento\Framework\App\Config\ Value
67
+ * @return Value
71
68
* @throws LocalizedException
72
69
*/
73
- public function afterSave ()
70
+ public function afterSave (): Value
74
71
{
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
-
81
72
try {
82
73
$ this ->configValueFactory ->create ()->load (
83
74
self ::CRON_STRING_PATH ,
84
75
'path '
85
76
)->setValue (
86
- $ expression
77
+ $ this -> getExpression ()
87
78
)->setPath (
88
79
self ::CRON_STRING_PATH
89
80
)->save ();
@@ -94,4 +85,14 @@ public function afterSave()
94
85
$ this ->reinitConfig ->reinit ();
95
86
return parent ::afterSave ();
96
87
}
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
+ }
97
98
}
0 commit comments