Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/theming/lib/Controller/UserThemeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand All @@ -53,6 +54,7 @@ class UserThemeController extends OCSController {
private IConfig $config;
private IUserSession $userSession;
private ThemesService $themesService;
private ThemingDefaults $themingDefaults;
private BackgroundService $backgroundService;

/**
Expand All @@ -63,11 +65,13 @@ public function __construct(string $appName,
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();
}
Expand Down Expand Up @@ -177,6 +181,8 @@ public function setBackground(string $type = 'default', string $value = ''): JSO
}
$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,
Expand Down
4 changes: 1 addition & 3 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,8 @@ public function getColorPrimary() {
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'];
}
}
Expand Down Expand Up @@ -411,7 +409,7 @@ protected function getCustomFavicon(): ?ISimpleFile {
/**
* 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();
Expand Down
5 changes: 5 additions & 0 deletions apps/theming/tests/Controller/UserThemeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand All @@ -54,6 +55,8 @@ class UserThemeControllerTest extends TestCase {
private $userSession;
/** @var ThemeService|MockObject */
private $themesService;
/** @var ThemingDefaults */
private $themingDefaults;
/** @var BackgroundService|MockObject */
private $backgroundService;

Expand All @@ -66,6 +69,7 @@ protected function setUp(): void {
$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 = [
Expand All @@ -91,6 +95,7 @@ protected function setUp(): void {
$this->config,
$this->userSession,
$this->themesService,
$this->themingDefaults,
$this->backgroundService,
);

Expand Down