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