0e5e909e268944c25f2003e82eceb84bcc5b7bda
[mailshears.git] / lib / mv / mv_runner.rb
1 require 'common/domain'
2 require 'common/errors'
3 require 'common/runner'
4
5 class MvRunner
6 include Runner
7
8 def run(cfg, plugin, src, dst)
9
10 if src.is_a?(Domain) or dst.is_a?(Domain) then
11 msg = 'only users can be moved'
12 raise NotImplementedError.new(msg)
13 end
14
15 begin
16 src_description = plugin.describe(src)
17 plugin.mv_user(src, dst)
18 dst_description = plugin.describe(dst)
19
20 msg = "Moved user #{src} "
21
22 # Only append the extra description if it's useful.
23 if not src_description.nil? and
24 not src_description.empty? and
25 not src_description == src.to_s() then
26 msg += "(#{src_description}) "
27 end
28
29 msg += "to #{dst}"
30
31 # Only append the extra description if it's useful.
32 if not dst_description.nil? and
33 not dst_description.empty? and
34 not dst_description == dst.to_s() then
35 msg += " (#{dst_description})"
36 end
37
38 msg += "."
39 report(plugin, msg)
40
41 rescue NonexistentUserError => e
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 => e
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 => e
52 report(plugin, "Destination user #{dst.to_s()} already exists.")
53 end
54 end
55
56 end