discourse/lib/system_themes_manager.rb
Martin Brennan 57fea290ef
DEV: Use themeable site settings for Horizon (#33645)
This commit removes the value transformers introduced
to Horizon back in
274e5f7a1f
and
897d34132e
in favor of the new themeable site settings introduced in
19af83d39e , as this is what they
are for.

No migration for existing sites...they will already have
ThemeSiteSetting values from a previous migration to ensure
site setting values were preserved in theme site settings.

We do delete the ThemeField storing the Horizon custom theme
setting definition though, otherwise the UI still shows the old
settings.
2025-07-24 12:20:34 +10:00

45 lines
1.4 KiB
Ruby

# frozen_string_literal: true
class SystemThemesManager
def self.sync!
Theme::CORE_THEMES.keys.each { |theme_name| sync_theme!(theme_name) }
end
def self.sync_theme!(theme_name)
theme_id = Theme::CORE_THEMES[theme_name]
raise Discourse::InvalidParameters unless theme_id
theme_dir = "#{Rails.root}/themes/#{theme_name}"
remote_theme = RemoteTheme.import_theme_from_directory(theme_dir, theme_id: theme_id)
if remote_theme.color_scheme
remote_theme.color_scheme.update!(user_selectable: true)
alternative_theme_name =
if remote_theme.color_scheme.name =~ / Dark$/
remote_theme.color_scheme.name.sub(" Dark", "")
else
"#{remote_theme.color_scheme.name} Dark"
end
remote_theme
.color_schemes
.where(name: alternative_theme_name)
.first
&.update!(user_selectable: true)
end
remote_theme.update_column(:enabled, true)
Stylesheet::Manager.clear_theme_cache!
end
# Don't want user history created from theme site setting changes
# from system themes polluting specs.
def self.clear_system_theme_user_history!
return if !Rails.env.test?
Theme::CORE_THEMES.each_key do |theme_name|
UserHistory
.where(action: UserHistory.actions[:change_theme_site_setting])
.where("subject ILIKE :theme_name", theme_name: "#{theme_name}:%")
.destroy_all
end
end
end