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

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

diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb
index f382df5..57870cf 100644
--- a/lib/backup_restore/restorer.rb
+++ b/lib/backup_restore/restorer.rb
@@ -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,9 +403,11 @@ module BackupRestore
       log "Reloading site settings..."
       SiteSetting.refresh!
 
-      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)
+      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
diff --git a/script/discourse b/script/discourse
index 205b9be..3b830db 100755
--- a/script/discourse
+++ b/script/discourse
@@ -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

GitHub sha: 78f81149

1 Like