CronInfo.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use OCP\IAppConfig;
  9. use OCP\IConfig;
  10. use OCP\IDateTimeFormatter;
  11. use OCP\IL10N;
  12. use OCP\IURLGenerator;
  13. use OCP\SetupCheck\ISetupCheck;
  14. use OCP\SetupCheck\SetupResult;
  15. class CronInfo implements ISetupCheck {
  16. public function __construct(
  17. private IL10N $l10n,
  18. private IConfig $config,
  19. private IAppConfig $appConfig,
  20. private IURLGenerator $urlGenerator,
  21. private IDateTimeFormatter $dateTimeFormatter,
  22. ) {
  23. }
  24. public function getCategory(): string {
  25. return 'system';
  26. }
  27. public function getName(): string {
  28. return $this->l10n->t('Cron last run');
  29. }
  30. public function run(): SetupResult {
  31. $lastCronRun = $this->appConfig->getValueInt('core', 'lastcron', 0);
  32. $relativeTime = $this->dateTimeFormatter->formatTimeSpan($lastCronRun);
  33. if ((time() - $lastCronRun) > 3600) {
  34. return SetupResult::error(
  35. $this->l10n->t(
  36. 'Last background job execution ran %s. Something seems wrong. {link}.',
  37. [$relativeTime]
  38. ),
  39. descriptionParameters:[
  40. 'link' => [
  41. 'type' => 'highlight',
  42. 'id' => 'backgroundjobs',
  43. 'name' => 'Check the background job settings',
  44. 'link' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs',
  45. ],
  46. ],
  47. );
  48. } else {
  49. return SetupResult::success(
  50. $this->l10n->t(
  51. 'Last background job execution ran %s.',
  52. [$relativeTime]
  53. )
  54. );
  55. }
  56. }
  57. }