]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/rm/rm_runner.rb
Move the Runner selection into the plugin.
[mailshears.git] / lib / rm / rm_runner.rb
index 039ae61f7d489c9a0a7807608b959fd912f3c99c..b953898061691cf70f049dd5217579980351c31c 100644 (file)
@@ -1,32 +1,41 @@
+require 'common/runner'
+
 class RmRunner
   include Runner
 
-  def run(plugin, targets)
+  def run(plugin, *targets)
     targets.each do |target|
-      # Why think too hard? An account has an @, a domain doesn't.
+      # Why think too hard? An user has an @, a domain doesn't.
       if target.include?('@') then
         begin
-          account_description = plugin.describe_account(target)
-          plugin.delete_account(target)
-          puts "Removed account: #{target} (#{account_description})"
+          user_description = plugin.describe_user(target)
+          plugin.delete_user(target)
+          report(plugin, "Removed user: #{target} (#{user_description})")
+
+        rescue NonexistentUserError => e
+          report(plugin, "User not found: #{e.to_s}")
         rescue StandardError => e
-          puts "There was an error removing the account: #{e.to_s}"
+          report(plugin, "There was an error removing the user: #{e.to_s}")
           Kernel.exit(ExitCodes::DATABASE_ERROR)
         end
       else
         begin
-          # TODO: Delete all accounts first.
           domain_description = plugin.describe_domain(target)
           plugin.delete_domain(target)
-          puts "Removed domain: #{target} (#{domain_description})"
+          report(plugin, "Removed domain: #{target} (#{domain_description})")
+
+        rescue NonexistentUserError => e
+          # Can happen in the usernames.each... block.
+          report(plugin, "User not found: #{e.to_s}")
+        rescue NonexistentDomainError => e
+          report(plugin, "Domain not found: #{e.to_s}")
         rescue StandardError => e
-          puts "There was an error removing the domain: #{e.to_s}"
+          report(plugin, "There was an error removing the domain: #{e.to_s}")
           Kernel.exit(ExitCodes::DATABASE_ERROR)
         end
       end
     end
 
-    # TODO: remove from postfixadmin as well.
   end
 
 end