]> gitweb.michael.orlitzky.com - mailshears.git/blob - lib/rm/plugins/roundcube.rb
Use semantic bound on pg library.
[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.to_s()) 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 connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
30 @db_name, @db_user, @db_pass)
31
32 sql_queries.each do |sql_query|
33 connection.query(sql_query, [user_id])
34 end
35
36 connection.close()
37 end
38
39 end