config = $config; $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.' ) ->addOption( 'check-elapsed', null, InputOption::VALUE_NONE, 'Check if the last job execution was too long ago. Return exit code 2 if so.' ) ->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'); $checkElapsed = (bool) $input->getOption('check-elapsed'); [$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()); $now = new DateTime('now'); $elapsedInterval = $now->diff($date); $output->writeln("Last Execution was ".$date->format('Y-m-d H:i:s e')); if ($checkElapsed) { $output->writeln($elapsedInterval->format('%h hours, %i minutes, %s seconds ago')); } if ($reset) { $output->writeln("Attempting to reset the job."); $this->updaterService->reset(); $output->writeln("Done, job should execute on next schedule."); return 0; } if ($checkElapsed) { $updateInterval = $this->config->getAppValue( Application::NAME, 'updateInterval', Application::DEFAULT_SETTINGS['updateInterval'] ); $threshold = ($updateInterval * 2) + 900; $elapsedSeconds = $now->getTimestamp() - $date->getTimestamp(); if ($elapsedSeconds > $threshold) { $output->writeln("Something is wrong with the news cronjob, execution delay exceeded the configured interval."); return 2; } } return 0; } }