From e9ba7eb2d8cb4d5603401e72321a618aec223149 Mon Sep 17 00:00:00 2001 From: Michele Fantetti Date: Sat, 9 Dec 2017 18:10:10 +0100 Subject: [PATCH 1/3] Update CrontabManager.php If crontab is already populated, 'php bin/magento cron:install' adds '#~ MAGENTO START' and the rest of code directly to the last row of crontab without any spaces. --- lib/internal/Magento/Framework/Crontab/CrontabManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Crontab/CrontabManager.php b/lib/internal/Magento/Framework/Crontab/CrontabManager.php index cd0dcdaeaa6a1..b06e12a7736e3 100644 --- a/lib/internal/Magento/Framework/Crontab/CrontabManager.php +++ b/lib/internal/Magento/Framework/Crontab/CrontabManager.php @@ -114,7 +114,7 @@ public function removeTasks() private function generateSection($content, $tasks = []) { if ($tasks) { - $content .= self::TASKS_BLOCK_START . PHP_EOL; + $content .= PHP_EOL . self::TASKS_BLOCK_START . PHP_EOL; foreach ($tasks as $task) { $content .= $task['expression'] . ' ' . PHP_BINARY . ' '. $task['command'] . PHP_EOL; } From 491ed56238c618d84fe2b6a6a5007ead43a64883 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Mon, 11 Dec 2017 16:00:53 +0200 Subject: [PATCH 2/3] magento/magento2#12610 --- .../Magento/Framework/Crontab/CrontabManager.php | 7 ++++++- .../Crontab/Test/Unit/CrontabManagerTest.php | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Crontab/CrontabManager.php b/lib/internal/Magento/Framework/Crontab/CrontabManager.php index b06e12a7736e3..5a4cdac432193 100644 --- a/lib/internal/Magento/Framework/Crontab/CrontabManager.php +++ b/lib/internal/Magento/Framework/Crontab/CrontabManager.php @@ -114,7 +114,12 @@ public function removeTasks() private function generateSection($content, $tasks = []) { if ($tasks) { - $content .= PHP_EOL . self::TASKS_BLOCK_START . PHP_EOL; + // Add EOL symbol to previous line if not exist. + if (substr($content, -strlen(PHP_EOL)) !== PHP_EOL) { + $content .= PHP_EOL; + } + + $content .= self::TASKS_BLOCK_START . PHP_EOL; foreach ($tasks as $task) { $content .= $task['expression'] . ' ' . PHP_BINARY . ' '. $task['command'] . PHP_EOL; } diff --git a/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php b/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php index e4088b1e4befc..71a4c6a6999e0 100644 --- a/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php +++ b/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php @@ -339,6 +339,17 @@ public function saveTasksDataProvider() . ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, ], + [ + 'tasks' => [ + ['command' => '{magentoRoot}run.php % cron:run | grep -v "Ran \'jobs\' by schedule"'] + ], + 'content' => '* * * * * /bin/php /var/www/cron.php', + 'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php' + . ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + ], ]; } } From 5bc45d98ef678b1e5b7e048debfb53199f75ffe7 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Mon, 11 Dec 2017 16:38:34 +0200 Subject: [PATCH 3/3] magento/magento2#12610 --- .../Framework/Crontab/Test/Unit/CrontabManagerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php b/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php index ca74077be04b0..3c52b5d33a5ef 100644 --- a/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php +++ b/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php @@ -343,10 +343,10 @@ public function saveTasksDataProvider() ], 'content' => '* * * * * /bin/php /var/www/cron.php', 'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL + . CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL . '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php' . ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL - . CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL, + . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL, ], ]; }