X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Frm%2Fplugins%2Froundcube.rb;h=56c3108c354cf79d0b5017e025d8e7c64fb75a5a;hp=a315e77f49b2ec0c9b17c09d228ee55db8fa8459;hb=fa7782720ff15fce29b6f875678e9fd0c197485a;hpb=f819b178c5c1cb8adda0182c610e5c52fad8bea7 diff --git a/lib/rm/plugins/roundcube.rb b/lib/rm/plugins/roundcube.rb index a315e77..56c3108 100644 --- a/lib/rm/plugins/roundcube.rb +++ b/lib/rm/plugins/roundcube.rb @@ -3,49 +3,40 @@ require 'pg' require 'common/roundcube_plugin' require 'rm/rm_plugin' +# Handle removal of Roundcube users from its database. Roundcube has +# no concept of domains. +# class RoundcubeRm include RoundcubePlugin include RmPlugin - def delete_user(user) - # Delete the given username and any records in other tables - # belonging to it. + # Remove *user* from the Roundcube database. This should remove him + # from _every_ table in which he is referenced. Fortunately the + # Roundcube developers were nice enough to include DBMS-specific + # install and upgrade scripts, so Postgres can take advantage of ON + # DELETE triggers. + # + # @param user [User] the user to remove. + # + def remove_user(user) raise NonexistentUserError.new(user.to_s()) if not user_exists(user) + # Get the primary key for this user in the "users" table. user_id = self.get_user_id(user) - # The Roundcube developers were nice enough to include - # DBMS-specific install and upgrade scripts, so Postgres can take - # advantage of ON DELETE triggers. Here's an example: - # - # ... - # user_id integer NOT NULL - # REFERENCES users (user_id) ON DELETE CASCADE ON UPDATE CASCADE - # - # This query is of course necessary with any DBMS: - sql_queries = ['DELETE FROM users WHERE user_id = $1::int;'] + # Thanks to the ON DELETE triggers, this will remove all child + # records associated with user_id too. + sql_query = 'DELETE FROM users WHERE user_id = $1::int;' - begin - connection = PGconn.connect(@db_host, - @db_port, - @db_opts, - @db_tty, - @db_name, - @db_user, - @db_pass) - - sql_queries.each do |sql_query| - connection.query(sql_query, [user_id]) - end + connection = PG::Connection.new(@db_hash) + begin + connection.sync_exec_params(sql_query, [user_id]) + ensure + # Make sure the connection gets closed even if the query explodes. connection.close() - - rescue PGError => e - # Pretend like we're database-agnostic in case we ever are. - raise DatabaseError.new(e) end - end end