Stop pretending that we'll ever work with another DBMS.
[mailshears.git] / lib / rm / plugins / postfixadmin.rb
index eddf93976981a5d031772cb3398001346d0fbc12..103912b648e71ce8edf02a6be0745d76cded190b 100644 (file)
@@ -23,32 +23,21 @@ class PostfixadminRm
     # Should be handled by a trigger, according to PostfixAdmin code.
     sql_queries << 'DELETE FROM vacation_notification WHERE on_vacation = $1;'
 
-    begin
-      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()])
-      end
+    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
+                                @db_name, @db_user, @db_pass)
 
-      # 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)
+    sql_queries.each do |sql_query|
+      connection.query(sql_query, [user.to_s()])
+    end
 
-      connection.close()
+    # 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)
 
-    rescue PGError => e
-      # Pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
-    end
+    connection.close()
   end
 
 
@@ -63,26 +52,14 @@ class PostfixadminRm
     sql_queries << 'DELETE FROM vacation WHERE domain = $1;'
     sql_queries << 'DELETE FROM domain WHERE domain = $1;'
 
-    begin
-      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, [domain.to_s()])
-      end
-
-      connection.close()
+    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
+                                @db_name, @db_user, @db_pass)
 
-    rescue PGError => e
-      # Pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
+    sql_queries.each do |sql_query|
+      connection.query(sql_query, [domain.to_s()])
     end
 
+    connection.close()
   end
 
 
@@ -91,32 +68,22 @@ class PostfixadminRm
   def domain_exists(domain)
     count = 0
 
-    # Just assume PostgreSQL for now.
-    begin
-      connection = PGconn.connect(@db_host,
-                                  @db_port,
-                                  @db_opts,
-                                  @db_tty,
-                                  @db_name,
-                                  @db_user,
-                                  @db_pass)
-
-      sql_query = 'SELECT COUNT(domain) as count FROM domain WHERE domain = $1;'
-      connection.query(sql_query, [domain.to_s()]) do |result|
-        return false if result.ntuples() < 1
-        begin
-          count = result.getvalue(0,0).to_i()
-          return false if count.nil?
-        rescue StandardError
-          return false
-        end
+    connection = PGconn.connect(@db_host, @db_port, @db_opts, @db_tty,
+                                @db_name, @db_user, @db_pass)
+
+    sql_query = 'SELECT COUNT(domain) as count FROM domain WHERE domain = $1;'
+    connection.query(sql_query, [domain.to_s()]) do |result|
+      return false if result.ntuples() < 1
+      begin
+        count = result.getvalue(0,0).to_i()
+        return false if count.nil?
+      rescue StandardError
+        return false
       end
-      connection.close()
-    rescue PGError => e
-      # But pretend like we're database-agnostic in case we ever are.
-      raise DatabaseError.new(e)
     end
 
+    connection.close()
+
     return (count > 0)
   end