]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/mv_runner.rb
ee762e1e70cf4198c1630b3404973d20c75ac264
[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 # Handle this once so we don't have to do it in every plugin.
16 if not dst.include?('@') then
17 msg = "the destination user #{dst} is not valid"
18 raise InvalidUserError.new(msg)
19 end
20
21 begin
22 src_description = plugin.describe_user(src)
23 plugin.mv_user(src, dst)
24 msg = "Moved user #{src} (#{src_description}) "
25 msg += "to #{dst}."
26 report(plugin, msg)
27 rescue InvalidUserError => e
28 report(plugin, e.message)
29 rescue NonexistentUserError => e
30 report(plugin, e.message)
31 rescue NonexistentDomainError => e
32 report(plugin, e.message)
33 rescue StandardError => e
34 msg = "There was an error (#{e.to_s}) moving the user: #{e.message}"
35 report(plugin, msg)
36 Kernel.exit(ExitCodes::DATABASE_ERROR)
37 end
38 end
39
40 end