Shortcut to avoid file system setup when generating the logo URL

If an SVG is requested and the app config value for logoMime is set then the logo is there. Otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which needs to be called then).

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2020-11-04 09:59:32 +01:00
parent 0247f22c83
commit c7ff0c71b4
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
2 changed files with 14 additions and 11 deletions

View File

@ -225,11 +225,20 @@ class ThemingDefaults extends \OC_Defaults {
public function getLogo($useSvg = true): string { public function getLogo($useSvg = true): string {
$logo = $this->config->getAppValue('theming', 'logoMime', false); $logo = $this->config->getAppValue('theming', 'logoMime', false);
$logoExists = true; // short cut to avoid setting up the filesystem just to check if the logo is there
try { //
$this->imageManager->getImage('logo', $useSvg); // explanation: if an SVG is requested and the app config value for logoMime is set then the logo is there.
} catch (\Exception $e) { // otherwise we need to check it and maybe also generate a PNG from the SVG (that's done in getImage() which
$logoExists = false; // needs to be called then)
if ($useSvg === true && $logo !== false) {
$logoExists = true;
} else {
try {
$this->imageManager->getImage('logo', $useSvg);
$logoExists = true;
} catch (\Exception $e) {
$logoExists = false;
}
} }
$cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0'); $cacheBusterCounter = $this->config->getAppValue('theming', 'cachebuster', '0');

View File

@ -40,7 +40,6 @@ use OCA\Theming\Util;
use OCP\App\IAppManager; use OCP\App\IAppManager;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\ICache; use OCP\ICache;
use OCP\ICacheFactory; use OCP\ICacheFactory;
use OCP\IConfig; use OCP\IConfig;
@ -617,11 +616,6 @@ class ThemingDefaultsTest extends TestCase {
} }
public function testGetLogoCustom() { public function testGetLogoCustom() {
$file = $this->createMock(ISimpleFile::class);
$this->imageManager->expects($this->once())
->method('getImage')
->with('logo')
->willReturn($file);
$this->config $this->config
->expects($this->at(0)) ->expects($this->at(0))
->method('getAppValue') ->method('getAppValue')