Implement user_exists() everywhere and use it to correct the console output.
[mailshears.git] / lib / rm / plugins / agendav.rb
1 require 'pg'
2
3 require 'common/agendav_plugin'
4 require 'rm/rm_plugin'
5
6 class AgendavRm
7
8 include AgendavPlugin
9 include RmPlugin
10
11
12 def delete_account(account)
13 # Delete the given username and any records in other tables
14 # belonging to it.
15 raise NonexistentAccountError.new(account) if not user_exists(account)
16
17 sql_queries = ['DELETE FROM prefs WHERE username = $1;']
18 sql_queries << 'DELETE FROM shared WHERE user_from = $1;'
19
20 begin
21 connection = PGconn.connect(@db_host,
22 @db_port,
23 @db_opts,
24 @db_tty,
25 @db_name,
26 @db_user,
27 @db_pass)
28
29 sql_queries.each do |sql_query|
30 connection.query(sql_query, [account])
31 end
32
33 connection.close()
34
35 rescue PGError => e
36 # Pretend like we're database-agnostic in case we ever are.
37 raise DatabaseError.new(e)
38 end
39
40 end
41
42 end