]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/mv_runner.rb
1 require 'common/domain'
2 require 'common/errors'
3 require 'common/runner'
5 # Perform the moving (renaming) of users/domains using {MvPlugin}s.
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}.
14 # @param cfg [Configuration] unused.
16 # @param plugin [Class] plugin class that will perform the move.
18 # @param src [User] the source user to be moved.
20 # @param dst [User] the destination user being moved to.
22 def run(cfg
, plugin
, src
, dst
)
24 if src
.is_a
?(Domain
) or dst
.is_a
?(Domain
) then
25 msg
= 'only users can be moved'
26 raise NotImplementedError
.new(msg
)
30 src_description
= plugin
.describe(src
)
31 plugin
.mv_user(src
, dst
)
32 dst_description
= plugin
.describe(dst
)
35 msg +
= add_description(src
, src_description
)
37 msg +
= add_description(dst
, dst_description
)
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
50 report(plugin
, "Destination domain #{dst.domainpart()} not found.")
51 rescue UserAlreadyExistsError
52 report(plugin
, "Destination user #{dst.to_s()} already exists.")