A platform for community discussion. Free, open, simple.
FIX: improve the migration script from advanced search to welcome banner updates (#35699)
Yuriy Kurant84ecf377b8d4
diff --git a/lib/tasks/migrate_advanced_search_banner_to_welcome_banner.rake b/lib/tasks/migrate_advanced_search_banner_to_welcome_banner.rakeindex f7b33d734a3..b4224076da9 100644--- a/lib/tasks/migrate_advanced_search_banner_to_welcome_banner.rake+++ b/lib/tasks/migrate_advanced_search_banner_to_welcome_banner.rake@@ -278,30 +278,15 @@ end# Exclude and disable methodsdef process_theme_component(theme)- exclude_theme_component(theme)enable_welcome_banner(theme)+ exclude_theme_component(theme)disable_theme_component(theme)puts "\n\e[1;34mTask completed successfully!\e[0m"end-def exclude_theme_component(theme)- puts "\n Executing exclude step..."- return if not_included_in_any_theme?(theme)-- parent_relations = theme.parent_theme_relation.to_a- total_relations = parent_relations.size-- puts "\n Excluding #{theme_identifier(theme)} from..."- parent_relations.each do |relation|- puts " - #{relation.parent_theme.name} (ID: #{relation.parent_theme_id})"- relation.destroy!- end- puts " \e[1;32m✓ Excluded from #{total_relations} theme#{"s" if total_relations > 1}\e[0m"-end-def enable_welcome_banner(theme)- puts "\n Executing enable core welcome banner step..."+ puts "\n Executing enable core welcome banner step... (1/3)"if !theme.enabledputs " \e[33m#{theme_identifier(theme)} is disabled, thus no need to enable core welcome banner. Skipping\e[0m"return@@ -310,7 +295,7 @@ def enable_welcome_banner(theme)return if not_included_in_any_theme?(theme)- puts "\n Enabling \e[1mcore welcome banner\e[0m for..."+ puts " Enabling \e[1mcore welcome banner\e[0m for..."enabled_count = 0theme.parent_theme_relation.each do |relation|@@ -319,7 +304,14 @@ def enable_welcome_banner(theme)ThemeSiteSetting.find_by(theme_id: parent_theme.id, name: "enable_welcome_banner")if site_setting.value == "f"- site_setting.update!(value: "t")+ Themes::ThemeSiteSettingManager.call(+ params: {+ theme_id: parent_theme.id,+ name: "enable_welcome_banner",+ value: true,+ },+ guardian: Discourse.system_user.guardian,+ )puts " - #{parent_theme.name} (ID: #{parent_theme.id}) \e[32m- enabled\e[0m"enabled_count += 1else@@ -330,14 +322,30 @@ def enable_welcome_banner(theme)puts " \e[1;32m✓ Enabled for #{enabled_count} theme#{"s" unless enabled_count == 1}\e[0m"end+def exclude_theme_component(theme)+ puts "\n Executing exclude step... (2/3)"+ return if not_included_in_any_theme?(theme)++ parent_relations = theme.parent_theme_relation.to_a+ total_relations = parent_relations.size+ parent_names = parent_relations.map { |r| "#{r.parent_theme.name} (ID: #{r.parent_theme_id})" }++ puts " Excluding #{theme_identifier(theme)} from:"+ puts " - #{parent_names.join("\n - ")}"++ theme.parent_theme_ids = []+ theme.save!+ puts " \e[1;32m✓ Excluded from #{total_relations} theme#{"s" if total_relations > 1}\e[0m"+end+def disable_theme_component(theme)- puts "\n Executing disable component step..."+ puts "\n Executing disable component step... (3/3)"if !theme.enabledputs " \e[33m#{theme_identifier(theme)} was already disabled. Skipping\e[0m"returnend- puts "\n Disabling #{theme_identifier(theme)}..."+ puts " Disabling #{theme_identifier(theme)}..."theme.update!(enabled: false)puts " \e[1;32m✓ Disabled\e[0m"end