]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/mv_runner.rb
d2a7c5ba01d4664882a14b9b539f76f1f578d709
[mailshears.git] / lib / mv / mv_runner.rb
1 require 'common/errors'
2 require 'common/runner'
3
4 class MvRunner
5 include Runner
6
7 def run(plugin, src, dst)
8 # Why think too hard? An user has an @, a domain doesn't.
9 if not src.include?('@') then
10 # We only support moving users right now, and the destination
11 # domain must already exist.
12 raise NotImplementedError.new('Only users can be moved.')
13 end
14
15 begin
16 src_description = plugin.describe_user(src)
17 plugin.mv_user(src, dst)
18 msg = "Moved user #{src} (#{src_description}) "
19 msg += "to #{dst}."
20 report(plugin, msg)
21 rescue InvalidUserError => e
22 report(plugin, e.message)
23 rescue NonexistentUserError => e
24 report(plugin, e.message)
25 rescue NonexistentDomainError => e
26 report(plugin, e.message)
27 rescue StandardError => e
28 msg = "There was an error (#{e.to_s}) moving the user: #{e.message}"
29 report(plugin, msg)
30 Kernel.exit(ExitCodes::DATABASE_ERROR)
31 end
32 end
33
34 end