Skip to content

Commit 491ed56

Browse files
author
Stanislav Idolov
committed
1 parent e9ba7eb commit 491ed56

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/internal/Magento/Framework/Crontab/CrontabManager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ public function removeTasks()
114114
private function generateSection($content, $tasks = [])
115115
{
116116
if ($tasks) {
117-
$content .= PHP_EOL . self::TASKS_BLOCK_START . PHP_EOL;
117+
// Add EOL symbol to previous line if not exist.
118+
if (substr($content, -strlen(PHP_EOL)) !== PHP_EOL) {
119+
$content .= PHP_EOL;
120+
}
121+
122+
$content .= self::TASKS_BLOCK_START . PHP_EOL;
118123
foreach ($tasks as $task) {
119124
$content .= $task['expression'] . ' ' . PHP_BINARY . ' '. $task['command'] . PHP_EOL;
120125
}

lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,17 @@ public function saveTasksDataProvider()
339339
. ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL
340340
. CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL,
341341
],
342+
[
343+
'tasks' => [
344+
['command' => '{magentoRoot}run.php % cron:run | grep -v "Ran \'jobs\' by schedule"']
345+
],
346+
'content' => '* * * * * /bin/php /var/www/cron.php',
347+
'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
348+
. CrontabManagerInterface::TASKS_BLOCK_START . PHP_EOL
349+
. '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php'
350+
. ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL
351+
. CrontabManagerInterface::TASKS_BLOCK_END . PHP_EOL,
352+
],
342353
];
343354
}
344355
}

0 commit comments

Comments
 (0)