X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fplugins%2Fpostfixadmin.rb;h=e22df6a53f7637945460ae3b61063fe8843278d3;hp=659b9b7d7166f98d2974cdc53159098cc9a9e8af;hb=df4e02ebf6a4e28a58abcb298a4442a245ad0b15;hpb=20b843bddcd73833d41f98ff79d92ef59bb4d81e diff --git a/lib/mv/plugins/postfixadmin.rb b/lib/mv/plugins/postfixadmin.rb index 659b9b7..e22df6a 100644 --- a/lib/mv/plugins/postfixadmin.rb +++ b/lib/mv/plugins/postfixadmin.rb @@ -3,22 +3,34 @@ require 'pg' require 'common/postfixadmin_plugin' require 'mv/mv_plugin' + +# Handle moving (renaming) of users in the Postfixadmin database. +# class PostfixadminMv include PostfixadminPlugin include MvPlugin + + # Move the user *src* to *dst* within the Postfixadmin + # database. This should "rename" him in _every_ table where he is + # referenced. Unfortunately that must be done manually. + # + # This can fail is *src* does not exist, or if *dst* already exists + # before the move. It will also fail if the domain associated with + # the user *dst* does not exist. + # + # @param src [User] the source user to be moved. + # + # @param dst [User] the destination user being moved to. + # def mv_user(src, dst) - # It's obviously an error if the source user does not exist. raise NonexistentUserError.new(src.to_s()) if not user_exists(src) - # And if the destination domain does not exist. if not domain_exists(dst.domain()) raise NonexistentDomainError.new(dst.domain.to_s()) end - # But the destination *user* should *not* exist. - # And it's an error if the destination user exists already. raise UserAlreadyExistsError.new(dst.to_s()) if user_exists(dst) mailbox_query = 'UPDATE mailbox SET ' @@ -43,15 +55,16 @@ class PostfixadminMv @db_name, @db_user, @db_pass) sql_queries.each do |sql_query| - varchar = 1043 # from pg_type.h - params = [{:value => dst.to_s(), :type => varchar}, - {:value => dst.domainpart(), :type => varchar}, - {:value => dst.localpart(), :type => varchar}, - {:value => src.to_s(), :type => varchar}] + varchar = 1043 # from pg_type.h + params = [{:value => dst.to_s(), :type => varchar}, + {:value => dst.domainpart(), :type => varchar}, + {:value => dst.localpart(), :type => varchar}, + {:value => src.to_s(), :type => varchar}] + + connection.query(sql_query, params) + end - connection.query(sql_query, params) connection.close() end - end