]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/rm_runner.rb
Replace 'account' with 'user' everywhere.
[mailshears.git] / lib / rm / rm_runner.rb
1 require 'common/runner'
2
3 class RmRunner
4 include Runner
5
6 def run(plugin, *targets)
7 targets.each do |target|
8 # Why think too hard? An user has an @, a domain doesn't.
9 if target.include?('@') then
10 begin
11 user_description = plugin.describe_user(target)
12 plugin.delete_user(target)
13 report(plugin, "Removed user: #{target} (#{user_description})")
14
15 rescue NonexistentUserError => e
16 report(plugin, "User not found: #{e.to_s}")
17 rescue StandardError => e
18 report(plugin, "There was an error removing the user: #{e.to_s}")
19 Kernel.exit(ExitCodes::DATABASE_ERROR)
20 end
21 else
22 begin
23 domain_description = plugin.describe_domain(target)
24 plugin.delete_domain(target)
25 report(plugin, "Removed domain: #{target} (#{domain_description})")
26
27 rescue NonexistentUserError => e
28 # Can happen in the usernames.each... block.
29 report(plugin, "User not found: #{e.to_s}")
30 rescue NonexistentDomainError => e
31 report(plugin, "Domain not found: #{e.to_s}")
32 rescue StandardError => e
33 report(plugin, "There was an error removing the domain: #{e.to_s}")
34 Kernel.exit(ExitCodes::DATABASE_ERROR)
35 end
36 end
37 end
38
39 end
40
41 end