]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/agendav.rb
46bd4073bfd459b4b2569ed1fd1d2f3a4657974f
[mailshears.git] / lib / rm / plugins / agendav.rb
1 require 'pg'
2
3 require 'common/agendav_plugin'
4 require 'rm/rm_plugin'
5
6
7 # Handle the removal of Agendav users from its database. Agendav has
8 # no concept of domains.
9 #
10 class AgendavRm
11
12 include AgendavPlugin
13 include RmPlugin
14
15
16 # Remove *user* from the Agendav database. This should remove him
17 # from _every_ table in which he is referenced.
18 #
19 # @param user [User] the user to remove.
20 #
21 def remove_user(user)
22 raise NonexistentUserError.new(user.to_s()) if not user_exists(user)
23
24 sql_queries = ['DELETE FROM prefs WHERE username = $1;']
25 sql_queries << 'DELETE FROM shared WHERE user_from = $1;'
26
27 connection = PG::Connection.new(@db_hash)
28 begin
29 sql_queries.each do |sql_query|
30 connection.query(sql_query, [user.to_s()])
31 end
32 ensure
33 # Make sure the connection gets closed even if a query explodes.
34 connection.close()
35 end
36 end
37
38 end