From 7d57b2c31786c883c58347ce936485b7ece45332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 30 Nov 2020 13:06:10 +0100 Subject: [PATCH] Store scss variables under a different prefix for each theming config version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main issue with using the general theming- prefix is that with APCu caching the cache is not shared between processes, so when trying to reset the cache through the CLI, e.g. when updating the theming config the old cache is never invalidated. Signed-off-by: Julius Härtl --- apps/theming/lib/ThemingDefaults.php | 5 +++-- apps/theming/tests/ThemingDefaultsTest.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index e710bee3f6..cf22cf7814 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -290,13 +290,14 @@ class ThemingDefaults extends \OC_Defaults { * @return array scss variables to overwrite */ public function getScssVariables() { - $cache = $this->cacheFactory->createDistributed('theming-' . $this->urlGenerator->getBaseUrl()); + $cacheBuster = $this->config->getAppValue('theming', 'cachebuster', '0'); + $cache = $this->cacheFactory->createDistributed('theming-' . $cacheBuster . '-' . $this->urlGenerator->getBaseUrl()); if ($value = $cache->get('getScssVariables')) { return $value; } $variables = [ - 'theming-cachebuster' => "'" . $this->config->getAppValue('theming', 'cachebuster', '0') . "'", + 'theming-cachebuster' => "'" . $cacheBuster . "'", 'theming-logo-mime' => "'" . $this->config->getAppValue('theming', 'logoMime') . "'", 'theming-background-mime' => "'" . $this->config->getAppValue('theming', 'backgroundMime') . "'", 'theming-logoheader-mime' => "'" . $this->config->getAppValue('theming', 'logoheaderMime') . "'", diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php index 3220870f8e..514e7e0150 100644 --- a/apps/theming/tests/ThemingDefaultsTest.php +++ b/apps/theming/tests/ThemingDefaultsTest.php @@ -634,9 +634,10 @@ class ThemingDefaultsTest extends TestCase { } public function testGetScssVariablesCached() { + $this->config->expects($this->any())->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('1'); $this->cacheFactory->expects($this->once()) ->method('createDistributed') - ->with('theming-') + ->with('theming-1-') ->willReturn($this->cache); $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(['foo'=>'bar']); $this->assertEquals(['foo'=>'bar'], $this->template->getScssVariables()); @@ -658,7 +659,7 @@ class ThemingDefaultsTest extends TestCase { $this->util->expects($this->any())->method('elementColor')->with($this->defaults->getColorPrimary())->willReturn('#aaaaaa'); $this->cacheFactory->expects($this->once()) ->method('createDistributed') - ->with('theming-') + ->with('theming-0-') ->willReturn($this->cache); $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null); $this->imageManager->expects($this->at(0))->method('getImageUrl')->with('logo')->willReturn('custom-logo?v=0');