You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.9 KiB

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