summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-03-27 01:37:25 +0100
committerMorris Jobke <hey@morrisjobke.de>2015-03-27 11:30:32 +0100
commitb5545932e7efec24f36fae76ffe8924e31e1d55a (patch)
tree06a07a060082907df99afa3e7bbde31957189d53
parent880b31c513eb755a057ca075d462e34ace911d0e (diff)
downloadnextcloud-server-b5545932e7efec24f36fae76ffe8924e31e1d55a.tar.gz
nextcloud-server-b5545932e7efec24f36fae76ffe8924e31e1d55a.zip
use StreamResponse to download the log file - fixes #14268
-rw-r--r--settings/application.php3
-rw-r--r--settings/controller/logsettingscontroller.php42
-rw-r--r--tests/settings/controller/logsettingscontrollertest.php12
3 files changed, 10 insertions, 47 deletions
diff --git a/settings/application.php b/settings/application.php
index 6992742b8d8..397e3b3de91 100644
--- a/settings/application.php
+++ b/settings/application.php
@@ -114,8 +114,7 @@ class Application extends App {
$c->query('AppName'),
$c->query('Request'),
$c->query('Config'),
- $c->query('L10N'),
- $c->query('TimeFactory')
+ $c->query('L10N')
);
});
diff --git a/settings/controller/logsettingscontroller.php b/settings/controller/logsettingscontroller.php
index b2493c46bab..f3de1fbb7c6 100644
--- a/settings/controller/logsettingscontroller.php
+++ b/settings/controller/logsettingscontroller.php
@@ -25,9 +25,8 @@ namespace OC\Settings\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
-use OCP\AppFramework\Http\DataDownloadResponse;
+use OCP\AppFramework\Http\StreamResponse;
use OCP\IL10N;
-use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IRequest;
use OCP\IConfig;
@@ -48,11 +47,6 @@ class LogSettingsController extends Controller {
private $l10n;
/**
- * @var \OCP\ITimeFactory
- */
- private $timefactory;
-
- /**
* @param string $appName
* @param IRequest $request
* @param IConfig $config
@@ -60,13 +54,10 @@ class LogSettingsController extends Controller {
public function __construct($appName,
IRequest $request,
IConfig $config,
- IL10N $l10n,
- ITimeFactory $timeFactory) {
-
+ IL10N $l10n) {
parent::__construct($appName, $request);
$this->config = $config;
$this->l10n = $l10n;
- $this->timefactory = $timeFactory;
}
/**
@@ -107,32 +98,11 @@ class LogSettingsController extends Controller {
*
* @NoCSRFRequired
*
- * @return DataDownloadResponse
+ * @return StreamResponse
*/
public function download() {
- return new DataDownloadResponse(
- json_encode(\OC_Log_Owncloud::getEntries(null, null)),
- $this->getFilenameForDownload(),
- '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;
+ $resp = new StreamResponse(\OC_Log_Owncloud::getLogFilePath());
+ $resp->addHeader('Content-Disposition', 'attachment; filename="owncloud.log"');
+ return $resp;
}
}
diff --git a/tests/settings/controller/logsettingscontrollertest.php b/tests/settings/controller/logsettingscontrollertest.php
index 84581bf5782..60680ba4647 100644
--- a/tests/settings/controller/logsettingscontrollertest.php
+++ b/tests/settings/controller/logsettingscontrollertest.php
@@ -66,15 +66,9 @@ class LogSettingsControllerTest extends \Test\TestCase {
];
}
- public function testGetFilenameForDownload() {
- $timestamp = 42;
- $this->container['Config']
- ->expects($this->once())
- ->method('getSystemValue')
- ->with('instanceid')
- ->will($this->returnValue('0xF'));
- $filename = \Test_Helper::invokePrivate($this->logSettingsController, 'getFilenameForDownload', [$timestamp]);
+ public function testDownload() {
+ $response = $this->logSettingsController->download();
- $this->assertSame('ownCloud-0xF-42.log', $filename);
+ $this->assertInstanceOf('\OCP\AppFramework\Http\StreamResponse', $response);
}
}