X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fmv_runner.rb;h=ee762e1e70cf4198c1630b3404973d20c75ac264;hp=c7dbc5e7497147c90f40dbfb696474e11f5f8619;hb=1d7d65c9583a879358de36ab1ac26b35a2805ba8;hpb=51f027b01e242737956c3ab5aecdd322d6ceeeed diff --git a/lib/mv/mv_runner.rb b/lib/mv/mv_runner.rb index c7dbc5e..ee762e1 100644 --- a/lib/mv/mv_runner.rb +++ b/lib/mv/mv_runner.rb @@ -1,10 +1,40 @@ +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 + + # Handle this once so we don't have to do it in every plugin. + if not dst.include?('@') then + msg = "the destination user #{dst} is not valid" + raise InvalidUserError.new(msg) + 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