[open-ils-commits] r12870 - trunk/Open-ILS/src/sql/Pg (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Apr 14 20:47:07 EDT 2009
Author: miker
Date: 2009-04-14 20:47:06 -0400 (Tue, 14 Apr 2009)
New Revision: 12870
Modified:
trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql
trunk/Open-ILS/src/sql/Pg/090.schema.action.sql
Log:
teaching record merge function how to copy over 856 tags when there is a MARC-mapped URI entry
Modified: trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql 2009-04-14 16:35:35 UTC (rev 12869)
+++ trunk/Open-ILS/src/sql/Pg/040.schema.asset.sql 2009-04-15 00:47:06 UTC (rev 12870)
@@ -166,6 +166,7 @@
call_number INT NOT NULL REFERENCES asset.call_number (id),
CONSTRAINT uri_cn_once UNIQUE (uri,call_number)
);
+CREATE INDEX asset_uri_call_number_map_cn_idx ON asset.uri_call_number_map (call_number);
CREATE TABLE asset.call_number_note (
id BIGSERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/090.schema.action.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/090.schema.action.sql 2009-04-14 16:35:35 UTC (rev 12869)
+++ trunk/Open-ILS/src/sql/Pg/090.schema.action.sql 2009-04-15 00:47:06 UTC (rev 12870)
@@ -356,7 +356,63 @@
target_cn asset.call_number%ROWTYPE;
metarec metabib.metarecord%ROWTYPE;
hold action.hold_request%ROWTYPE;
+ uri_count INT := 0;
+ counter INT := 0;
+ uri_datafield TEXT;
+ uri_text TEXT := '';
BEGIN
+
+ -- move any 856 entries on records that have at least one MARC-mapped URI entry
+ SELECT INTO uri_count COUNT(*)
+ FROM asset.uri_call_number_map m
+ JOIN asset.call_number cn ON (m.call_number = cn.id)
+ WHERE cn.record = source_record;
+
+ IF uri_count > 0 THEN
+
+ SELECT COUNT(*) INTO counter
+ FROM xpath_table(
+ 'id',
+ 'marc',
+ 'acq.lineitem',
+ '//*[@tag="856"]',
+ 'id=' || lineitem
+ ) as t(i int,c text);
+
+ FOR i IN 1 .. counter LOOP
+ SELECT '<datafield xmlns="http://www.loc.gov/MARC21/slim" tag="856">' ||
+ array_to_string(
+ array_accum(
+ '<subfield code="' || subfield || '">' ||
+ regexp_replace(
+ regexp_replace(
+ regexp_replace(data,'&','&','g'),
+ '>', '>', 'g'
+ ),
+ '<', '<', 'g'
+ ) || '</subfield>'
+ ), ''
+ ) || '</datafield>' INTO uri_datafield
+ FROM xpath_table(
+ 'id',
+ 'marc',
+ 'biblio.record_entry',
+ '//*[@tag="856"][position()=' || i || ']/*/@code|' ||
+ '//*[@tag="856"][position()=' || i || ']/*[@code]',
+ 'id=' || source_record
+ ) as t(id int,subfield text,data text);
+
+ uri_text := uri_text || uri_datafield;
+ END LOOP;
+
+ IF uri_text <> '' THEN
+ UPDATE biblio.record_entry
+ SET marc = regexp_replace(marc,'(</[^>]*record>)', uri_text || E'\\1')
+ WHERE id = target_record;
+ END IF;
+
+ END IF;
+
-- Find and move metarecords to the target record
SELECT INTO metarec *
FROM metabib.metarecord
More information about the open-ils-commits
mailing list