Skip to content

Commit dc9cd22

Browse files
authored
Merge pull request #34473 from nextcloud/fix/excessive-increase-cachebuster
Fix excessive increase of cachebuster value
2 parents 8d05e18 + 46ee620 commit dc9cd22

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

apps/theming/lib/Controller/UserThemeController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OCA\Theming\ITheme;
3535
use OCA\Theming\Service\BackgroundService;
3636
use OCA\Theming\Service\ThemesService;
37+
use OCA\Theming\ThemingDefaults;
3738
use OCP\AppFramework\Http;
3839
use OCP\AppFramework\Http\DataResponse;
3940
use OCP\AppFramework\Http\FileDisplayResponse;
@@ -53,6 +54,7 @@ class UserThemeController extends OCSController {
5354
private IConfig $config;
5455
private IUserSession $userSession;
5556
private ThemesService $themesService;
57+
private ThemingDefaults $themingDefaults;
5658
private BackgroundService $backgroundService;
5759

5860
/**
@@ -63,11 +65,13 @@ public function __construct(string $appName,
6365
IConfig $config,
6466
IUserSession $userSession,
6567
ThemesService $themesService,
68+
ThemingDefaults $themingDefaults,
6669
BackgroundService $backgroundService) {
6770
parent::__construct($appName, $request);
6871
$this->config = $config;
6972
$this->userSession = $userSession;
7073
$this->themesService = $themesService;
74+
$this->themingDefaults = $themingDefaults;
7175
$this->backgroundService = $backgroundService;
7276
$this->userId = $userSession->getUser()->getUID();
7377
}
@@ -177,6 +181,8 @@ public function setBackground(string $type = 'default', string $value = ''): JSO
177181
}
178182
$currentVersion++;
179183
$this->config->setUserValue($this->userId, Application::APP_ID, 'backgroundVersion', (string)$currentVersion);
184+
// FIXME replace with user-specific cachebuster increase https://github.com/nextcloud/server/issues/34472
185+
$this->themingDefaults->increaseCacheBuster();
180186
return new JSONResponse([
181187
'type' => $type,
182188
'value' => $value,

apps/theming/lib/ThemingDefaults.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ public function getColorPrimary() {
224224
if ($color === '' && !empty($user)) {
225225
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
226226
if ($themingBackground === 'default') {
227-
$this->increaseCacheBuster();
228227
return BackgroundService::DEFAULT_COLOR;
229228
} else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) {
230-
$this->increaseCacheBuster();
231229
return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
232230
}
233231
}
@@ -411,7 +409,7 @@ protected function getCustomFavicon(): ?ISimpleFile {
411409
/**
412410
* Increases the cache buster key
413411
*/
414-
private function increaseCacheBuster(): void {
412+
public function increaseCacheBuster(): void {
415413
$cacheBusterKey = (int)$this->config->getAppValue('theming', 'cachebuster', '0');
416414
$this->config->setAppValue('theming', 'cachebuster', (string)($cacheBusterKey + 1));
417415
$this->cacheFactory->createDistributed('theming-')->clear();

apps/theming/tests/Controller/UserThemeControllerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OCA\Theming\Themes\HighContrastTheme;
3434
use OCA\Theming\Service\ThemesService;
3535
use OCA\Theming\Themes\LightTheme;
36+
use OCA\Theming\ThemingDefaults;
3637
use OCP\AppFramework\Http\DataResponse;
3738
use OCP\AppFramework\OCS\OCSBadRequestException;
3839
use OCP\IConfig;
@@ -54,6 +55,8 @@ class UserThemeControllerTest extends TestCase {
5455
private $userSession;
5556
/** @var ThemeService|MockObject */
5657
private $themesService;
58+
/** @var ThemingDefaults */
59+
private $themingDefaults;
5760
/** @var BackgroundService|MockObject */
5861
private $backgroundService;
5962

@@ -66,6 +69,7 @@ protected function setUp(): void {
6669
$this->config = $this->createMock(IConfig::class);
6770
$this->userSession = $this->createMock(IUserSession::class);
6871
$this->themesService = $this->createMock(ThemesService::class);
72+
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
6973
$this->backgroundService = $this->createMock(BackgroundService::class);
7074

7175
$this->themes = [
@@ -91,6 +95,7 @@ protected function setUp(): void {
9195
$this->config,
9296
$this->userSession,
9397
$this->themesService,
98+
$this->themingDefaults,
9499
$this->backgroundService,
95100
);
96101

0 commit comments

Comments
 (0)