From: Bill Erickson Date: Thu, 8 Mar 2012 18:13:25 +0000 (-0500) Subject: User activity : only delete transient activity for user/type X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=cd0a6898069afafcf49a7bc59e60dc4927213efd;p=evergreen%2Fmasslnc.git User activity : only delete transient activity for user/type Repairs a bug spotted by Thomas Berezansky where the addition of a new activity for a transient type would delete all existing activity entries. Signed-off-by: Bill Erickson Signed-off-by: Thomas Berezansky --- diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 69d9cbe6f1..c1df4afede 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -2097,8 +2097,11 @@ $F$ LANGUAGE SQL; -- remove transient activity entries on insert of new entries CREATE OR REPLACE FUNCTION actor.usr_activity_transient_trg () RETURNS TRIGGER AS $$ BEGIN - DELETE FROM actor.usr_activity USING config.usr_activity_type atype - WHERE atype.transient AND NEW.etype = atype.id; + DELETE FROM actor.usr_activity act USING config.usr_activity_type atype + WHERE atype.transient AND + NEW.etype = atype.id AND + act.etype = atype.id AND + act.usr = NEW.usr; RETURN NEW; END; $$ LANGUAGE PLPGSQL; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql index de8cc5eb7d..576fe7f87d 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.user-activity.sql @@ -34,8 +34,11 @@ CREATE TABLE actor.usr_activity ( -- remove transient activity entries on insert of new entries CREATE OR REPLACE FUNCTION actor.usr_activity_transient_trg () RETURNS TRIGGER AS $$ BEGIN - DELETE FROM actor.usr_activity USING config.usr_activity_type atype - WHERE atype.transient AND NEW.etype = atype.id; + DELETE FROM actor.usr_activity act USING config.usr_activity_type atype + WHERE atype.transient AND + NEW.etype = atype.id AND + act.etype = atype.id AND + act.usr = NEW.usr; RETURN NEW; END; $$ LANGUAGE PLPGSQL;