lib,test: replace connection query() method with sync_exec{,_params}.
[mailshears.git] / lib / rm / plugins / davical.rb
1 require 'pg'
2
3 require 'common/davical_plugin'
4 require 'rm/rm_plugin'
5
6 # Handle the removal of DAViCal users from its database. DAViCal has
7 # no concept of domains.
8 #
9 class DavicalRm
10
11 include DavicalPlugin
12 include RmPlugin
13
14
15 # Remove *user* from the DAViCal database. This should remove him
16 # from _every_ table in which he is referenced. Fortunately, DAViCal
17 # uses foreign keys properly (and only supports postgres, where they
18 # work!), so we can let the ON DELETE CASCADE trigger handle most of
19 # the work.
20 #
21 # @param user [User] the user to remove.
22 #
23 def remove_user(user)
24 raise NonexistentUserError.new(user.to_s()) if not user_exists(user)
25
26 sql_query = 'DELETE FROM usr WHERE username = $1;'
27
28 connection = PG::Connection.new(@db_hash)
29 begin
30 connection.sync_exec_params(sql_query, [user.to_s()])
31 ensure
32 # Make sure the connection gets closed even if the query explodes.
33 connection.close()
34 end
35 end
36
37
38 end