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