Passed
Push — master ( b7bfe2...dd9d46 )
by Christoph
19:39 queued 11s
created

Server   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 29
dl 0
loc 68
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSection() 0 2 1
A getPriority() 0 2 1
A __construct() 0 6 1
A cronMaxAge() 0 16 2
A getForm() 0 12 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Arthur Schiwon <[email protected]>
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Morris Jobke <[email protected]>
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
28
namespace OCA\Settings\Settings\Admin;
29
30
use OCP\AppFramework\Http\TemplateResponse;
31
use OCP\AppFramework\Utility\ITimeFactory;
32
use OCP\IConfig;
33
use OCP\IDBConnection;
34
use OCP\Settings\ISettings;
35
36
class Server implements ISettings {
37
38
	/** @var IDBConnection */
39
	private $connection;
40
	/** @var ITimeFactory */
41
	private $timeFactory;
42
	/** @var IConfig */
43
	private $config;
44
45
	public function __construct(IDBConnection $connection,
46
								ITimeFactory $timeFactory,
47
								IConfig $config) {
48
		$this->connection = $connection;
49
		$this->timeFactory = $timeFactory;
50
		$this->config = $config;
51
	}
52
53
	/**
54
	 * @return TemplateResponse
55
	 */
56
	public function getForm() {
57
		$parameters = [
58
			// Background jobs
59
			'backgroundjobs_mode' => $this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax'),
60
			'lastcron'            => $this->config->getAppValue('core', 'lastcron', false),
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $default of OCP\IConfig::getAppValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
			'lastcron'            => $this->config->getAppValue('core', 'lastcron', /** @scrutinizer ignore-type */ false),
Loading history...
61
			'cronMaxAge'          => $this->cronMaxAge(),
62
			'cronErrors'          => $this->config->getAppValue('core', 'cronErrors'),
63
			'cli_based_cron_possible' => function_exists('posix_getpwuid'),
64
			'cli_based_cron_user' => function_exists('posix_getpwuid') ? posix_getpwuid(fileowner(\OC::$configDir . 'config.php'))['name'] : '',
65
		];
66
67
		return new TemplateResponse('settings', 'settings/admin/server', $parameters, '');
68
	}
69
70
	protected function cronMaxAge(): int {
71
		$query = $this->connection->getQueryBuilder();
72
		$query->select('last_checked')
73
			->from('jobs')
74
			->orderBy('last_checked', 'ASC')
75
			->setMaxResults(1);
76
77
		$result = $query->execute();
78
		if ($row = $result->fetch()) {
79
			$maxAge = (int) $row['last_checked'];
80
		} else {
81
			$maxAge = $this->timeFactory->getTime();
82
		}
83
		$result->closeCursor();
84
85
		return $maxAge;
86
	}
87
88
	/**
89
	 * @return string the section ID, e.g. 'sharing'
90
	 */
91
	public function getSection(): string {
92
		return 'server';
93
	}
94
95
	/**
96
	 * @return int whether the form should be rather on the top or bottom of
97
	 * the admin section. The forms are arranged in ascending order of the
98
	 * priority values. It is required to return a value between 0 and 100.
99
	 *
100
	 * E.g.: 70
101
	 */
102
	public function getPriority(): int {
103
		return 0;
104
	}
105
}
106