Commit b5545932 authored by Thomas Müller's avatar Thomas Müller Committed by Morris Jobke
Browse files

use StreamResponse to download the log file - fixes #14268

parent 880b31c5
...@@ -114,8 +114,7 @@ class Application extends App { ...@@ -114,8 +114,7 @@ class Application extends App {
$c->query('AppName'), $c->query('AppName'),
$c->query('Request'), $c->query('Request'),
$c->query('Config'), $c->query('Config'),
$c->query('L10N'), $c->query('L10N')
$c->query('TimeFactory')
); );
}); });
......
...@@ -25,9 +25,8 @@ namespace OC\Settings\Controller; ...@@ -25,9 +25,8 @@ namespace OC\Settings\Controller;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\DataDownloadResponse; use OCP\AppFramework\Http\StreamResponse;
use OCP\IL10N; use OCP\IL10N;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest; use OCP\IRequest;
use OCP\IConfig; use OCP\IConfig;
...@@ -47,11 +46,6 @@ class LogSettingsController extends Controller { ...@@ -47,11 +46,6 @@ class LogSettingsController extends Controller {
*/ */
private $l10n; private $l10n;
/**
* @var \OCP\ITimeFactory
*/
private $timefactory;
/** /**
* @param string $appName * @param string $appName
* @param IRequest $request * @param IRequest $request
...@@ -60,13 +54,10 @@ class LogSettingsController extends Controller { ...@@ -60,13 +54,10 @@ class LogSettingsController extends Controller {
public function __construct($appName, public function __construct($appName,
IRequest $request, IRequest $request,
IConfig $config, IConfig $config,
IL10N $l10n, IL10N $l10n) {
ITimeFactory $timeFactory) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->config = $config; $this->config = $config;
$this->l10n = $l10n; $this->l10n = $l10n;
$this->timefactory = $timeFactory;
} }
/** /**
...@@ -107,32 +98,11 @@ class LogSettingsController extends Controller { ...@@ -107,32 +98,11 @@ class LogSettingsController extends Controller {
* *
* @NoCSRFRequired * @NoCSRFRequired
* *
* @return DataDownloadResponse * @return StreamResponse
*/ */
public function download() { public function download() {
return new DataDownloadResponse( $resp = new StreamResponse(\OC_Log_Owncloud::getLogFilePath());
json_encode(\OC_Log_Owncloud::getEntries(null, null)), $resp->addHeader('Content-Disposition', 'attachment; filename="owncloud.log"');
$this->getFilenameForDownload(), return $resp;
'application/json'
);
}
/**
* get filename for the logfile that's being downloaded
*
* @param int $timestamp (defaults to time())
* @return string
*/
private function getFilenameForDownload($timestamp=null) {
$instanceId = $this->config->getSystemValue('instanceid');
$filename = implode([
'ownCloud',
$instanceId,
(!is_null($timestamp)) ? $timestamp : $this->timefactory->getTime()
], '-');
$filename .= '.log';
return $filename;
} }
} }
...@@ -66,15 +66,9 @@ class LogSettingsControllerTest extends \Test\TestCase { ...@@ -66,15 +66,9 @@ class LogSettingsControllerTest extends \Test\TestCase {
]; ];
} }
public function testGetFilenameForDownload() { public function testDownload() {
$timestamp = 42; $response = $this->logSettingsController->download();
$this->container['Config']
->expects($this->once())
->method('getSystemValue')
->with('instanceid')
->will($this->returnValue('0xF'));
$filename = \Test_Helper::invokePrivate($this->logSettingsController, 'getFilenameForDownload', [$timestamp]);
$this->assertSame('ownCloud-0xF-42.log', $filename); $this->assertInstanceOf('\OCP\AppFramework\Http\StreamResponse', $response);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment