From 9c81053a6aa3982025f737850dcc595a7f598ad5 Mon Sep 17 00:00:00 2001 From: dbs Date: Tue, 13 Jul 2010 19:03:41 +0000 Subject: [PATCH] Make maintain_901() more robust in the presence of namespaces Some records manage to get XML namespace declarations into each element, like ', '', 'g'); + -- Remove any existing 901 fields before we insert the authoritative one + NEW.marc := REGEXP_REPLACE(NEW.marc, E']*?\s*tag="901".+?', '', 'g'); IF TG_TABLE_SCHEMA = 'biblio' THEN NEW.marc := REGEXP_REPLACE( NEW.marc, diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index ccdfc8065a..ecf1979470 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -68,7 +68,7 @@ CREATE TABLE config.upgrade_log ( 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, diff --git a/Open-ILS/src/sql/Pg/upgrade/0335.schema.maintain_901_xmlns.sql b/Open-ILS/src/sql/Pg/upgrade/0335.schema.maintain_901_xmlns.sql new file mode 100644 index 0000000000..0fa4fd679d --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0335.schema.maintain_901_xmlns.sql @@ -0,0 +1,63 @@ +BEGIN; + +-- Some records manage to get XML namespace declarations into each element, +-- like ]*?\s*tag="901".+?', '', 'g'); + IF TG_TABLE_SCHEMA = 'biblio' THEN + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || NEW.tcn_value || E'' || + '' || NEW.tcn_source || E'' || + '' || NEW.id || E'' || + '' || TG_TABLE_SCHEMA || E'' || + CASE WHEN NEW.owner IS NOT NULL THEN '' || NEW.owner || E'' ELSE '' END || + CASE WHEN NEW.share_depth IS NOT NULL THEN '' || NEW.share_depth || E'' ELSE '' END || + E'\\1' + ); + ELSIF TG_TABLE_SCHEMA = 'authority' THEN + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || NEW.arn_value || E'' || + '' || NEW.arn_source || E'' || + '' || NEW.id || E'' || + '' || TG_TABLE_SCHEMA || E'' || + E'\\1' + ); + ELSIF TG_TABLE_SCHEMA = 'serial' THEN + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || NEW.id || E'' || + '' || TG_TABLE_SCHEMA || E'' || + '' || NEW.owning_lib || E'' || + CASE WHEN NEW.record IS NOT NULL THEN '' || NEW.record || E'' ELSE '' END || + E'\\1' + ); + ELSE + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || NEW.id || E'' || + '' || TG_TABLE_SCHEMA || E'' || + E'\\1' + ); + END IF; + + RETURN NEW; +END; +$func$ LANGUAGE PLPGSQL; + +COMMIT; -- 2.11.0