diff --git a/changelog/unreleased/issue-36298 b/changelog/unreleased/issue-36298 new file mode 100644 index 000000000000..a8e79474fb1d --- /dev/null +++ b/changelog/unreleased/issue-36298 @@ -0,0 +1,6 @@ +Bugfix: occ system:cron only shows progess bar if option is set + +occ system:cron will only output the progess bar if the newly introduced option --progress is set. +When being executed from crontab occ system::cron shall only print out in case of error. + +https://github.com/owncloud/core/issues/36298 diff --git a/core/Command/System/Cron.php b/core/Command/System/Cron.php index 062c99689d5d..9b49f14139ce 100644 --- a/core/Command/System/Cron.php +++ b/core/Command/System/Cron.php @@ -28,6 +28,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Cron extends Command { @@ -63,7 +64,8 @@ public function __construct(IJobList $jobList, protected function configure() { $this ->setName('system:cron') - ->setDescription('Execute background jobs as cron'); + ->setDescription('Execute background jobs as cron') + ->addOption('progress', 'p', InputOption::VALUE_NONE, 'shows a progress bar - for use in manual execution. Do not use when executing from crontab'); } /** @@ -100,7 +102,9 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->config->setAppValue('core', 'backgroundjobs_mode', 'cron'); } + $showProgress = $input->getOption('progress'); $progress = new ProgressBar($output); + $progress->setFormat(" %message%\n %current% [%bar%]"); // We only ask for jobs for 14 minutes, because after 15 minutes the next // system cron task should spawn. @@ -112,9 +116,11 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->jobList->unlockJob($job); break; } - $progress->advance(); - $jobName = \get_class($job); - $progress->setMessage("Executing: {$job->getId()} - {$jobName}"); + if ($showProgress) { + $progress->advance(); + $jobName = \get_class($job); + $progress->setMessage("Executing: {$job->getId()} - {$jobName}"); + } $job->execute($this->jobList, $this->logger); @@ -134,7 +140,9 @@ protected function execute(InputInterface $input, OutputInterface $output) { if ($this->config->getSystemValue('cron_log', true)) { $this->config->setAppValue('core', 'lastcron', \time()); } - $output->writeln(''); + if ($showProgress) { + $output->writeln(''); + } return 0; } diff --git a/tests/Core/Command/System/CronTest.php b/tests/Core/Command/System/CronTest.php index f1c046310a11..81c5a51b5ecf 100644 --- a/tests/Core/Command/System/CronTest.php +++ b/tests/Core/Command/System/CronTest.php @@ -111,7 +111,7 @@ public function testCronRun() { $this->jobList->method('getNext')->willReturnOnConsecutiveCalls($job, null); $this->jobList->expects(self::once())->method('setLastJob')->with($job); - $this->commandTester->execute([]); + $this->commandTester->execute(['--progress' => true]); $output = $this->commandTester->getDisplay(); $this->assertContains('1 [->--------------------------]', $output); }