]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/mv/mv_runner.rb
Move the "mv" invalid destination user check into the runner.
[mailshears.git] / lib / mv / mv_runner.rb
index a0fa8e7ae6089e9899a7910b0355b3b12c7a14df..ee762e1e70cf4198c1630b3404973d20c75ac264 100644 (file)
@@ -1,8 +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