Completed
Push — master ( a56ec1...2aa108 )
by Morris
44:44 queued 16:07
created

LogSettingsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Georg Ehrke <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 * @author Morris Jobke <[email protected]>
8
 * @author Thomas Müller <[email protected]>
9
 * @author Thomas Pulzer <[email protected]>
10
 *
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 OC\Log;
30
use OCP\AppFramework\Controller;
31
use OCP\AppFramework\Http\StreamResponse;
32
use OCP\ILogger;
33
use OCP\IRequest;
34
35
/**
36
 * Class LogSettingsController
37
 *
38
 * @package OC\Settings\Controller
39
 */
40
class LogSettingsController extends Controller {
41
42
	/** @var ILogger */
43
	private $log;
44
45
	public function __construct(string $appName, IRequest $request, ILogger $logger) {
46
		parent::__construct($appName, $request);
47
		$this->log = $logger;
48
	}
49
50
	/**
51
	 * download logfile
52
	 *
53
	 * @NoCSRFRequired
54
	 *
55
	 * @return StreamResponse
56
	 */
57
	public function download() {
58
		if(!$this->log instanceof Log) {
59
			throw new \UnexpectedValueException('Log file not available');
60
		}
61
		$resp = new StreamResponse($this->log->getLogPath());
62
		$resp->addHeader('Content-Type', 'application/octet-stream');
63
		$resp->addHeader('Content-Disposition', 'attachment; filename="nextcloud.log"');
64
		return $resp;
65
	}
66
}
67