[open-ils-commits] r11854 - trunk/Open-ILS/src/sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Jan 15 16:46:44 EST 2009
Author: erickson
Date: 2009-01-15 16:46:40 -0500 (Thu, 15 Jan 2009)
New Revision: 11854
Modified:
trunk/Open-ILS/src/sql/Pg/999.functions.global.sql
Log:
provide option to delete addresses and cards as well as deactive merged cards
Modified: trunk/Open-ILS/src/sql/Pg/999.functions.global.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/999.functions.global.sql 2009-01-15 21:01:38 UTC (rev 11853)
+++ trunk/Open-ILS/src/sql/Pg/999.functions.global.sql 2009-01-15 21:46:40 UTC (rev 11854)
@@ -44,15 +44,34 @@
$$;
-CREATE OR REPLACE FUNCTION actor.usr_merge( src_usr INT, dest_usr INT ) RETURNS VOID AS $$
+CREATE OR REPLACE FUNCTION actor.usr_merge( src_usr INT, dest_usr INT, del_addrs BOOLEAN, del_cards BOOLEAN, deactivate_cards BOOLEAN ) RETURNS VOID AS $$
BEGIN
+ -- do some initial cleanup
+ UPDATE actor.usr SET card = NULL WHERE id = src_usr;
+ UPDATE actor.usr SET mailing_address = NULL WHERE id = src_usr;
+ UPDATE actor.usr SET billing_address = NULL WHERE id = src_usr;
+
-- actor.*
- UPDATE actor.card SET usr = dest_usr WHERE usr = src_usr;
+ IF del_cards THEN
+ DELETE FROM actor.card where usr = src_usr;
+ ELSE
+ IF deactivate_cards THEN
+ UPDATE actor.card SET active = 'f' WHERE usr = src_usr;
+ END IF;
+ UPDATE actor.card SET usr = dest_usr WHERE usr = src_usr;
+ END IF;
+
+
+ IF del_addrs THEN
+ DELETE FROM actor.usr_address WHERE usr = src_usr;
+ ELSE
+ UPDATE actor.usr_address SET usr = dest_usr WHERE usr = src_usr;
+ END IF;
+
UPDATE actor.usr_note SET usr = dest_usr WHERE usr = src_usr;
-- dupes are technically OK in actor.usr_standing_penalty, should manually delete them...
UPDATE actor.usr_standing_penalty SET usr = dest_usr WHERE usr = src_usr;
- UPDATE actor.usr_address SET usr = dest_usr WHERE usr = src_usr;
PERFORM actor.usr_merge_rows('actor.usr_org_unit_opt_in', 'usr', src_usr, dest_usr);
PERFORM actor.usr_merge_rows('actor.usr_setting', 'usr', src_usr, dest_usr);
@@ -149,10 +168,7 @@
-- do nothing
END;
- -- Finally, clean and delete the source user
- UPDATE actor.usr SET card = NULL WHERE id = src_usr;
- UPDATE actor.usr SET mailing_address = NULL WHERE id = src_usr;
- UPDATE actor.usr SET billing_address = NULL WHERE id = src_usr;
+ -- Finally, delete the source user
DELETE FROM actor.usr WHERE id = src_usr;
END;
More information about the open-ils-commits
mailing list