852d9c4c66b1fa97467de79c2628a34fd6320338
[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_queries = ['DELETE FROM usr WHERE username = $1']
27
28 connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
29 @db_name, @db_user, @db_pass)
30
31 sql_queries.each do |sql_query|
32 connection.query(sql_query, [user.to_s()])
33 end
34
35 connection.close()
36 end
37
38
39 end