pin an upgrade version for fix_maintain_901_quoting
authorJason Etheridge <jason@esilibrary.com>
Tue, 12 Jul 2011 21:55:54 +0000 (17:55 -0400)
committerJason Etheridge <jason@esilibrary.com>
Tue, 12 Jul 2011 21:58:56 +0000 (17:58 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/sql/Pg/002.schema.config.sql
Open-ILS/src/sql/Pg/upgrade/0576.fix_maintain_901_quoting.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.fix_maintain_901_quoting.sql [deleted file]

index 96277db..10038a9 100644 (file)
@@ -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 (file)
index 0000000..7e8e87f
--- /dev/null
@@ -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'<datafield[^>]*?tag="901".+?</datafield>', '', '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'(</(?:[^:]*?:)?record>)',
+            E'<datafield tag="901" ind1=" " ind2=" ">' ||
+                '<subfield code="a">' || REPLACE(evergreen.xml_escape(NEW.tcn_value), E'\\', E'\\\\') || E'</subfield>' ||
+                '<subfield code="b">' || REPLACE(evergreen.xml_escape(NEW.tcn_source), E'\\', E'\\\\') || 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="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;
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 (file)
index c59e2f1..0000000
+++ /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'<datafield[^>]*?tag="901".+?</datafield>', '', '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'(</(?:[^:]*?:)?record>)',
-            E'<datafield tag="901" ind1=" " ind2=" ">' ||
-                '<subfield code="a">' || REPLACE(evergreen.xml_escape(NEW.tcn_value), E'\\', E'\\\\') || E'</subfield>' ||
-                '<subfield code="b">' || REPLACE(evergreen.xml_escape(NEW.tcn_source), E'\\', E'\\\\') || 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="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;