From 0edd963f21bcbfe3f5628d76ff94a281501a9a96 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms Date: Wed, 11 Feb 2026 13:58:37 +0100 Subject: delete theme asset upon theme deletion, allow activation regardless of other themes state and some small touchups, fixes #6244 --- lib/classes/JsonApi/Routes/Themes/ThemesUpdate.php | 14 +++++++++----- lib/classes/PageLayout.php | 2 +- lib/models/Theme.php | 18 +++++++++++++++--- public/assets.php | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/classes/JsonApi/Routes/Themes/ThemesUpdate.php b/lib/classes/JsonApi/Routes/Themes/ThemesUpdate.php index 751b0d0..c1fcc6b 100644 --- a/lib/classes/JsonApi/Routes/Themes/ThemesUpdate.php +++ b/lib/classes/JsonApi/Routes/Themes/ThemesUpdate.php @@ -35,13 +35,17 @@ class ThemesUpdate extends JsonApiController if (self::arrayGet($json, 'data.attributes.active') === true) { $activeThemes = \Theme::getActiveThemes(); foreach ($activeThemes as $theme) { - if ($theme->id !== $resource->id && $theme->type === $resource->type) { + if ( + $theme->id !== $resource->id + && $theme->type === $resource->type + ) { $theme->active = false; $theme->store(); - $resource->active = true; - $resource->store(); } } + + $resource->active = true; + $resource->store(); } return $this->getContentResponse($resource); @@ -77,10 +81,10 @@ class ThemesUpdate extends JsonApiController $resource->$sormKey = $val; } } - + $resource->store(); return $resource; } -} \ No newline at end of file +} diff --git a/lib/classes/PageLayout.php b/lib/classes/PageLayout.php index c529fa6..17ddf76 100644 --- a/lib/classes/PageLayout.php +++ b/lib/classes/PageLayout.php @@ -147,7 +147,7 @@ class PageLayout $old_base = URLHelper::setBaseURL($GLOBALS['ABSOLUTE_URI_STUDIP']); self::addHeadElement('link', [ 'rel' => 'stylesheet', - 'href' => Theme::getDownloadURL(), + 'href' => URLHelper::getLink(Theme::getDownloadURL(), [], true), ]); URLHelper::setBaseURL($old_base); } catch (Exception) { diff --git a/lib/models/Theme.php b/lib/models/Theme.php index 824d8cd..852dc42 100644 --- a/lib/models/Theme.php +++ b/lib/models/Theme.php @@ -67,8 +67,13 @@ && $theme->isFieldDirty('values') ) ) { - self::loadActiveThemes(true); - self::getThemeAsset()->writeContent(self::getActiveCSS()); + self::regenerateCSS(); + } + }; + + $config['registered_callbacks']['after_delete'][] = function (Theme $theme): void { + if ($theme->active) { + self::regenerateCSS(); } }; @@ -105,12 +110,19 @@ public static function getDownloadURL(): string { $asset = self::getThemeAsset(); - return URLHelper::getLink( + return URLHelper::getURL( "assets.php/css/{$asset->id}#{$asset->filename}", ['v' => $asset->chdate], true ); + } + + private static function regenerateCSS(): void + { + self::getThemeAsset()->delete(); + self::loadActiveThemes(true); + self::getThemeAsset()->writeContent(self::getActiveCSS()); } public static function getActiveCSS(): string diff --git a/public/assets.php b/public/assets.php index 886886b..d10b6ad 100644 --- a/public/assets.php +++ b/public/assets.php @@ -45,7 +45,7 @@ $app->get('/{type:js|css}/{id}', function (ServerRequestInterface $request, Resp $response->getBody()->write($asset->getContent()); $response = $response->withHeader('Content-Type', $args['type'] === 'css' ? 'text/css' : 'application/javascript'); - $response = $response->withHeader('Content-Length', $model->size); + $response = $response->withHeader('Content-Length', $model->size ?? 0); // Store cache information if (Studip\ENV !== 'development') { -- cgit v1.0