]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/agendav.rb
ad1e9c2bfcf9f88b6fb67cf893a4c0ecb4d0348a
[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 connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
25 @db_name, @db_user, @db_pass)
26
27 sql_queries.each do |sql_query|
28 connection.query(sql_query, [dst.to_s(), src.to_s()])
29 end
30
31 connection.close()
32 end
33
34 end