CronErrors.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\IConfig;
  9. use OCP\IL10N;
  10. use OCP\SetupCheck\ISetupCheck;
  11. use OCP\SetupCheck\SetupResult;
  12. class CronErrors implements ISetupCheck {
  13. public function __construct(
  14. private IL10N $l10n,
  15. private IConfig $config,
  16. ) {
  17. }
  18. public function getCategory(): string {
  19. return 'system';
  20. }
  21. public function getName(): string {
  22. return $this->l10n->t('Cron errors');
  23. }
  24. public function run(): SetupResult {
  25. $errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true);
  26. if (is_array($errors) && count($errors) > 0) {
  27. return SetupResult::error(
  28. $this->l10n->t(
  29. "It was not possible to execute the cron job via CLI. The following technical errors have appeared:\n%s",
  30. implode("\n", array_map(fn (array $error) => '- '.$error['error'].' '.$error['hint'], $errors))
  31. )
  32. );
  33. } else {
  34. return SetupResult::success($this->l10n->t('The last cron job ran without errors.'));
  35. }
  36. }
  37. }