Server.php 4.1 KB

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