A platform for community discussion. Free, open, simple.
FIX: allow out-of-sequence theme settings migrations on re-sync (#38705)
Martin Brennan7504805f89fb
diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rbindex de5c83c3dbd..5ed758e4eec 100644--- a/app/models/remote_theme.rb+++ b/app/models/remote_theme.rb@@ -84,11 +84,16 @@ class RemoteTheme < ActiveRecord::Base)end- def self.import_theme_from_directory(directory, theme_id: nil)+ def self.import_theme_from_directory(+ directory,+ theme_id: nil,+ allow_out_of_sequence_migration: false+ )update_theme(ThemeStore::DirectoryImporter.new(directory),update_components: "none",theme_id: theme_id,+ allow_out_of_sequence_migration: allow_out_of_sequence_migration,)end@@ -97,7 +102,8 @@ class RemoteTheme < ActiveRecord::Baseuser: Discourse.system_user,theme_id: nil,update_components: nil,- run_migrations: true+ run_migrations: true,+ allow_out_of_sequence_migration: false)importer.import!@@ -132,6 +138,7 @@ class RemoteTheme < ActiveRecord::Baseskip_update: true,already_in_transaction: true,run_migrations:,+ allow_out_of_sequence_migration:,)if existing && update_components.present? && update_components != "none"@@ -236,7 +243,8 @@ class RemoteTheme < ActiveRecord::Baseskip_update: false,raise_if_theme_save_fails: true,already_in_transaction: false,- run_migrations: true+ run_migrations: true,+ allow_out_of_sequence_migration: false)cleanup = false@@ -390,7 +398,12 @@ class RemoteTheme < ActiveRecord::Basecreate_theme_site_settings(theme, theme_info["theme_site_settings"])- theme.migrate_settings(start_transaction: false) if run_migrations+ if run_migrations+ theme.migrate_settings(+ start_transaction: false,+ allow_out_of_sequence_migration: allow_out_of_sequence_migration,+ )+ endendif already_in_transactiondiff --git a/lib/system_themes_manager.rb b/lib/system_themes_manager.rbindex 6f4d87a44a3..bb5f28c7bc2 100644--- a/lib/system_themes_manager.rb+++ b/lib/system_themes_manager.rb@@ -13,7 +13,12 @@ class SystemThemesManageris_initial_install = !Theme.exists?(id: theme_id)- theme = RemoteTheme.import_theme_from_directory(theme_dir, theme_id: theme_id)+ theme =+ RemoteTheme.import_theme_from_directory(+ theme_dir,+ theme_id: theme_id,+ allow_out_of_sequence_migration: !is_initial_install,+ )theme.update_column(:enabled, true)if is_initial_installdiff --git a/spec/lib/system_themes_manager_spec.rb b/spec/lib/system_themes_manager_spec.rbindex 3db6a8db92a..3440d69ef94 100644--- a/spec/lib/system_themes_manager_spec.rb+++ b/spec/lib/system_themes_manager_spec.rb@@ -40,4 +40,18 @@ RSpec.describe SystemThemesManager doexpect(Theme.horizon_theme.color_scheme).to eq(nil)expect(Theme.horizon_theme.dark_color_scheme).to eq(nil)end++ it "does not raise when re-syncing themes with existing settings migrations" do+ Theme.delete_all+ SystemThemesManager.sync!++ themes_with_migrations =+ Theme::CORE_THEMES.select { |_, id| ThemeSettingsMigration.exists?(theme_id: id) }++ skip "no core themes have settings migrations" if themes_with_migrations.empty?++ themes_with_migrations.each_key do |theme_name|+ expect { SystemThemesManager.sync_theme!(theme_name) }.not_to raise_error+ end+ endend