FIX: Reset changed site settings after import is complete

After an import has finished the site settings should be reset to their
previous values. For example, since 'disable_emails' was set to false
before any import, it wasn't possible to login after the import
(sending email for password reset didn't work).
This commit is contained in:
Gerhard Schlager 2014-08-31 18:09:21 +02:00
parent 9aac004c0a
commit 5a769c7c48

View file

@ -27,6 +27,7 @@ class ImportScripts::Base
@categories_lookup = {} @categories_lookup = {}
@existing_posts = {} @existing_posts = {}
@topic_lookup = {} @topic_lookup = {}
@old_site_settings = {}
puts "loading existing groups..." puts "loading existing groups..."
GroupCustomField.where(name: 'import_id').pluck(:group_id, :value).each do |group_id, import_id| GroupCustomField.where(name: 'import_id').pluck(:group_id, :value).each do |group_id, import_id|
@ -66,17 +67,7 @@ class ImportScripts::Base
def perform def perform
Rails.logger.level = 3 # :error, so that we don't create log files that are many GB Rails.logger.level = 3 # :error, so that we don't create log files that are many GB
SiteSetting.email_domains_blacklist = '' change_site_settings
SiteSetting.min_topic_title_length = 1
SiteSetting.min_post_length = 1
SiteSetting.min_private_message_post_length = 1
SiteSetting.min_private_message_title_length = 1
SiteSetting.allow_duplicate_topic_titles = true
SiteSetting.default_digest_email_frequency = ''
SiteSetting.disable_emails = true
RateLimiter.disable
execute execute
puts "" puts ""
@ -89,6 +80,34 @@ class ImportScripts::Base
puts "", "Done" puts "", "Done"
ensure ensure
reset_site_settings
end
def change_site_settings
new_settings = {
email_domains_blacklist: '',
min_topic_title_length: 1,
min_post_length: 1,
min_private_message_post_length: 1,
min_private_message_title_length: 1,
allow_duplicate_topic_titles: true,
default_digest_email_frequency: '',
disable_emails: true
}
new_settings.each do |key, value|
@old_site_settings[key] = SiteSetting.send(key)
SiteSetting.set(key, value)
end
RateLimiter.disable
end
def reset_site_settings
@old_site_settings.each do |key, value|
SiteSetting.set(key, value)
end
RateLimiter.enable RateLimiter.enable
end end