5
5
*/
6
6
namespace Magento \Framework \Crontab ;
7
7
8
- use Magento \Framework \ShellInterface ;
9
- use Magento \Framework \Phrase ;
8
+ use Magento \Framework \App \Filesystem \DirectoryList ;
10
9
use Magento \Framework \Exception \LocalizedException ;
11
10
use Magento \Framework \Filesystem ;
12
- use Magento \Framework \App \Filesystem \DirectoryList ;
11
+ use Magento \Framework \Phrase ;
12
+ use Magento \Framework \ShellInterface ;
13
13
14
14
/**
15
15
* Manager works with cron tasks
@@ -38,14 +38,38 @@ public function __construct(
38
38
$ this ->filesystem = $ filesystem ;
39
39
}
40
40
41
+ /**
42
+ * @return string
43
+ */
44
+ private function getTasksBlockStart ()
45
+ {
46
+ $ tasksBlockStart = self ::TASKS_BLOCK_START ;
47
+ if (defined ('BP ' )) {
48
+ $ tasksBlockStart .= ' ' . md5 (BP );
49
+ }
50
+ return $ tasksBlockStart ;
51
+ }
52
+
53
+ /**
54
+ * @return string
55
+ */
56
+ private function getTasksBlockEnd ()
57
+ {
58
+ $ tasksBlockEnd = self ::TASKS_BLOCK_END ;
59
+ if (defined ('BP ' )) {
60
+ $ tasksBlockEnd .= ' ' . md5 (BP );
61
+ }
62
+ return $ tasksBlockEnd ;
63
+ }
64
+
41
65
/**
42
66
* {@inheritdoc}
43
67
*/
44
68
public function getTasks ()
45
69
{
46
70
$ this ->checkSupportedOs ();
47
71
$ content = $ this ->getCrontabContent ();
48
- $ pattern = '!( ' . self :: TASKS_BLOCK_START . ')(.*?)( ' . self :: TASKS_BLOCK_END . ')!s ' ;
72
+ $ pattern = '!( ' . $ this -> getTasksBlockStart () . ')(.*?)( ' . $ this -> getTasksBlockEnd () . ')!s ' ;
49
73
50
74
if (preg_match ($ pattern , $ content , $ matches )) {
51
75
$ tasks = trim ($ matches [2 ], PHP_EOL );
@@ -61,14 +85,14 @@ public function getTasks()
61
85
*/
62
86
public function saveTasks (array $ tasks )
63
87
{
64
- $ this ->checkSupportedOs ();
65
- $ baseDir = $ this ->filesystem ->getDirectoryRead (DirectoryList::ROOT )->getAbsolutePath ();
66
- $ logDir = $ this ->filesystem ->getDirectoryRead (DirectoryList::LOG )->getAbsolutePath ();
67
-
68
88
if (!$ tasks ) {
69
89
throw new LocalizedException (new Phrase ('List of tasks is empty ' ));
70
90
}
71
91
92
+ $ this ->checkSupportedOs ();
93
+ $ baseDir = $ this ->filesystem ->getDirectoryRead (DirectoryList::ROOT )->getAbsolutePath ();
94
+ $ logDir = $ this ->filesystem ->getDirectoryRead (DirectoryList::LOG )->getAbsolutePath ();
95
+
72
96
foreach ($ tasks as $ key => $ task ) {
73
97
if (empty ($ task ['expression ' ])) {
74
98
$ tasks [$ key ]['expression ' ] = '* * * * * ' ;
@@ -114,11 +138,11 @@ public function removeTasks()
114
138
private function generateSection ($ content , $ tasks = [])
115
139
{
116
140
if ($ tasks ) {
117
- $ content .= self :: TASKS_BLOCK_START . PHP_EOL ;
141
+ $ content .= $ this -> getTasksBlockStart () . PHP_EOL ;
118
142
foreach ($ tasks as $ task ) {
119
- $ content .= $ task ['expression ' ] . ' ' . PHP_BINARY . ' ' . $ task ['command ' ] . PHP_EOL ;
143
+ $ content .= $ task ['expression ' ] . ' ' . PHP_BINARY . ' ' . $ task ['command ' ] . PHP_EOL ;
120
144
}
121
- $ content .= self :: TASKS_BLOCK_END . PHP_EOL ;
145
+ $ content .= $ this -> getTasksBlockEnd () . PHP_EOL ;
122
146
}
123
147
124
148
return $ content ;
@@ -133,7 +157,8 @@ private function generateSection($content, $tasks = [])
133
157
private function cleanMagentoSection ($ content )
134
158
{
135
159
$ content = preg_replace (
136
- '! ' . preg_quote (self ::TASKS_BLOCK_START ) . '.*? ' . preg_quote (self ::TASKS_BLOCK_END . PHP_EOL ) . '!s ' ,
160
+ '! ' . preg_quote ($ this ->getTasksBlockStart ()) . '.*? '
161
+ . preg_quote ($ this ->getTasksBlockEnd () . PHP_EOL ) . '!s ' ,
137
162
'' ,
138
163
$ content
139
164
);
@@ -192,7 +217,7 @@ private function checkSupportedOs()
192
217
{
193
218
if (stripos (PHP_OS , 'WIN ' ) === 0 ) {
194
219
throw new LocalizedException (
195
- new Phrase ('Your operation system is not supported to work with this command ' )
220
+ new Phrase ('Your operating system is not supported to work with this command ' )
196
221
);
197
222
}
198
223
}
0 commit comments