Server.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Settings\Settings\Admin;
  26. use OCP\AppFramework\Http\TemplateResponse;
  27. use OCP\AppFramework\Utility\ITimeFactory;
  28. use OCP\IConfig;
  29. use OCP\IDBConnection;
  30. use OCP\Settings\ISettings;
  31. class Server implements ISettings {
  32. /** @var IDBConnection */
  33. private $connection;
  34. /** @var ITimeFactory */
  35. private $timeFactory;
  36. /** @var IConfig */
  37. private $config;
  38. public function __construct(IDBConnection $connection,
  39. ITimeFactory $timeFactory,
  40. IConfig $config) {
  41. $this->connection = $connection;
  42. $this->timeFactory = $timeFactory;
  43. $this->config = $config;
  44. }
  45. /**
  46. * @return TemplateResponse
  47. */
  48. public function getForm() {
  49. $parameters = [
  50. // Background jobs
  51. 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
  52. 'lastcron' => $this->config->getAppValue('core', 'lastcron', false),
  53. 'cronMaxAge' => $this->cronMaxAge(),
  54. 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'),
  55. 'cli_based_cron_possible' => function_exists('posix_getpwuid'),
  56. 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
  57. ];
  58. return new TemplateResponse('settings', 'settings/admin/server', $parameters, '');
  59. }
  60. protected function cronMaxAge(): int {
  61. $query = $this->connection->getQueryBuilder();
  62. $query->select('last_checked')
  63. ->from('jobs')
  64. ->orderBy('last_checked', 'ASC')
  65. ->setMaxResults(1);
  66. $result = $query->execute();
  67. if ($row = $result->fetch()) {
  68. $maxAge = (int) $row['last_checked'];
  69. } else {
  70. $maxAge = $this->timeFactory->getTime();
  71. }
  72. $result->closeCursor();
  73. return $maxAge;
  74. }
  75. /**
  76. * @return string the section ID, e.g. 'sharing'
  77. */
  78. public function getSection(): string {
  79. return 'server';
  80. }
  81. /**
  82. * @return int whether the form should be rather on the top or bottom of
  83. * the admin section. The forms are arranged in ascending order of the
  84. * priority values. It is required to return a value between 0 and 100.
  85. *
  86. * E.g.: 70
  87. */
  88. public function getPriority(): int {
  89. return 0;
  90. }
  91. }