Server.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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\IConfig;
  33. use OCP\IDBConnection;
  34. use OCP\IL10N;
  35. use OCP\IURLGenerator;
  36. use OCP\Settings\IDelegatedSettings;
  37. class Server implements IDelegatedSettings {
  38. use TProfileHelper;
  39. private IDBConnection $connection;
  40. private IInitialState $initialStateService;
  41. private ProfileManager $profileManager;
  42. private ITimeFactory $timeFactory;
  43. private IConfig $config;
  44. private IL10N $l;
  45. private IURLGenerator $urlGenerator;
  46. public function __construct(IDBConnection $connection,
  47. IInitialState $initialStateService,
  48. ProfileManager $profileManager,
  49. ITimeFactory $timeFactory,
  50. IURLGenerator $urlGenerator,
  51. IConfig $config,
  52. IL10N $l) {
  53. $this->connection = $connection;
  54. $this->initialStateService = $initialStateService;
  55. $this->profileManager = $profileManager;
  56. $this->timeFactory = $timeFactory;
  57. $this->config = $config;
  58. $this->l = $l;
  59. $this->urlGenerator = $urlGenerator;
  60. }
  61. /**
  62. * @return TemplateResponse
  63. */
  64. public function getForm() {
  65. // Background jobs
  66. $this->initialStateService->provideInitialState('backgroundJobsMode', $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'));
  67. $this->initialStateService->provideInitialState('lastCron', (int)$this->config->getAppValue('core', 'lastcron', '0'));
  68. $this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge());
  69. $this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors'));
  70. $this->initialStateService->provideInitialState('cliBasedCronPossible', function_exists('posix_getpwuid'));
  71. $this->initialStateService->provideInitialState('cliBasedCronUser', function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '');
  72. $this->initialStateService->provideInitialState('backgroundJobsDocUrl', $this->urlGenerator->linkToDocs('admin-background-jobs'));
  73. // Profile page
  74. $this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled());
  75. $this->initialStateService->provideInitialState('profileEnabledByDefault', $this->isProfileEnabledByDefault($this->config));
  76. return new TemplateResponse('settings', 'settings/admin/server', [
  77. 'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
  78. ], '');
  79. }
  80. protected function cronMaxAge(): int {
  81. $query = $this->connection->getQueryBuilder();
  82. $query->select('last_checked')
  83. ->from('jobs')
  84. ->orderBy('last_checked', 'ASC')
  85. ->setMaxResults(1);
  86. $result = $query->execute();
  87. if ($row = $result->fetch()) {
  88. $maxAge = (int) $row['last_checked'];
  89. } else {
  90. $maxAge = $this->timeFactory->getTime();
  91. }
  92. $result->closeCursor();
  93. return $maxAge;
  94. }
  95. /**
  96. * @return string the section ID, e.g. 'sharing'
  97. */
  98. public function getSection(): string {
  99. return 'server';
  100. }
  101. /**
  102. * @return int whether the form should be rather on the top or bottom of
  103. * the admin section. The forms are arranged in ascending order of the
  104. * priority values. It is required to return a value between 0 and 100.
  105. *
  106. * E.g.: 70
  107. */
  108. public function getPriority(): int {
  109. return 0;
  110. }
  111. public function getName(): ?string {
  112. return $this->l->t('Background jobs');
  113. }
  114. public function getAuthorizedAppConfig(): array {
  115. return [
  116. 'core' => [
  117. '/mail_general_settings/',
  118. ],
  119. ];
  120. }
  121. }