Make pruning use the correct config and clean up *before* running tests, too.
[mailshears.git] / lib / prune / prune_runner.rb
index 12a02d7417500917557f6235f5d2c45244931077..fbad8e8f11c4e5cb71f7dcc2ccbdc0caf7ad40b5 100644 (file)
@@ -1,36 +1,24 @@
 require 'common/runner'
-
-# This is always needed, regardless of which plugin is running.
 require 'prune/plugins/postfixadmin'
+require 'rm/rm_runner'
 
 class PruneRunner
   include Runner
 
-  def run(plugin)
+  def run(cfg, plugin)
     # We don't want to check the PostfixAdmin database against itself.
     return if plugin.class == PostfixadminPrune
 
-    cfg = Configuration.new()
     pfa = PostfixadminPrune.new(cfg)
 
     db_users = pfa.list_users()
     db_domains = pfa.list_domains()
 
-    leftover_users = plugin.get_leftover_users(db_users)
-    leftover_domains = plugin.get_leftover_domains(db_domains)
-
-    leftover_users.each do |user|
-      user_description = plugin.describe_user(user)
-      plugin.delete_user(user)
-      report(plugin, "Removed user: #{user} (#{user_description})")
-    end
-
-    leftover_domains.each do |domain|
-      domain_description = plugin.describe_domain(domain)
-      plugin.delete_domain(domain)
-      report(plugin, "Removed domain: #{domain} (#{domain_description})")
-    end
+    leftovers  = plugin.get_leftover_users(db_users)
+    leftovers += plugin.get_leftover_domains(db_domains)
 
+    rm_runner = RmRunner.new()
+    rm_runner.run(cfg, plugin, *leftovers)
   end
 
 end