]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/roundcube.rb
23782d20a575471820aa279f7ce47b346e68f2e2
[mailshears.git] / lib / rm / plugins / roundcube.rb
1 require 'pg'
2
3 require 'common/roundcube_plugin'
4 require 'rm/rm_plugin'
5
6 class RoundcubeRm
7
8 include RoundcubePlugin
9 include RmPlugin
10
11 def delete_user(user)
12 # Delete the given username and any records in other tables
13 # belonging to it.
14 raise NonexistentUserError.new(user) if not user_exists(user)
15
16 user_id = self.get_user_id(user)
17
18 # The Roundcube developers were nice enough to include
19 # DBMS-specific install and upgrade scripts, so Postgres can take
20 # advantage of ON DELETE triggers. Here's an example:
21 #
22 # ...
23 # user_id integer NOT NULL
24 # REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE
25 #
26 # This query is of course necessary with any DBMS:
27 sql_queries = ['DELETE FROM users WHERE user_id = $1::int;']
28
29 begin
30 connection = PGconn.connect(@db_host,
31 @db_port,
32 @db_opts,
33 @db_tty,
34 @db_name,
35 @db_user,
36 @db_pass)
37
38 sql_queries.each do |sql_query|
39 connection.query(sql_query, [user_id])
40 end
41
42 connection.close()
43
44 rescue PGError => e
45 # Pretend like we're database-agnostic in case we ever are.
46 raise DatabaseError.new(e)
47 end
48
49 end
50
51 end