]>
gitweb.michael.orlitzky.com - mailshears.git/blob - lib/mv/plugins/davical.rb
58287b3b69937eaa32b2823d3ffd62f13de83566
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_queries
= ['UPDATE usr SET username = $1 WHERE username = $2']
34 connection
= PGconn
.connect(@db_host, @db_port, @db_opts, @db_tty,
35 @db_name, @db_user, @db_pass)
37 sql_queries
.each
do |sql_query
|
38 connection
.query(sql_query
, [dst
.to_s(), src
.to_s()])