diff --git a/lib/internal/Magento/Framework/Crontab/CrontabManager.php b/lib/internal/Magento/Framework/Crontab/CrontabManager.php index 1f079b766c22e..94e2027abd135 100644 --- a/lib/internal/Magento/Framework/Crontab/CrontabManager.php +++ b/lib/internal/Magento/Framework/Crontab/CrontabManager.php @@ -138,6 +138,11 @@ public function removeTasks() private function generateSection($content, $tasks = []) { if ($tasks) { + // Add EOL symbol to previous line if not exist. + if (substr($content, -strlen(PHP_EOL)) !== PHP_EOL) { + $content .= PHP_EOL; + } + $content .= $this->getTasksBlockStart() . 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 779bc7621be7c..3c52b5d33a5ef 100644 --- a/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php +++ b/lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php @@ -337,6 +337,17 @@ public function saveTasksDataProvider() . ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL . CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . 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 . ' ' . 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 . ' ' . md5(BP) . PHP_EOL, + ], ]; } }