1
0

Server.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Settings\Settings\Admin;
  7. use OC\Profile\ProfileManager;
  8. use OC\Profile\TProfileHelper;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\AppFramework\Services\IInitialState;
  11. use OCP\AppFramework\Utility\ITimeFactory;
  12. use OCP\IAppConfig;
  13. use OCP\IConfig;
  14. use OCP\IDBConnection;
  15. use OCP\IL10N;
  16. use OCP\IURLGenerator;
  17. use OCP\Settings\IDelegatedSettings;
  18. class Server implements IDelegatedSettings {
  19. use TProfileHelper;
  20. public function __construct(
  21. private IDBConnection $connection,
  22. private IInitialState $initialStateService,
  23. private ProfileManager $profileManager,
  24. private ITimeFactory $timeFactory,
  25. private IURLGenerator $urlGenerator,
  26. private IConfig $config,
  27. private IAppConfig $appConfig,
  28. private IL10N $l,
  29. ) {
  30. }
  31. /**
  32. * @return TemplateResponse
  33. */
  34. public function getForm() {
  35. $ownerConfigFile = fileowner(\OC::$configDir . 'config.php');
  36. $cliBasedCronPossible = function_exists('posix_getpwuid') && $ownerConfigFile !== false;
  37. $cliBasedCronUser = $cliBasedCronPossible ? (posix_getpwuid($ownerConfigFile)['name'] ?? '') : '';
  38. // Background jobs
  39. $this->initialStateService->provideInitialState('backgroundJobsMode', $this->appConfig->getValueString('core', 'backgroundjobs_mode', 'ajax'));
  40. $this->initialStateService->provideInitialState('lastCron', $this->appConfig->getValueInt('core', 'lastcron', 0));
  41. $this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge());
  42. $this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors'));
  43. $this->initialStateService->provideInitialState('cliBasedCronPossible', $cliBasedCronPossible);
  44. $this->initialStateService->provideInitialState('cliBasedCronUser', $cliBasedCronUser);
  45. $this->initialStateService->provideInitialState('backgroundJobsDocUrl', $this->urlGenerator->linkToDocs('admin-background-jobs'));
  46. // Profile page
  47. $this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled());
  48. $this->initialStateService->provideInitialState('profileEnabledByDefault', $this->isProfileEnabledByDefault($this->config));
  49. return new TemplateResponse('settings', 'settings/admin/server', [
  50. 'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
  51. ], '');
  52. }
  53. protected function cronMaxAge(): int {
  54. $query = $this->connection->getQueryBuilder();
  55. $query->select('last_checked')
  56. ->from('jobs')
  57. ->orderBy('last_checked', 'ASC')
  58. ->setMaxResults(1);
  59. $result = $query->execute();
  60. if ($row = $result->fetch()) {
  61. $maxAge = (int) $row['last_checked'];
  62. } else {
  63. $maxAge = $this->timeFactory->getTime();
  64. }
  65. $result->closeCursor();
  66. return $maxAge;
  67. }
  68. /**
  69. * @return string the section ID, e.g. 'sharing'
  70. */
  71. public function getSection(): string {
  72. return 'server';
  73. }
  74. /**
  75. * @return int whether the form should be rather on the top or bottom of
  76. * the admin section. The forms are arranged in ascending order of the
  77. * priority values. It is required to return a value between 0 and 100.
  78. *
  79. * E.g.: 70
  80. */
  81. public function getPriority(): int {
  82. return 0;
  83. }
  84. public function getName(): ?string {
  85. return $this->l->t('Background jobs');
  86. }
  87. public function getAuthorizedAppConfig(): array {
  88. return [
  89. 'core' => [
  90. '/mail_general_settings/',
  91. ],
  92. ];
  93. }
  94. }