Server.php 3.1 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 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 OCP\AppFramework\Http\TemplateResponse;
  28. use OCP\AppFramework\Utility\ITimeFactory;
  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 ITimeFactory */
  36. private $timeFactory;
  37. /** @var IConfig */
  38. private $config;
  39. public function __construct(IDBConnection $connection,
  40. ITimeFactory $timeFactory,
  41. IConfig $config) {
  42. $this->connection = $connection;
  43. $this->timeFactory = $timeFactory;
  44. $this->config = $config;
  45. }
  46. /**
  47. * @return TemplateResponse
  48. */
  49. public function getForm() {
  50. $parameters = [
  51. // Background jobs
  52. 'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
  53. 'lastcron' => $this->config->getAppValue('core', 'lastcron', false),
  54. 'cronMaxAge' => $this->cronMaxAge(),
  55. 'cronErrors' => $this->config->getAppValue('core', 'cronErrors'),
  56. 'cli_based_cron_possible' => function_exists('posix_getpwuid'),
  57. 'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
  58. ];
  59. return new TemplateResponse('settings', 'settings/admin/server', $parameters, '');
  60. }
  61. protected function cronMaxAge(): int {
  62. $query = $this->connection->getQueryBuilder();
  63. $query->select('last_checked')
  64. ->from('jobs')
  65. ->orderBy('last_checked', 'ASC')
  66. ->setMaxResults(1);
  67. $result = $query->execute();
  68. if ($row = $result->fetch()) {
  69. $maxAge = (int) $row['last_checked'];
  70. } else {
  71. $maxAge = $this->timeFactory->getTime();
  72. }
  73. $result->closeCursor();
  74. return $maxAge;
  75. }
  76. /**
  77. * @return string the section ID, e.g. 'sharing'
  78. */
  79. public function getSection(): string {
  80. return 'server';
  81. }
  82. /**
  83. * @return int whether the form should be rather on the top or bottom of
  84. * the admin section. The forms are arranged in ascending order of the
  85. * priority values. It is required to return a value between 0 and 100.
  86. *
  87. * E.g.: 70
  88. */
  89. public function getPriority(): int {
  90. return 0;
  91. }
  92. }