diff options
author | Devlin Junker <devlin.junker@gmail.com> | 2023-10-22 13:57:14 -0700 |
---|---|---|
committer | Devlin Junker <devlin.junker@gmail.com> | 2023-10-22 14:03:52 -0700 |
commit | 3e35d781cf712efa1473b4495a48299326b52c0c (patch) | |
tree | 9643b2e75ee3139bb6c5abb102d6f69937a5169e /lib/Command/Updater/Job.php | |
parent | 94f04d4a20cbbadb7d8ad835bc7ae3dc1c4256fd (diff) | |
parent | d423ca520ca9c61233c33717d604e3183f0f486c (diff) |
Merge remote-tracking branch 'nextcloud/master' into master-merge
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'lib/Command/Updater/Job.php')
-rw-r--r-- | lib/Command/Updater/Job.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/Command/Updater/Job.php b/lib/Command/Updater/Job.php new file mode 100644 index 000000000..4404a456e --- /dev/null +++ b/lib/Command/Updater/Job.php @@ -0,0 +1,76 @@ +<?php +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + */ + +namespace OCA\News\Command\Updater; + +use DateTime; +use OCP\Util; +use OCA\News\Service\StatusService; +use OCA\News\Service\UpdaterService; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class Job extends Command +{ + /** + * @var StatusService Status service + */ + private $statusService; + + /** + * @var UpdaterService Update service + */ + private $updaterService; + + public function __construct(StatusService $statusService, UpdaterService $updaterService) + { + parent::__construct(); + $this->statusService = $statusService; + $this->updaterService = $updaterService; + } + + /** + * @return void + */ + protected function configure() + { + $this->setName('news:updater:job') + ->addOption( + 'reset', + null, + InputOption::VALUE_NONE, + 'If the job should be reset, warning this might lead to issues.' + ) + ->setDescription('Console API for checking the update job status and to reset it.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $reset = (bool) $input->getOption('reset'); + + [$major, $minor, $micro] = Util::getVersion(); + + if ($major < 26) { + $output->writeln("Error: This only works with Nextcloud 26 or newer."); + return 1; + } + $output->writeln("Checking update Status"); + $date = new DateTime(); + $date->setTimestamp($this->statusService->getUpdateTime()); + $output->writeln("Last Execution was ".$date->format('Y-m-d H:i:s e')); + + if ($reset) { + $output->writeln("Attempting to reset the job."); + $this->updaterService->reset(); + $output->writeln("Done, job should execute on next schedule."); + } + return 0; + } +} |