7f345a4a70bb73094d02110ce8f6ff05d6a315e5
[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 connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
24 @db_name, @db_user, @db_pass)
25
26 sql_queries.each do |sql_query|
27 connection.query(sql_query, [dst.to_s(), src.to_s()])
28 end
29
30 connection.close()
31 end
32
33 end