require 'common/errors' require 'common/runner' class MvRunner include Runner def run(plugin, src, dst) # 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