From: Jason Etheridge Date: Tue, 12 Jul 2011 21:55:54 +0000 (-0400) Subject: pin an upgrade version for fix_maintain_901_quoting X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7ea9abada5fa1e2e013e35dd50665b76bba9a065;p=evergreen%2Fmasslnc.git pin an upgrade version for fix_maintain_901_quoting Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 96277dbb4e..10038a95fc 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -86,7 +86,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0575', :eg_version); -- miker/senator +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0576', :eg_version); -- phasefx/gmcharlt CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/upgrade/0576.fix_maintain_901_quoting.sql b/Open-ILS/src/sql/Pg/upgrade/0576.fix_maintain_901_quoting.sql new file mode 100644 index 0000000000..7e8e87fc8b --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0576.fix_maintain_901_quoting.sql @@ -0,0 +1,74 @@ +-- Evergreen DB patch 0576.fix_maintain_901_quoting.sql +-- +-- Fix for bug LP#809540 - fixes crash when inserting or updating +-- bib whose tcn_value contains regex metacharacters. +-- +BEGIN; + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('0576', :eg_version); + +CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$ +DECLARE + use_id_for_tcn BOOLEAN; +BEGIN + -- Remove any existing 901 fields before we insert the authoritative one + NEW.marc := REGEXP_REPLACE(NEW.marc, E']*?tag="901".+?', '', 'g'); + + IF TG_TABLE_SCHEMA = 'biblio' THEN + -- Set TCN value to record ID? + SELECT enabled FROM config.global_flag INTO use_id_for_tcn + WHERE name = 'cat.bib.use_id_for_tcn'; + + IF use_id_for_tcn = 't' THEN + NEW.tcn_value := NEW.id; + END IF; + + NEW.marc := REGEXP_REPLACE( + NEW.marc, + E'()', + E'' || + '' || REPLACE(evergreen.xml_escape(NEW.tcn_value), E'\\', E'\\\\') || E'' || + '' || REPLACE(evergreen.xml_escape(NEW.tcn_source), E'\\', E'\\\\') || 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.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; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.fix_maintain_901_quoting.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.fix_maintain_901_quoting.sql deleted file mode 100644 index c59e2f176f..0000000000 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.fix_maintain_901_quoting.sql +++ /dev/null @@ -1,74 +0,0 @@ --- Evergreen DB patch XXXX.fix_maintain_901_quoting.sql --- --- Fix for bug LP#809540 - fixes crash when inserting or updating --- bib whose tcn_value contains regex metacharacters. --- -BEGIN; - --- check whether patch can be applied -SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); - -CREATE OR REPLACE FUNCTION evergreen.maintain_901 () RETURNS TRIGGER AS $func$ -DECLARE - use_id_for_tcn BOOLEAN; -BEGIN - -- Remove any existing 901 fields before we insert the authoritative one - NEW.marc := REGEXP_REPLACE(NEW.marc, E']*?tag="901".+?', '', 'g'); - - IF TG_TABLE_SCHEMA = 'biblio' THEN - -- Set TCN value to record ID? - SELECT enabled FROM config.global_flag INTO use_id_for_tcn - WHERE name = 'cat.bib.use_id_for_tcn'; - - IF use_id_for_tcn = 't' THEN - NEW.tcn_value := NEW.id; - END IF; - - NEW.marc := REGEXP_REPLACE( - NEW.marc, - E'()', - E'' || - '' || REPLACE(evergreen.xml_escape(NEW.tcn_value), E'\\', E'\\\\') || E'' || - '' || REPLACE(evergreen.xml_escape(NEW.tcn_source), E'\\', E'\\\\') || 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.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;