X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Frm%2Fplugins%2Fpostfixadmin.rb;h=c8e44abd2d9140b5a75d969078e31b6eb836aa02;hp=b950b7a76d6c27e9d80c1d9d0b0972427681baf3;hb=b947ef8844f090eedd50be0383abe417d910bb1a;hpb=df4e02ebf6a4e28a58abcb298a4442a245ad0b15 diff --git a/lib/rm/plugins/postfixadmin.rb b/lib/rm/plugins/postfixadmin.rb index b950b7a..c8e44ab 100644 --- a/lib/rm/plugins/postfixadmin.rb +++ b/lib/rm/plugins/postfixadmin.rb @@ -44,21 +44,23 @@ class PostfixadminRm # Should be handled by a trigger, according to PostfixAdmin code. sql_queries << 'DELETE FROM vacation_notification WHERE on_vacation = $1;' - 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.to_s()]) + connection = PG::Connection.new(@db_hash) + + begin + sql_queries.each do |sql_query| + connection.query(sql_query, [user.to_s()]) + end + + # The earlier alias update query will leave things like + # "foo@example.com,,bar@example.com" in the "goto" column. Now + # we fix it. We don't do it in the loop because query() craps + # out on the superfluous parameter. + sql_query = "UPDATE alias SET goto=REPLACE(goto, ',,', ',');" + connection.query(sql_query) + ensure + # Make sure the connection gets closed even if a query explodes. + connection.close() end - - # The earlier alias update query will leave things like - # "foo@example.com,,bar@example.com" in the "goto" column. Now - # we fix it. We don't do it in the loop because query() craps - # out on the superfluous parameter. - sql_query = "UPDATE alias SET goto=REPLACE(goto, ',,', ',');" - connection.query(sql_query) - - connection.close() end @@ -96,14 +98,16 @@ class PostfixadminRm sql_queries << 'DELETE FROM vacation WHERE domain = $1;' sql_queries << 'DELETE FROM domain WHERE domain = $1;' - connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty, - @db_name, @db_user, @db_pass) + connection = PG::Connection.new(@db_hash) - sql_queries.each do |sql_query| - connection.query(sql_query, [domain.to_s()]) + begin + sql_queries.each do |sql_query| + connection.query(sql_query, [domain.to_s()]) + end + ensure + # Make sure the connection gets closed even if a query explodes. + connection.close() end - - connection.close() end end