123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace OCA\Settings\Settings\Admin;
- use OC\Profile\ProfileManager;
- use OC\Profile\TProfileHelper;
- use OCP\AppFramework\Http\TemplateResponse;
- use OCP\AppFramework\Services\IInitialState;
- use OCP\AppFramework\Utility\ITimeFactory;
- use OCP\IConfig;
- use OCP\IDBConnection;
- use OCP\IL10N;
- use OCP\IURLGenerator;
- use OCP\Settings\IDelegatedSettings;
- class Server implements IDelegatedSettings {
- use TProfileHelper;
- private IDBConnection $connection;
- private IInitialState $initialStateService;
- private ProfileManager $profileManager;
- private ITimeFactory $timeFactory;
- private IConfig $config;
- private IL10N $l;
- private IURLGenerator $urlGenerator;
- public function __construct(IDBConnection $connection,
- IInitialState $initialStateService,
- ProfileManager $profileManager,
- ITimeFactory $timeFactory,
- IURLGenerator $urlGenerator,
- IConfig $config,
- IL10N $l) {
- $this->connection = $connection;
- $this->initialStateService = $initialStateService;
- $this->profileManager = $profileManager;
- $this->timeFactory = $timeFactory;
- $this->config = $config;
- $this->l = $l;
- $this->urlGenerator = $urlGenerator;
- }
-
- public function getForm() {
-
- $this->initialStateService->provideInitialState('backgroundJobsMode', $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'));
- $this->initialStateService->provideInitialState('lastCron', (int)$this->config->getAppValue('core', 'lastcron', '0'));
- $this->initialStateService->provideInitialState('cronMaxAge', $this->cronMaxAge());
- $this->initialStateService->provideInitialState('cronErrors', $this->config->getAppValue('core', 'cronErrors'));
- $this->initialStateService->provideInitialState('cliBasedCronPossible', function_exists('posix_getpwuid'));
- $this->initialStateService->provideInitialState('cliBasedCronUser', function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '');
- $this->initialStateService->provideInitialState('backgroundJobsDocUrl', $this->urlGenerator->linkToDocs('admin-background-jobs'));
-
- $this->initialStateService->provideInitialState('profileEnabledGlobally', $this->profileManager->isProfileEnabled());
- $this->initialStateService->provideInitialState('profileEnabledByDefault', $this->isProfileEnabledByDefault($this->config));
- return new TemplateResponse('settings', 'settings/admin/server', [
- 'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
- ], '');
- }
- protected function cronMaxAge(): int {
- $query = $this->connection->getQueryBuilder();
- $query->select('last_checked')
- ->from('jobs')
- ->orderBy('last_checked', 'ASC')
- ->setMaxResults(1);
- $result = $query->execute();
- if ($row = $result->fetch()) {
- $maxAge = (int) $row['last_checked'];
- } else {
- $maxAge = $this->timeFactory->getTime();
- }
- $result->closeCursor();
- return $maxAge;
- }
-
- public function getSection(): string {
- return 'server';
- }
-
- public function getPriority(): int {
- return 0;
- }
- public function getName(): ?string {
- return $this->l->t('Background jobs');
- }
- public function getAuthorizedAppConfig(): array {
- return [
- 'core' => [
- '/mail_general_settings/',
- ],
- ];
- }
- }
|