]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/roundcube.rb
Overhaul everything to get consistent error reports.
[mailshears.git] / lib / mv / plugins / roundcube.rb
1 require 'pg'
2
3 require 'common/roundcube_plugin'
4 require 'mv/mv_plugin'
5
6 class RoundcubeMv
7
8 include RoundcubePlugin
9 include MvPlugin
10
11
12 def mv_user(src, dst)
13 # It's obviously an error if the source user does not exist. It
14 # would also be an error if the destination domain didn't exist;
15 # however, Roundcube doesn't know about domains, so we let that slide.
16 raise NonexistentUserError.new(src.to_s()) if not user_exists(src)
17
18 # And it's an error if the destination user exists already.
19 raise UserAlreadyExistsError.new(dst.to_s()) if user_exists(dst)
20
21 sql_queries = ['UPDATE users SET username = $1 WHERE username = $2;']
22
23 begin
24 connection = PGconn.connect(@db_host,
25 @db_port,
26 @db_opts,
27 @db_tty,
28 @db_name,
29 @db_user,
30 @db_pass)
31
32 sql_queries.each do |sql_query|
33 connection.query(sql_query, [dst.to_s(), src.to_s()])
34 end
35
36 connection.close()
37
38 rescue PGError => e
39 # Pretend like we're database-agnostic in case we ever are.
40 raise DatabaseError.new(e)
41 end
42
43 end
44
45 end