]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/roundcube.rb
3 require 'common/roundcube_plugin'
6 # Handle moving (renaming) of users in the Roundcube
7 # database. Roundcube has no concept of domains.
11 include RoundcubePlugin
15 # Move the user *src* to *dst* within the Roundcube database. This
16 # should "rename" him in _every_ table where he is referenced.
17 # Roundcube uses foreign keys properly, so we let the ON UPDATE
18 # CASCADE trigger handle most of the work.
20 # This can fail is *src* does not exist, or if *dst* already exists
21 # before the move. It should also be an error if the destination
22 # domain doesn't exist. But Roundcube doesn't know about domains, so
25 # @param src [User] the source user to be moved.
27 # @param dst [User] the destination user being moved to.
30 raise NonexistentUserError
.new(src
.to_s()) if not user_exists(src
)
31 raise UserAlreadyExistsError
.new(dst
.to_s()) if user_exists(dst
)
33 sql_query
= 'UPDATE users SET username = $1 WHERE username = $2;'
35 connection
= PG
::Connection.new(@db_hash)
37 connection
.sync_exec_params(sql_query
, [dst
.to_s(), src
.to_s()])
39 # Make sure the connection gets closed even if the query explodes.