def delete_domain(domain)
+ raise NonexistentDomainError.new(domain) if not domain_exists(domain)
+
sql_queries = ['DELETE FROM domain_admins WHERE domain = $1;']
sql_queries << 'DELETE FROM alias WHERE domain = $1;'
sql_queries << 'DELETE FROM mailbox WHERE domain = $1;'
sql_queries << 'DELETE FROM alias_domain WHERE alias_domain = $1;'
sql_queries << 'DELETE FROM log WHERE domain = $1;'
sql_queries << 'DELETE FROM vacation WHERE domain = $1;'
+ sql_queries << 'DELETE FROM domain WHERE domain = $1;'
begin
connection = PGconn.connect(@db_host,
end
+ protected;
- def get_domain_usernames(domain)
- usernames = []
+ def domain_exists(domain)
+ count = 0
# Just assume PostgreSQL for now.
begin
@db_user,
@db_pass)
- sql_query = 'SELECT username FROM mailbox WHERE domain = $1;'
-
+ sql_query = 'SELECT COUNT(domain) as count FROM domain WHERE domain = $1;'
connection.query(sql_query, [domain]) do |result|
- usernames = result.field_values('username')
+ return false if result.ntuples() < 1
+ begin
+ count = result.getvalue(0,0).to_i()
+ return false if count.nil?
+ rescue StandardError
+ return false
+ end
end
-
connection.close()
rescue PGError => e
- # Pretend like we're database-agnostic in case we ever are.
+ # But pretend like we're database-agnostic in case we ever are.
raise DatabaseError.new(e)
end
- return usernames
+ return (count > 0)
end
end