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