Skip to content

Commit

Permalink
Use IRootFolder for checking image existence
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr committed Aug 10, 2016
1 parent 4975d6c commit 232cd38
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
14 changes: 9 additions & 5 deletions apps/theming/lib/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Files\IRootFolder;

/**
* Class Template
Expand All @@ -52,6 +53,8 @@ class Template extends \OC_Defaults {
private $slogan;
/** @var string */
private $color;
/** @var IRootFolder */
private $rootFolder;

/**
* Template constructor.
Expand All @@ -60,16 +63,19 @@ class Template extends \OC_Defaults {
* @param IL10N $l
* @param IURLGenerator $urlGenerator
* @param \OC_Defaults $defaults
* @param IRootFolder $rootFolder
*/
public function __construct(IConfig $config,
IL10N $l,
IURLGenerator $urlGenerator,
\OC_Defaults $defaults
\OC_Defaults $defaults,
IRootFolder $rootFolder
) {
parent::__construct();
$this->config = $config;
$this->l = $l;
$this->urlGenerator = $urlGenerator;
$this->rootFolder = $rootFolder;

$this->name = $defaults->getName();
$this->url = $defaults->getBaseUrl();
Expand Down Expand Up @@ -126,8 +132,7 @@ public function getMailHeaderColor() {
*/
public function getLogo() {
$logo = $this->config->getAppValue('theming', 'logoMime');
$pathToLogo = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedinstancelogo';
if(!$logo || !file_exists($pathToLogo)) {
if(!$logo || !$this->rootFolder->nodeExists('themedinstancelogo')) {
return $this->urlGenerator->imagePath('core','logo.svg');
} else {
return $this->urlGenerator->linkToRoute('theming.Theming.getLogo');
Expand All @@ -140,8 +145,7 @@ public function getLogo() {
*/
public function getBackground() {
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime');
$pathToLogo = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/') . '/themedbackgroundlogo';
if(!$backgroundLogo || !file_exists($pathToLogo)) {
if(!$backgroundLogo || !$this->rootFolder->nodeExists('themedbackgroundlogo')) {
return $this->urlGenerator->imagePath('core','background.jpg');
} else {
return $this->urlGenerator->linkToRoute('theming.Theming.getLoginBackground');
Expand Down
7 changes: 6 additions & 1 deletion apps/theming/tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Files\IRootFolder;
use Test\TestCase;

class TemplateTest extends TestCase {
Expand All @@ -40,11 +41,14 @@ class TemplateTest extends TestCase {
private $defaults;
/** @var Template */
private $template;
/** @var IRootFolder */
private $rootFolder;

public function setUp() {
$this->config = $this->getMock('\\OCP\\IConfig');
$this->l10n = $this->getMock('\\OCP\\IL10N');
$this->urlGenerator = $this->getMock('\\OCP\\IURLGenerator');
$this->rootFolder = $this->getMock('\\OCP\\Files\\IRootFolder');
$this->defaults = $this->getMockBuilder('\\OC_Defaults')
->disableOriginalConstructor()
->getMock();
Expand All @@ -68,7 +72,8 @@ public function setUp() {
$this->config,
$this->l10n,
$this->urlGenerator,
$this->defaults
$this->defaults,
$this->rootFolder
);

return parent::setUp();
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ public function __construct($webRoot, \OC\Config $config) {
$this->getConfig(),
$this->getL10N('theming'),
$this->getURLGenerator(),
new \OC_Defaults()
new \OC_Defaults(),
$this->getRootFolder()
);
}
return new \OC_Defaults();
Expand Down

0 comments on commit 232cd38

Please sign in to comment.