Completed
Push — master ( 399f71...73ad09 )
by Thomas
19:59
created

LogSettingsController::getEntries()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Georg Ehrke <[email protected]>
4
 * @author Joas Schilling <[email protected]>
5
 * @author Morris Jobke <[email protected]>
6
 * @author Roeland Jago Douma <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 * @author Vincent Petry <[email protected]>
9
 *
10
 * @copyright Copyright (c) 2016, ownCloud GmbH.
11
 * @license AGPL-3.0
12
 *
13
 * This code is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License, version 3,
15
 * as published by the Free Software Foundation.
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, version 3,
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
24
 *
25
 */
26
27
namespace OC\Settings\Controller;
28
29
use OCP\AppFramework\Controller;
30
use OCP\AppFramework\Http;
31
use OCP\AppFramework\Http\JSONResponse;
32
use OCP\AppFramework\Http\StreamResponse;
33
use OCP\IL10N;
34
use OCP\IRequest;
35
use OCP\IConfig;
36
37
/**
38
 * Class LogSettingsController
39
 *
40
 * @package OC\Settings\Controller
41
 */
42
class LogSettingsController extends Controller {
43
	/**
44
	 * @var \OCP\IConfig
45
	 */
46
	private $config;
47
48
	/**
49
	 * @var \OCP\IL10N
50
	 */
51
	private $l10n;
52
53
	/**
54
	 * @param string $appName
55
	 * @param IRequest $request
56
	 * @param IConfig $config
57
	 */
58
	public function __construct($appName,
59
								IRequest $request,
60
								IConfig $config,
61
								IL10N $l10n) {
62
		parent::__construct($appName, $request);
63
		$this->config = $config;
64
		$this->l10n = $l10n;
65
	}
66
67
	/**
68
	 * set log level for logger
69
	 *
70
	 * @param int $level
71
	 * @return JSONResponse
72
	 */
73
	public function setLogLevel($level) {
74 View Code Duplication
		if ($level < 0 || $level > 4) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
			return new JSONResponse([
76
				'message' => (string) $this->l10n->t('log-level out of allowed range'),
77
			], Http::STATUS_BAD_REQUEST);
78
		}
79
80
		$this->config->setSystemValue('loglevel', $level);
81
		return new JSONResponse([
82
			'level' => $level,
83
		]);
84
	}
85
86
	/**
87
	 * download logfile
88
	 *
89
	 * @NoCSRFRequired
90
	 *
91
	 * @return StreamResponse
92
	 */
93
	public function download() {
94
		$resp = new StreamResponse(\OC\Log\Owncloud::getLogFilePath());
95
		$resp->addHeader('Content-Type', 'application/octet-stream');
96
		$resp->addHeader('Content-Disposition', 'attachment; filename="owncloud.log"');
97
		return $resp;
98
	}
99
}
100