X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fmv_runner.rb;h=d2a7c5ba01d4664882a14b9b539f76f1f578d709;hp=a0fa8e7ae6089e9899a7910b0355b3b12c7a14df;hb=861e51dd6a409cb41fa6fdac3f49195acccc6541;hpb=e3826d8926e11763837a591986d453e9ef5d9dec diff --git a/lib/mv/mv_runner.rb b/lib/mv/mv_runner.rb index a0fa8e7..d2a7c5b 100644 --- a/lib/mv/mv_runner.rb +++ b/lib/mv/mv_runner.rb @@ -1,8 +1,34 @@ +require 'common/errors' +require 'common/runner' + class MvRunner include Runner def run(plugin, src, dst) - puts "Not implemented" + # Why think too hard? An user has an @, a domain doesn't. + if not src.include?('@') then + # We only support moving users right now, and the destination + # domain must already exist. + raise NotImplementedError.new('Only users can be moved.') + end + + begin + src_description = plugin.describe_user(src) + plugin.mv_user(src, dst) + msg = "Moved user #{src} (#{src_description}) " + msg += "to #{dst}." + report(plugin, msg) + rescue InvalidUserError => e + report(plugin, e.message) + rescue NonexistentUserError => e + report(plugin, e.message) + rescue NonexistentDomainError => e + report(plugin, e.message) + rescue StandardError => e + msg = "There was an error (#{e.to_s}) moving the user: #{e.message}" + report(plugin, msg) + Kernel.exit(ExitCodes::DATABASE_ERROR) + end end end