[open-ils-commits] r11059 - branches/rel_1_4/Open-ILS/src/sql/Pg
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Nov 4 14:47:21 EST 2008
Author: miker
Date: 2008-11-04 14:47:17 -0500 (Tue, 04 Nov 2008)
New Revision: 11059
Modified:
branches/rel_1_4/Open-ILS/src/sql/Pg/040.schema.asset.sql
Log:
backporting: update record merging stored proc to move holds and metarecords, and count all moved objects
Modified: branches/rel_1_4/Open-ILS/src/sql/Pg/040.schema.asset.sql
===================================================================
--- branches/rel_1_4/Open-ILS/src/sql/Pg/040.schema.asset.sql 2008-11-04 19:11:06 UTC (rev 11058)
+++ branches/rel_1_4/Open-ILS/src/sql/Pg/040.schema.asset.sql 2008-11-04 19:47:17 UTC (rev 11059)
@@ -190,10 +190,27 @@
CREATE OR REPLACE FUNCTION asset.merge_record_assets( target_record BIGINT, source_record BIGINT ) RETURNS INT AS $func$
DECLARE
- moved_cns INT := 0;
- source_cn asset.call_number%ROWTYPE;
- target_cn asset.call_number%ROWTYPE;
+ moved_objects INT := 0;
+ source_cn asset.call_number%ROWTYPE;
+ target_cn asset.call_number%ROWTYPE;
+ metarec metabib.metarecord%ROWTYPE;
+ hold action.hold_request%ROWTYPE;
BEGIN
+ -- Find and move metarecords to the target record
+ SELECT INTO metarec *
+ FROM metabib.metarecord
+ WHERE master_record = source_record;
+
+ IF FOUND THEN
+ UPDATE metabib.metarecord
+ SET master_record = target_record,
+ mods = NULL
+ WHERE id = metarec.id;
+
+ moved_objects := moved_objects + 1;
+ END IF;
+
+ -- Find call numbers attached to the source ...
FOR source_cn IN SELECT * FROM asset.call_number WHERE record = source_record LOOP
SELECT INTO target_cn *
@@ -202,20 +219,48 @@
AND owning_lib = source_cn.owning_lib
AND record = target_record;
+ -- ... and if there's a conflicting one on the target ...
IF FOUND THEN
+
+ -- ... move the copies to that, and ...
UPDATE asset.copy
SET call_number = target_cn.id
WHERE call_number = source_cn.id;
+
+ -- ... move V holds to the move-target call number
+ FOR hold IN SELECT * FROM action.hold_request WHERE target = source_cn.id AND hold_type = 'V' LOOP
+
+ UPDATE action.hold_request
+ SET target = target_cn.id
+ WHERE id = hold.id;
+
+ moved_objects := moved_objects + 1;
+ END LOOP;
+
+ -- ... if not ...
ELSE
+ -- ... just move the call number to the target record
UPDATE asset.call_number
SET record = target_record
WHERE id = source_cn.id;
END IF;
- moved_cns := moved_cns + 1;
+ moved_objects := moved_objects + 1;
END LOOP;
- RETURN moved_cns;
+ -- Find T holds targeting the source record ...
+ FOR hold IN SELECT * FROM action.hold_request WHERE target = source_record AND hold_type = 'T' LOOP
+
+ -- ... and move them to the target record
+ UPDATE action.hold_request
+ SET target = target_record
+ WHERE id = hold.id;
+
+ moved_objects := moved_objects + 1;
+ END LOOP;
+
+ -- That's all, folks!
+ RETURN moved_objects;
END;
$func$ LANGUAGE plpgsql;
More information about the open-ils-commits
mailing list