FEATURE: Allow discourse script to skip disabling of emails after restore

This commit is contained in:
Gerhard Schlager 2019-03-07 21:48:26 +01:00
parent ccff1d2dbb
commit 78f8114989
2 changed files with 12 additions and 4 deletions

View File

@ -29,6 +29,7 @@ module BackupRestore
@client_id = opts[:client_id] @client_id = opts[:client_id]
@filename = opts[:filename] @filename = opts[:filename]
@publish_to_message_bus = opts[:publish_to_message_bus] || false @publish_to_message_bus = opts[:publish_to_message_bus] || false
@disable_emails = opts.fetch(:disable_emails, true)
ensure_restore_is_enabled ensure_restore_is_enabled
ensure_no_operation_is_running ensure_no_operation_is_running
@ -402,9 +403,11 @@ module BackupRestore
log "Reloading site settings..." log "Reloading site settings..."
SiteSetting.refresh! SiteSetting.refresh!
log "Disabling outgoing emails for non-staff users..." if @disable_emails
user = User.find_by_email(@user_info[:email]) || Discourse.system_user log "Disabling outgoing emails for non-staff users..."
SiteSetting.set_and_log(:disable_emails, 'non-staff', user) user = User.find_by_email(@user_info[:email]) || Discourse.system_user
SiteSetting.set_and_log(:disable_emails, 'non-staff', user)
end
end end
def clear_emoji_cache def clear_emoji_cache

View File

@ -106,6 +106,7 @@ class DiscourseCLI < Thor
end end
desc "restore", "Restore a Discourse backup" desc "restore", "Restore a Discourse backup"
option :disable_emails, type: :boolean, default: true
def restore(filename = nil) def restore(filename = nil)
if File.exist?('/usr/local/bin/discourse') if File.exist?('/usr/local/bin/discourse')
@ -132,7 +133,11 @@ class DiscourseCLI < Thor
begin begin
puts "Starting restore: #{filename}" puts "Starting restore: #{filename}"
restorer = BackupRestore::Restorer.new(Discourse.system_user.id, filename: filename) restorer = BackupRestore::Restorer.new(
Discourse.system_user.id,
filename: filename,
disable_emails: options[:disable_emails]
)
restorer.run restorer.run
puts 'Restore done.' puts 'Restore done.'
rescue BackupRestore::FilenameMissingError rescue BackupRestore::FilenameMissingError