1
0

MaintenanceWindowStart.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\IURLGenerator;
  11. use OCP\SetupCheck\ISetupCheck;
  12. use OCP\SetupCheck\SetupResult;
  13. class MaintenanceWindowStart implements ISetupCheck {
  14. public function __construct(
  15. private IL10N $l10n,
  16. private IURLGenerator $urlGenerator,
  17. private IConfig $config,
  18. ) {
  19. }
  20. public function getCategory(): string {
  21. return 'system';
  22. }
  23. public function getName(): string {
  24. return $this->l10n->t('Maintenance window start');
  25. }
  26. public function run(): SetupResult {
  27. $configValue = $this->config->getSystemValue('maintenance_window_start', null);
  28. if ($configValue === null) {
  29. return SetupResult::warning(
  30. $this->l10n->t('Server has no maintenance window start time configured. This means resource intensive daily background jobs will also be executed during your main usage time. We recommend to set it to a time of low usage, so users are less impacted by the load caused from these heavy tasks.'),
  31. $this->urlGenerator->linkToDocs('admin-background-jobs')
  32. );
  33. }
  34. $startValue = (int) $configValue;
  35. $endValue = ($startValue + 6) % 24;
  36. return SetupResult::success(
  37. str_replace(
  38. ['{start}', '{end}'],
  39. [$startValue, $endValue],
  40. $this->l10n->t('Maintenance window to execute heavy background jobs is between {start}:00 UTC and {end}:00 UTC')
  41. )
  42. );
  43. }
  44. }