Document everything with YARD and fix some bugs along the way.
[mailshears.git] / lib / rm / plugins / roundcube.rb
1 require 'pg'
2
3 require 'common/roundcube_plugin'
4 require 'rm/rm_plugin'
5
6 # Handle removal of Roundcube users from its database. Roundcube has
7 # no concept of domains.
8 #
9 class RoundcubeRm
10
11 include RoundcubePlugin
12 include RmPlugin
13
14 # Remove *user* from the Roundcube database. This should remove him
15 # from _every_ table in which he is referenced. Fortunately the
16 # Roundcube developers were nice enough to include DBMS-specific
17 # install and upgrade scripts, so Postgres can take advantage of ON
18 # DELETE triggers.
19 #
20 # @param user [User] the user to remove.
21 #
22 def remove_user(user)
23 raise NonexistentUserError.new(user.to_s()) if not user_exists(user)
24
25 # Get the primary key for this user in the "users" table.
26 user_id = self.get_user_id(user)
27
28 # Thanks to the ON DELETE triggers, this will remove all child
29 # records associated with user_id too.
30 sql_queries = ['DELETE FROM users WHERE user_id = $1::int;']
31
32 connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
33 @db_name, @db_user, @db_pass)
34
35 sql_queries.each do |sql_query|
36 connection.query(sql_query, [user_id])
37 end
38
39 connection.close()
40 end
41
42 end