]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/davical.rb
Overhaul everything to get consistent error reports.
[mailshears.git] / lib / rm / plugins / davical.rb
1 require 'pg'
2
3 require 'common/davical_plugin'
4 require 'rm/rm_plugin'
5
6 class DavicalRm
7 #
8 # DAViCal only supports Postgres, so even if we ever are
9 # database-agnostic, this plugin can't be.
10 #
11 include DavicalPlugin
12 include RmPlugin
13
14
15 def delete_user(user)
16 # Delete the given username. DAViCal uses foreign keys properly
17 # and only supports postgres, so we let the ON DELETE CASCADE
18 # trigger handle most of the work.
19 raise NonexistentUserError.new(user.to_s()) if not user_exists(user)
20
21 sql_queries = ['DELETE FROM usr WHERE username = $1']
22
23 begin
24 connection = PGconn.connect(@db_host,
25 @db_port,
26 @db_opts,
27 @db_tty,
28 @db_name,
29 @db_user,
30 @db_pass)
31
32 sql_queries.each do |sql_query|
33 connection.query(sql_query, [user.to_s()])
34 end
35
36 connection.close()
37
38 rescue PGError => e
39 # Pretend like we're database-agnostic in case we ever are.
40 raise DatabaseError.new(e)
41 end
42
43 end
44
45
46 end