mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add skip_migrations param when importing remote theme (#25218)
Why this change? Importing theme with the `bundle` params is used mainly by `discourse_theme` CLI in the development environment. However, we do not want migrations to automatically run in the development environment and instead want the developer to be intentional about running theme migrations. As such, this commit adds support for a `skip_migrations` param when importing a theme with the `bundle` params. This commit also adds a `migrated` attribute for migrations theme fields to indicate whether a migrations theme field has been migrated or not.
This commit is contained in:
committed by
GitHub
parent
30bea5c7c2
commit
59839e428f
@@ -70,13 +70,15 @@ class RemoteTheme < ActiveRecord::Base
|
||||
original_filename,
|
||||
user: Discourse.system_user,
|
||||
theme_id: nil,
|
||||
update_components: nil
|
||||
update_components: nil,
|
||||
run_migrations: true
|
||||
)
|
||||
update_theme(
|
||||
ThemeStore::ZipImporter.new(filename, original_filename),
|
||||
user:,
|
||||
theme_id:,
|
||||
update_components:,
|
||||
run_migrations:,
|
||||
)
|
||||
end
|
||||
|
||||
@@ -91,7 +93,8 @@ class RemoteTheme < ActiveRecord::Base
|
||||
importer,
|
||||
user: Discourse.system_user,
|
||||
theme_id: nil,
|
||||
update_components: nil
|
||||
update_components: nil,
|
||||
run_migrations: true
|
||||
)
|
||||
importer.import!
|
||||
|
||||
@@ -112,8 +115,14 @@ class RemoteTheme < ActiveRecord::Base
|
||||
remote_theme.remote_url = ""
|
||||
|
||||
do_update_child_components = false
|
||||
|
||||
theme.transaction do
|
||||
remote_theme.update_from_remote(importer, skip_update: true, already_in_transaction: true)
|
||||
remote_theme.update_from_remote(
|
||||
importer,
|
||||
skip_update: true,
|
||||
already_in_transaction: true,
|
||||
run_migrations:,
|
||||
)
|
||||
|
||||
if existing && update_components.present? && update_components != "none"
|
||||
child_components = child_components.map { |url| ThemeStore::GitImporter.new(url.strip).url }
|
||||
@@ -216,7 +225,8 @@ class RemoteTheme < ActiveRecord::Base
|
||||
importer = nil,
|
||||
skip_update: false,
|
||||
raise_if_theme_save_fails: true,
|
||||
already_in_transaction: false
|
||||
already_in_transaction: false,
|
||||
run_migrations: true
|
||||
)
|
||||
cleanup = false
|
||||
|
||||
@@ -356,12 +366,14 @@ class RemoteTheme < ActiveRecord::Base
|
||||
update_theme_color_schemes(theme, theme_info["color_schemes"]) unless theme.component
|
||||
|
||||
self.save!
|
||||
|
||||
if raise_if_theme_save_fails
|
||||
theme.save!
|
||||
else
|
||||
raise ActiveRecord::Rollback if !theme.save
|
||||
end
|
||||
theme.migrate_settings(start_transaction: false)
|
||||
|
||||
theme.migrate_settings(start_transaction: false) if run_migrations
|
||||
end
|
||||
|
||||
if already_in_transaction
|
||||
|
||||
@@ -86,7 +86,7 @@ class Theme < ActiveRecord::Base
|
||||
:user,
|
||||
:color_scheme,
|
||||
:theme_translation_overrides,
|
||||
theme_fields: :upload,
|
||||
theme_fields: %i[upload theme_settings_migration],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -130,6 +130,7 @@ class Theme < ActiveRecord::Base
|
||||
|
||||
remove_from_cache!
|
||||
ColorScheme.hex_cache.clear
|
||||
|
||||
notify_theme_change(with_scheme: notify_with_scheme)
|
||||
|
||||
if theme_setting_requests_refresh
|
||||
@@ -647,13 +648,14 @@ class Theme < ActiveRecord::Base
|
||||
def settings
|
||||
field = settings_field
|
||||
return [] unless field && field.error.nil?
|
||||
|
||||
settings = []
|
||||
|
||||
ThemeSettingsParser
|
||||
.new(field)
|
||||
.load do |name, default, type, opts|
|
||||
settings << ThemeSettingsManager.create(name, default, type, self, opts)
|
||||
end
|
||||
|
||||
settings
|
||||
end
|
||||
|
||||
@@ -847,6 +849,7 @@ class Theme < ActiveRecord::Base
|
||||
self.theme_settings.destroy_all
|
||||
|
||||
final_result = results.last
|
||||
|
||||
final_result[:settings_after].each do |key, val|
|
||||
self.update_setting(key.to_sym, val)
|
||||
rescue Discourse::NotFound
|
||||
@@ -874,7 +877,8 @@ class Theme < ActiveRecord::Base
|
||||
record.calculate_diff(res[:settings_before], res[:settings_after])
|
||||
record.save!
|
||||
end
|
||||
self.save!
|
||||
|
||||
self.reload
|
||||
end
|
||||
|
||||
if start_transaction
|
||||
|
||||
Reference in New Issue
Block a user