lib,test: replace connection query() method with sync_exec{,_params}.
[mailshears.git] / lib / mv / mv_runner.rb
1 require 'common/domain'
2 require 'common/errors'
3 require 'common/runner'
4
5 # Perform the moving (renaming) of users/domains using {MvPlugin}s.
6 #
7 class MvRunner
8 include Runner
9
10 # Run *plugin* to move the user *src* to *dst*. The method
11 # signature includes the unused *cfg* for consistency with the
12 # runners that do need a {Configuration}.
13 #
14 # @param cfg [Configuration] unused.
15 #
16 # @param plugin [Class] plugin class that will perform the move.
17 #
18 # @param src [User] the source user to be moved.
19 #
20 # @param dst [User] the destination user being moved to.
21 #
22 def run(cfg, plugin, src, dst)
23
24 if src.is_a?(Domain) or dst.is_a?(Domain) then
25 msg = 'only users can be moved'
26 raise NotImplementedError.new(msg)
27 end
28
29 begin
30 src_description = plugin.describe(src)
31 plugin.mv_user(src, dst)
32 dst_description = plugin.describe(dst)
33
34 msg = "Moved user "
35 msg += add_description(src, src_description)
36 msg += " to "
37 msg += add_description(dst, dst_description)
38 msg += "."
39 report(plugin, msg)
40
41 rescue NonexistentUserError
42 # This means that the SOURCE user didn't exist, since a
43 # nonexistent destination user is perfectly expected.
44 report(plugin, "Source user #{src.to_s()} not found.")
45 rescue NonexistentDomainError
46 # This could mean that the source domain doesn't exist, but in
47 # that case, we just report that the source user doesn't
48 # exist. So a nonexistent domain refers to a nonexistent
49 # DESTINATION domain.
50 report(plugin, "Destination domain #{dst.domainpart()} not found.")
51 rescue UserAlreadyExistsError
52 report(plugin, "Destination user #{dst.to_s()} already exists.")
53 end
54 end
55
56 end