Use stream instead of rename
This commit is contained in:
parent
0a5c5d9b03
commit
51646bb3f6
|
@ -26,6 +26,7 @@ use OCA\Theming\Template;
|
|||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
|
@ -44,6 +45,8 @@ class ThemingController extends Controller {
|
|||
private $l;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
/**
|
||||
* ThemingController constructor.
|
||||
|
@ -53,19 +56,22 @@ class ThemingController extends Controller {
|
|||
* @param IConfig $config
|
||||
* @param Template $template
|
||||
* @param IL10N $l
|
||||
* @param IRootFolder $rootFolder
|
||||
*/
|
||||
public function __construct(
|
||||
$appName,
|
||||
IRequest $request,
|
||||
IConfig $config,
|
||||
Template $template,
|
||||
IL10N $l
|
||||
IL10N $l,
|
||||
IRootFolder $rootFolder
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->template = $template;
|
||||
$this->l = $l;
|
||||
$this->config = $config;
|
||||
$this->rootFolder = $rootFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,12 +112,14 @@ class ThemingController extends Controller {
|
|||
}
|
||||
$name = '';
|
||||
if(!empty($newLogo)) {
|
||||
rename($newLogo['tmp_name'], $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/themedinstancelogo');
|
||||
$target = $this->rootFolder->newFile('themedinstancelogo');
|
||||
stream_copy_to_stream(fopen($newLogo['tmp_name'], 'r'), $target->fopen('w'));
|
||||
$this->template->set('logoMime', $newLogo['type']);
|
||||
$name = $newLogo['name'];
|
||||
}
|
||||
if(!empty($newBackgroundLogo)) {
|
||||
rename($newBackgroundLogo['tmp_name'], $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/themedbackgroundlogo');
|
||||
$target = $this->rootFolder->newFile('themedbackgroundlogo');
|
||||
stream_copy_to_stream(fopen($newBackgroundLogo['tmp_name'], 'r'), $target->fopen('w'));
|
||||
$this->template->set('backgroundMime', $newBackgroundLogo['type']);
|
||||
$name = $newBackgroundLogo['name'];
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ use OCA\Theming\Controller\ThemingController;
|
|||
use OCA\Theming\Template;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
|
@ -40,6 +41,8 @@ class ThemingControllerTest extends TestCase {
|
|||
private $l10n;
|
||||
/** @var ThemingController */
|
||||
private $themingController;
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
public function setUp() {
|
||||
$this->request = $this->getMock('\\OCP\\IRequest');
|
||||
|
@ -47,12 +50,15 @@ class ThemingControllerTest extends TestCase {
|
|||
$this->template = $this->getMockBuilder('\\OCA\\Theming\\Template')
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->l10n = $this->getMock('\\OCP\\IL10N');
|
||||
$this->rootFolder = $this->getMock('\\OCP\\Files\\IRootFolder');
|
||||
|
||||
$this->themingController = new ThemingController(
|
||||
'theming',
|
||||
$this->request,
|
||||
$this->config,
|
||||
$this->template,
|
||||
$this->l10n
|
||||
$this->l10n,
|
||||
$this->rootFolder
|
||||
);
|
||||
|
||||
return parent::setUp();
|
||||
|
@ -130,16 +136,24 @@ class ThemingControllerTest extends TestCase {
|
|||
->method('getUploadedFile')
|
||||
->with('upload-login-background')
|
||||
->willReturn(null);
|
||||
$this->config
|
||||
->expects($this->at(0))
|
||||
->method('getSystemValue')
|
||||
->with('datadirectory', \OC::$SERVERROOT . '/data')
|
||||
->willReturn($destination);
|
||||
$this->l10n
|
||||
->expects($this->once())
|
||||
->method('t')
|
||||
->with('Saved')
|
||||
->willReturn('Saved');
|
||||
$file = $this->getMockBuilder('\\OCP\\Files\\File')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->rootFolder
|
||||
->expects($this->once())
|
||||
->method('newFile')
|
||||
->with('themedinstancelogo')
|
||||
->willReturn($file);
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('fopen')
|
||||
->with('w')
|
||||
->willReturn(fopen($destination . '/themedinstancelogo', 'w'));
|
||||
|
||||
$expected = new DataResponse(
|
||||
[
|
||||
|
@ -174,16 +188,25 @@ class ThemingControllerTest extends TestCase {
|
|||
'type' => 'text/svg',
|
||||
'name' => 'logo.svg',
|
||||
]);
|
||||
$this->config
|
||||
->expects($this->at(0))
|
||||
->method('getSystemValue')
|
||||
->with('datadirectory', \OC::$SERVERROOT . '/data')
|
||||
->willReturn($destination);
|
||||
$this->l10n
|
||||
->expects($this->once())
|
||||
->method('t')
|
||||
->with('Saved')
|
||||
->willReturn('Saved');
|
||||
$file = $this->getMockBuilder('\\OCP\\Files\\File')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->rootFolder
|
||||
->expects($this->once())
|
||||
->method('newFile')
|
||||
->with('themedbackgroundlogo')
|
||||
->willReturn($file);
|
||||
$file
|
||||
->expects($this->once())
|
||||
->method('fopen')
|
||||
->with('w')
|
||||
->willReturn(fopen($destination . '/themedbackgroundlogo', 'w'));
|
||||
|
||||
|
||||
$expected = new DataResponse(
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue