Get prune working, at least in a simple case.
[mailshears.git] / lib / prune / prune_runner.rb
1 require 'common/runner'
2
3 # This is always needed, regardless of which plugin is running.
4 require 'prune/plugins/postfixadmin'
5
6 class PruneRunner
7 include Runner
8
9 def run(plugin)
10 # We don't want to check the PostfixAdmin database against itself.
11 return if plugin.class == PostfixadminPrune
12
13 pfa = PostfixadminPrune.new()
14
15 db_users = pfa.list_users()
16 db_domains = pfa.list_domains()
17
18 leftover_users = plugin.get_leftover_accounts(db_users)
19 leftover_domains = plugin.get_leftover_domains(db_domains)
20
21 leftover_users.each do |user|
22 user_description = plugin.describe_account(user)
23 plugin.delete_account(user)
24 report(plugin, "Removed user: #{user} (#{user_description})")
25 end
26
27 leftover_domains.each do |domain|
28 domain_description = plugin.describe_domain(domain)
29 plugin.delete_domain(domain)
30 report(plugin, "Removed domain: #{domain} (#{domain_description})")
31 end
32
33 end
34
35 end