Server.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\Settings\Settings\Admin;
  27. use OC\Profile\ProfileManager;
  28. use OC\Profile\TProfileHelper;
  29. use OCP\AppFramework\Http\TemplateResponse;
  30. use OCP\AppFramework\Services\IInitialState;
  31. use OCP\AppFramework\Utility\ITimeFactory;
  32. use OCP\IAppConfig;
  33. use OCP\IConfig;
  34. use OCP\IDBConnection;
  35. use OCP\IL10N;
  36. use OCP\IURLGenerator;
  37. use OCP\Settings\IDelegatedSettings;
  38. class Server implements IDelegatedSettings {
  39. use TProfileHelper;
  40. public function __construct(
  41. private IDBConnection $connection,
  42. private IInitialState $initialStateService,
  43. private ProfileManager $profileManager,
  44. private ITimeFactory $timeFactory,
  45. private IURLGenerator $urlGenerator,
  46. private IConfig $config,
  47. private IAppConfig $appConfig,
  48. private IL10N $l,
  49. ) {
  50. }
  51. /**
  52. * @return TemplateResponse
  53. */
  54. public function getForm() {
  55. $ownerConfigFile = fileowner(\OC::$configDir . 'config.php');
  56. $cliBasedCronPossible = function_exists('posix_getpwuid') && $ownerConfigFile !== false;
  57. $cliBasedCronUser = $cliBasedCronPossible ? (posix_getpwuid($ownerConfigFile)['name'] ?? '') : '';
  58. // Background jobs
  59. $this->initialStateService->provideInitialState('backgroundJobsMode', $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'));
  60. $this->initialStateService->provideInitialState('lastCron', $this->appConfig->getValueInt('core', 'lastcron', 0));
  61. $this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge());
  62. $this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors'));
  63. $this->initialStateService->provideInitialState('cliBasedCronPossible', $cliBasedCronPossible);
  64. $this->initialStateService->provideInitialState('cliBasedCronUser', $cliBasedCronUser);
  65. $this->initialStateService->provideInitialState('backgroundJobsDocUrl', $this->urlGenerator->linkToDocs('admin-background-jobs'));
  66. // Profile page
  67. $this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled());
  68. $this->initialStateService->provideInitialState('profileEnabledByDefault', $this->isProfileEnabledByDefault($this->config));
  69. return new TemplateResponse('settings', 'settings/admin/server', [
  70. 'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
  71. ], '');
  72. }
  73. protected function cronMaxAge(): int {
  74. $query = $this->connection->getQueryBuilder();
  75. $query->select('last_checked')
  76. ->from('jobs')
  77. ->orderBy('last_checked', 'ASC')
  78. ->setMaxResults(1);
  79. $result = $query->execute();
  80. if ($row = $result->fetch()) {
  81. $maxAge = (int) $row['last_checked'];
  82. } else {
  83. $maxAge = $this->timeFactory->getTime();
  84. }
  85. $result->closeCursor();
  86. return $maxAge;
  87. }
  88. /**
  89. * @return string the section ID, e.g. 'sharing'
  90. */
  91. public function getSection(): string {
  92. return 'server';
  93. }
  94. /**
  95. * @return int whether the form should be rather on the top or bottom of
  96. * the admin section. The forms are arranged in ascending order of the
  97. * priority values. It is required to return a value between 0 and 100.
  98. *
  99. * E.g.: 70
  100. */
  101. public function getPriority(): int {
  102. return 0;
  103. }
  104. public function getName(): ?string {
  105. return $this->l->t('Background jobs');
  106. }
  107. public function getAuthorizedAppConfig(): array {
  108. return [
  109. 'core' => [
  110. '/mail_general_settings/',
  111. ],
  112. ];
  113. }
  114. }