Document everything with YARD and fix some bugs along the way.
[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 = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
28 @db_name, @db_user, @db_pass)
29
30 sql_queries.each do |sql_query|
31 connection.query(sql_query, [user.to_s()])
32 end
33
34 connection.close()
35 end
36
37 end