diff options
author | Christopher Ng <chrng8@gmail.com> | 2022-10-08 00:52:09 +0000 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2022-10-11 16:25:42 +0000 |
commit | 46ee6201503d33a10328e200e51d591dacd11f46 (patch) | |
tree | 11c18751e62d92bb0c51cefe2b994a24638729e6 /apps | |
parent | 8d05e180bc29dbe0d546fd46d16339ced60c4228 (diff) | |
download | nextcloud-server-46ee6201503d33a10328e200e51d591dacd11f46.tar.gz nextcloud-server-46ee6201503d33a10328e200e51d591dacd11f46.zip |
Fix excessive increase of cachebuster value
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/theming/lib/Controller/UserThemeController.php | 6 | ||||
-rw-r--r-- | apps/theming/lib/ThemingDefaults.php | 4 | ||||
-rw-r--r-- | apps/theming/tests/Controller/UserThemeControllerTest.php | 5 |
3 files changed, 12 insertions, 3 deletions
diff --git a/apps/theming/lib/Controller/UserThemeController.php b/apps/theming/lib/Controller/UserThemeController.php index 327029b26cd..091331706a7 100644 --- a/apps/theming/lib/Controller/UserThemeController.php +++ b/apps/theming/lib/Controller/UserThemeController.php @@ -34,6 +34,7 @@ use OCA\Theming\AppInfo\Application; use OCA\Theming\ITheme; use OCA\Theming\Service\BackgroundService; use OCA\Theming\Service\ThemesService; +use OCA\Theming\ThemingDefaults; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; @@ -53,6 +54,7 @@ class UserThemeController extends OCSController { private IConfig $config; private IUserSession $userSession; private ThemesService $themesService; + private ThemingDefaults $themingDefaults; private BackgroundService $backgroundService; /** @@ -63,11 +65,13 @@ class UserThemeController extends OCSController { IConfig $config, IUserSession $userSession, ThemesService $themesService, + ThemingDefaults $themingDefaults, BackgroundService $backgroundService) { parent::__construct($appName, $request); $this->config = $config; $this->userSession = $userSession; $this->themesService = $themesService; + $this->themingDefaults = $themingDefaults; $this->backgroundService = $backgroundService; $this->userId = $userSession->getUser()->getUID(); } @@ -177,6 +181,8 @@ class UserThemeController extends OCSController { } $currentVersion++; $this->config->setUserValue($this->userId, Application::APP_ID, 'backgroundVersion', (string)$currentVersion); + // FIXME replace with user-specific cachebuster increase https://github.com/nextcloud/server/issues/34472 + $this->themingDefaults->increaseCacheBuster(); return new JSONResponse([ 'type' => $type, 'value' => $value, diff --git a/apps/theming/lib/ThemingDefaults.php b/apps/theming/lib/ThemingDefaults.php index 5fa5656d928..ae12530fb5c 100644 --- a/apps/theming/lib/ThemingDefaults.php +++ b/apps/theming/lib/ThemingDefaults.php @@ -224,10 +224,8 @@ class ThemingDefaults extends \OC_Defaults { if ($color === '' && !empty($user)) { $themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default'); if ($themingBackground === 'default') { - $this->increaseCacheBuster(); return BackgroundService::DEFAULT_COLOR; } else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) { - $this->increaseCacheBuster(); return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color']; } } @@ -411,7 +409,7 @@ class ThemingDefaults extends \OC_Defaults { /** * Increases the cache buster key */ - private function increaseCacheBuster(): void { + public function increaseCacheBuster(): void { $cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0'); $this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1)); $this->cacheFactory->createDistributed('theming-')->clear(); diff --git a/apps/theming/tests/Controller/UserThemeControllerTest.php b/apps/theming/tests/Controller/UserThemeControllerTest.php index a6f73a087fc..851dbec38eb 100644 --- a/apps/theming/tests/Controller/UserThemeControllerTest.php +++ b/apps/theming/tests/Controller/UserThemeControllerTest.php @@ -33,6 +33,7 @@ use OCA\Theming\Themes\DyslexiaFont; use OCA\Theming\Themes\HighContrastTheme; use OCA\Theming\Service\ThemesService; use OCA\Theming\Themes\LightTheme; +use OCA\Theming\ThemingDefaults; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\IConfig; @@ -54,6 +55,8 @@ class UserThemeControllerTest extends TestCase { private $userSession; /** @var ThemeService|MockObject */ private $themesService; + /** @var ThemingDefaults */ + private $themingDefaults; /** @var BackgroundService|MockObject */ private $backgroundService; @@ -66,6 +69,7 @@ class UserThemeControllerTest extends TestCase { $this->config = $this->createMock(IConfig::class); $this->userSession = $this->createMock(IUserSession::class); $this->themesService = $this->createMock(ThemesService::class); + $this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->backgroundService = $this->createMock(BackgroundService::class); $this->themes = [ @@ -91,6 +95,7 @@ class UserThemeControllerTest extends TestCase { $this->config, $this->userSession, $this->themesService, + $this->themingDefaults, $this->backgroundService, ); |