112fa2ab52f307e6dcff9fbe3e65f93f213ed7d5
[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
12 def mv_domain(from, to)
13 # AgenDAV doesn't have a concept of domains.
14 end
15
16 def mv_user(from, to)
17 sql_queries = ['UPDATE prefs SET username = $1 WHERE username $2;']
18 sql_queries << 'UPDATE shared SET user_from = $1 WHERE user_from = $2;'
19 sql_queries << 'UPDATE shared SET user_which = $1 WHERE user_which = $2;'
20
21 begin
22 connection = PGconn.connect(@db_host,
23 @db_port,
24 @db_opts,
25 @db_tty,
26 @db_name,
27 @db_user,
28 @db_pass)
29
30 sql_queries.each do |sql_query|
31 connection.query(sql_query, [to, from])
32 end
33
34 connection.close()
35
36 rescue PGError => e
37 # Pretend like we're database-agnostic in case we ever are.
38 raise DatabaseError.new(e)
39 end
40
41 end
42
43 end