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]
@filename = opts[:filename]
@publish_to_message_bus = opts[:publish_to_message_bus] || false
@disable_emails = opts.fetch(:disable_emails, true)
ensure_restore_is_enabled
ensure_no_operation_is_running
@ -402,10 +403,12 @@ module BackupRestore
log "Reloading site settings..."
SiteSetting.refresh!
if @disable_emails
log "Disabling outgoing emails for non-staff users..."
user = User.find_by_email(@user_info[:email]) || Discourse.system_user
SiteSetting.set_and_log(:disable_emails, 'non-staff', user)
end
end
def clear_emoji_cache
log "Clearing emoji cache..."

View File

@ -106,6 +106,7 @@ class DiscourseCLI < Thor
end
desc "restore", "Restore a Discourse backup"
option :disable_emails, type: :boolean, default: true
def restore(filename = nil)
if File.exist?('/usr/local/bin/discourse')
@ -132,7 +133,11 @@ class DiscourseCLI < Thor
begin
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
puts 'Restore done.'
rescue BackupRestore::FilenameMissingError