diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/classes/JsonApi/Routes/Themes/ThemesUpdate.php | 14 | ||||
| -rw-r--r-- | lib/classes/PageLayout.php | 2 | ||||
| -rw-r--r-- | lib/models/Theme.php | 18 |
3 files changed, 25 insertions, 9 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 |
