[open-ils-commits] r16919 - in trunk/Open-ILS/src/sql/Pg: . upgrade (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Jul 13 15:03:46 EDT 2010
Author: dbs
Date: 2010-07-13 15:03:41 -0400 (Tue, 13 Jul 2010)
New Revision: 16919
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0335.schema.maintain_901_xmlns.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.functions.config.sql
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
Make maintain_901() more robust in the presence of namespaces
Some records manage to get XML namespace declarations into each element,
like <datafield xmlns:marc="http://www.loc.gov/MARC21/slim"
This broke the old maintain_901(), so we'll make the regex more robust
Modified: trunk/Open-ILS/src/sql/Pg/002.functions.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.functions.config.sql 2010-07-13 15:56:33 UTC (rev 16918)
+++ trunk/Open-ILS/src/sql/Pg/002.functions.config.sql 2010-07-13 19:03:41 UTC (rev 16919)
@@ -417,7 +417,8 @@
CREATE OR REPLACE FUNCTION maintain_901 () RETURNS TRIGGER AS $func$
BEGIN
- NEW.marc := REGEXP_REPLACE(NEW.marc, E'<datafield tag="901".+?</datafield>', '', 'g');
+ -- Remove any existing 901 fields before we insert the authoritative one
+ NEW.marc := REGEXP_REPLACE(NEW.marc, E'<datafield\s*[^<>]*?\s*tag="901".+?</datafield>', '', 'g');
IF TG_TABLE_SCHEMA = 'biblio' THEN
NEW.marc := REGEXP_REPLACE(
NEW.marc,
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-07-13 15:56:33 UTC (rev 16918)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-07-13 19:03:41 UTC (rev 16919)
@@ -68,7 +68,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0334'); -- Scott McKellar
+INSERT INTO config.upgrade_log (version) VALUES ('0335'); -- dbs
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0335.schema.maintain_901_xmlns.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0335.schema.maintain_901_xmlns.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0335.schema.maintain_901_xmlns.sql 2010-07-13 19:03:41 UTC (rev 16919)
@@ -0,0 +1,63 @@
+BEGIN;
+
+-- Some records manage to get XML namespace declarations into each element,
+-- like <datafield xmlns:marc="http://www.loc.gov/MARC21/slim"
+-- This broke the old maintain_901(), so we'll make the regex more robust
+
+INSERT INTO config.upgrade_log (version) VALUES ('0335'); -- dbs
+
+CREATE OR REPLACE FUNCTION maintain_901 () RETURNS TRIGGER AS $func$
+BEGIN
+ -- Remove any existing 901 fields before we insert the authoritative one
+ NEW.marc := REGEXP_REPLACE(NEW.marc, E'<datafield\s*[^<>]*?\s*tag="901".+?</datafield>', '', 'g');
+ IF TG_TABLE_SCHEMA = 'biblio' THEN
+ NEW.marc := REGEXP_REPLACE(
+ NEW.marc,
+ E'(</(?:[^:]*?:)?record>)',
+ E'<datafield tag="901" ind1=" " ind2=" ">' ||
+ '<subfield code="a">' || NEW.tcn_value || E'</subfield>' ||
+ '<subfield code="b">' || NEW.tcn_source || E'</subfield>' ||
+ '<subfield code="c">' || NEW.id || E'</subfield>' ||
+ '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
+ CASE WHEN NEW.owner IS NOT NULL THEN '<subfield code="o">' || NEW.owner || E'</subfield>' ELSE '' END ||
+ CASE WHEN NEW.share_depth IS NOT NULL THEN '<subfield code="d">' || NEW.share_depth || E'</subfield>' ELSE '' END ||
+ E'</datafield>\\1'
+ );
+ ELSIF TG_TABLE_SCHEMA = 'authority' THEN
+ NEW.marc := REGEXP_REPLACE(
+ NEW.marc,
+ E'(</(?:[^:]*?:)?record>)',
+ E'<datafield tag="901" ind1=" " ind2=" ">' ||
+ '<subfield code="a">' || NEW.arn_value || E'</subfield>' ||
+ '<subfield code="b">' || NEW.arn_source || E'</subfield>' ||
+ '<subfield code="c">' || NEW.id || E'</subfield>' ||
+ '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
+ E'</datafield>\\1'
+ );
+ ELSIF TG_TABLE_SCHEMA = 'serial' THEN
+ NEW.marc := REGEXP_REPLACE(
+ NEW.marc,
+ E'(</(?:[^:]*?:)?record>)',
+ E'<datafield tag="901" ind1=" " ind2=" ">' ||
+ '<subfield code="c">' || NEW.id || E'</subfield>' ||
+ '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
+ '<subfield code="o">' || NEW.owning_lib || E'</subfield>' ||
+ CASE WHEN NEW.record IS NOT NULL THEN '<subfield code="r">' || NEW.record || E'</subfield>' ELSE '' END ||
+ E'</datafield>\\1'
+ );
+ ELSE
+ NEW.marc := REGEXP_REPLACE(
+ NEW.marc,
+ E'(</(?:[^:]*?:)?record>)',
+ E'<datafield tag="901" ind1=" " ind2=" ">' ||
+ '<subfield code="c">' || NEW.id || E'</subfield>' ||
+ '<subfield code="t">' || TG_TABLE_SCHEMA || E'</subfield>' ||
+ E'</datafield>\\1'
+ );
+ END IF;
+
+ RETURN NEW;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
More information about the open-ils-commits
mailing list