X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fmv_runner.rb;h=6a4413b412ee8256b0988518f8659c59c0fec245;hp=c7dbc5e7497147c90f40dbfb696474e11f5f8619;hb=refs%2Ftags%2F0.0.4;hpb=51f027b01e242737956c3ab5aecdd322d6ceeeed diff --git a/lib/mv/mv_runner.rb b/lib/mv/mv_runner.rb index c7dbc5e..6a4413b 100644 --- a/lib/mv/mv_runner.rb +++ b/lib/mv/mv_runner.rb @@ -1,10 +1,56 @@ +require 'common/domain' +require 'common/errors' require 'common/runner' +# Perform the moving (renaming) of users/domains using {MvPlugin}s. +# class MvRunner include Runner - def run(plugin, src, dst) - puts "Not implemented" + # Run *plugin* to move the user *src* to *dst*. The method + # signature includes the unused *cfg* for consistency with the + # runners that do need a {Configuration}. + # + # @param cfg [Configuration] unused. + # + # @param plugin [Class] plugin class that will perform the move. + # + # @param src [User] the source user to be moved. + # + # @param dst [User] the destination user being moved to. + # + def run(cfg, plugin, src, dst) + + if src.is_a?(Domain) or dst.is_a?(Domain) then + msg = 'only users can be moved' + raise NotImplementedError.new(msg) + end + + begin + src_description = plugin.describe(src) + plugin.mv_user(src, dst) + dst_description = plugin.describe(dst) + + msg = "Moved user " + msg += add_description(src, src_description) + msg += " to " + msg += add_description(dst, dst_description) + msg += "." + report(plugin, msg) + + rescue NonexistentUserError + # This means that the SOURCE user didn't exist, since a + # nonexistent destination user is perfectly expected. + report(plugin, "Source user #{src.to_s()} not found.") + rescue NonexistentDomainError + # This could mean that the source domain doesn't exist, but in + # that case, we just report that the source user doesn't + # exist. So a nonexistent domain refers to a nonexistent + # DESTINATION domain. + report(plugin, "Destination domain #{dst.domainpart()} not found.") + rescue UserAlreadyExistsError + report(plugin, "Destination user #{dst.to_s()} already exists.") + end end end