]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/mv_runner.rb
fe44e5c244d3fe4cff66f140bb4d684ca903364a
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
)
34 msg
= "Moved user #{src} "
36 # Only append the extra description if it's useful.
37 if not src_description
.nil? and
38 not src_description
.empty
? and
39 not src_description
== src
.to_s() then
40 msg +
= "(#{src_description}) "
45 # Only append the extra description if it's useful.
46 if not dst_description
.nil? and
47 not dst_description
.empty
? and
48 not dst_description
== dst
.to_s() then
49 msg +
= " (#{dst_description})"
55 rescue NonexistentUserError
=> e
56 # This means that the SOURCE user didn't exist, since a
57 # nonexistent destination user is perfectly expected.
58 report(plugin
, "Source user #{src.to_s()} not found.")
59 rescue NonexistentDomainError
=> e
60 # This could mean that the source domain doesn't exist, but in
61 # that case, we just report that the source user doesn't
62 # exist. So a nonexistent domain refers to a nonexistent
64 report(plugin
, "Destination domain #{dst.domainpart()} not found.")
65 rescue UserAlreadyExistsError
=> e
66 report(plugin
, "Destination user #{dst.to_s()} already exists.")