45 private function getTasksBlockStart()
49 $tasksBlockStart .=
' ' . md5(
BP);
51 return $tasksBlockStart;
57 private function getTasksBlockEnd()
61 $tasksBlockEnd .=
' ' . md5(
BP);
63 return $tasksBlockEnd;
71 $this->checkSupportedOs();
72 $content = $this->getCrontabContent();
73 $pattern =
'!(' . $this->getTasksBlockStart() .
')(.*?)(' . $this->getTasksBlockEnd() .
')!s';
76 $tasks = trim($matches[2], PHP_EOL);
77 $tasks = explode(PHP_EOL, $tasks);
93 $this->checkSupportedOs();
97 foreach ($tasks as $key => $task) {
98 if (empty($task[
'expression'])) {
99 $tasks[$key][
'expression'] =
'* * * * *';
102 if (empty($task[
'command'])) {
106 $tasks[$key][
'command'] = str_replace(
107 [
'{magentoRoot}',
'{magentoLog}'],
113 $content = $this->getCrontabContent();
126 $this->checkSupportedOs();
127 $content = $this->getCrontabContent();
139 private function generateSection(
$content, $tasks = [])
143 if (substr(
$content, -strlen(PHP_EOL)) !== PHP_EOL) {
147 $content .= $this->getTasksBlockStart() . PHP_EOL;
148 foreach ($tasks as $task) {
149 $content .= $task[
'expression'] .
' ' . PHP_BINARY .
' ' . $task[
'command'] . PHP_EOL;
151 $content .= $this->getTasksBlockEnd() . PHP_EOL;
163 private function cleanMagentoSection(
$content)
166 '!' . preg_quote($this->getTasksBlockStart()) .
'.*?' 167 . preg_quote($this->getTasksBlockEnd() . PHP_EOL) .
'!s',
182 private function getCrontabContent()
185 $content = (string)$this->shell->execute(
'crontab -l');
186 }
catch (LocalizedException $e) {
205 $this->shell->execute(
'echo "' .
$content .
'" | crontab -');
206 }
catch (LocalizedException $e) {
207 throw new LocalizedException(
208 new Phrase(
'Error during saving of crontab: %1', [$e->getPrevious()->getMessage()]),
222 private function checkSupportedOs()
224 if (stripos(PHP_OS,
'WIN') === 0) {
225 throw new LocalizedException(
226 new Phrase(
'Your operating system is not supported to work with this command')
if(!file_exists($installConfigFile)) if(!defined('TESTS_INSTALLATION_DB_CONFIG_FILE')) $shell
__construct(ShellInterface $shell, Filesystem $filesystem)