Commit 514c96d4 authored by Pierre DAVID's avatar Pierre DAVID

Fix DELETE triggers on host/alias/mx deletion

parent 83ac8ce9
...@@ -379,10 +379,13 @@ CREATE OR REPLACE FUNCTION dns.mod_mx_alias () ...@@ -379,10 +379,13 @@ CREATE OR REPLACE FUNCTION dns.mod_mx_alias ()
PERFORM sum (dns.gen_norm_idname (OLD.idname)) ; PERFORM sum (dns.gen_norm_idname (OLD.idname)) ;
END IF ; END IF ;
IF TG_OP = 'DELETE' -- There is no delete trigger on dns.mx nor dns.alias:
THEN -- Forward zone is modified by dns.del_name explicitly
PERFORM sum (dns.gen_norm_idname (OLD.idname)) ; -- triggered for a delete on these tables
END IF ; -- IF TG_OP = 'DELETE'
-- THEN
-- nothing
-- END IF ;
RETURN NEW ; RETURN NEW ;
END ; END ;
...@@ -470,10 +473,14 @@ CREATE OR REPLACE FUNCTION dns.mod_host () ...@@ -470,10 +473,14 @@ CREATE OR REPLACE FUNCTION dns.mod_host ()
-- IP addresses did not change -- IP addresses did not change
END IF ; END IF ;
-- There is no delete trigger on dns.host:
-- reverse zone is modified when triggering delete
-- on dns.addr
-- forward zone is modified when the dns.name row is deleted
-- (implicitly via a distinct delete trigger on dns.host)
-- IF TG_OP = 'DELETE' -- IF TG_OP = 'DELETE'
-- THEN -- THEN
-- no need to regenerate anything since all IP addresses have -- nothing
-- already been removed before
-- END IF ; -- END IF ;
RETURN NEW ; RETURN NEW ;
...@@ -595,13 +602,19 @@ CREATE OR REPLACE FUNCTION dns.check_ip_grp (INET, INTEGER) ...@@ -595,13 +602,19 @@ CREATE OR REPLACE FUNCTION dns.check_ip_grp (INET, INTEGER)
CREATE OR REPLACE FUNCTION dns.del_name () CREATE OR REPLACE FUNCTION dns.del_name ()
RETURNS trigger AS $$ RETURNS trigger AS $$
BEGIN BEGIN
DELETE FROM dns.name WHERE idname = OLD.idname ; PERFORM sum (dns.gen_norm_iddom (n.iddom, n.idview))
RETURN NULL ; FROM dns.name n
EXCEPTION WHERE n.idname = OLD.idname
WHEN foreign_key_violation ;
THEN BEGIN
-- do nothing DELETE FROM dns.name WHERE idname = OLD.idname ;
RETURN NULL ; RETURN NULL ;
EXCEPTION
WHEN foreign_key_violation
THEN
-- do nothing
RETURN NULL ;
END ;
END ; END ;
$$ LANGUAGE 'plpgsql' ; $$ LANGUAGE 'plpgsql' ;
......
...@@ -36,15 +36,15 @@ CREATE TRIGGER tr_mod_addr ...@@ -36,15 +36,15 @@ CREATE TRIGGER tr_mod_addr
FOR EACH ROW EXECUTE PROCEDURE dns.mod_addr () ; FOR EACH ROW EXECUTE PROCEDURE dns.mod_addr () ;
CREATE TRIGGER tr_mod_host CREATE TRIGGER tr_mod_host
AFTER INSERT OR UPDATE OR DELETE ON dns.host AFTER INSERT OR UPDATE ON dns.host
FOR EACH ROW EXECUTE PROCEDURE dns.mod_host () ; FOR EACH ROW EXECUTE PROCEDURE dns.mod_host () ;
CREATE TRIGGER tr_mod_alias CREATE TRIGGER tr_mod_alias
AFTER INSERT OR UPDATE OR DELETE ON dns.alias AFTER INSERT OR UPDATE ON dns.alias
FOR EACH ROW EXECUTE PROCEDURE dns.mod_mx_alias () ; FOR EACH ROW EXECUTE PROCEDURE dns.mod_mx_alias () ;
CREATE TRIGGER tr_mod_mx CREATE TRIGGER tr_mod_mx
AFTER INSERT OR UPDATE OR DELETE ON dns.mx AFTER INSERT OR UPDATE ON dns.mx
FOR EACH ROW EXECUTE PROCEDURE dns.mod_mx_alias () ; FOR EACH ROW EXECUTE PROCEDURE dns.mod_mx_alias () ;
CREATE TRIGGER tr_mod_name CREATE TRIGGER tr_mod_name
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment