partial backport of r18957 to capture the fixes for vandelay.replace_field -- specifi...
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 10 Dec 2010 14:33:42 +0000 (14:33 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 10 Dec 2010 14:33:42 +0000 (14:33 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6@18961 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Pg/012.schema.vandelay.sql
Open-ILS/src/sql/Pg/upgrade/0469.schema.authority-maint-trigger-funcs.sql [new file with mode: 0644]

index b742e3d..93fe5df 100644 (file)
@@ -268,10 +268,12 @@ $_$ LANGUAGE SQL;
 CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
 DECLARE
     xml_output TEXT;
+    parsed_target TEXT;
 BEGIN
-    xml_output := vandelay.strip_field( target_xml, field);
+    parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalized the format of the xml for the IF below
+    xml_output := vandelay.strip_field( parsed_target, field);
 
-    IF xml_output <> target_xml  AND field ~ E'~' THEN
+    IF xml_output <> parsed_target  AND field ~ E'~' THEN
         -- we removed something, and there was a regexp restriction in the field definition, so proceed
         xml_output := vandelay.add_field( xml_output, source_xml, field, 1 );
     ELSIF field !~ E'~' THEN
diff --git a/Open-ILS/src/sql/Pg/upgrade/0469.schema.authority-maint-trigger-funcs.sql b/Open-ILS/src/sql/Pg/upgrade/0469.schema.authority-maint-trigger-funcs.sql
new file mode 100644 (file)
index 0000000..c02e399
--- /dev/null
@@ -0,0 +1,26 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0469'); -- miker
+
+CREATE OR REPLACE FUNCTION vandelay.replace_field ( target_xml TEXT, source_xml TEXT, field TEXT ) RETURNS TEXT AS $_$
+DECLARE
+    xml_output TEXT;
+    parsed_target TEXT;
+BEGIN
+    parsed_target := vandelay.strip_field( target_xml, ''); -- this dance normalized the format of the xml for the IF below
+    xml_output := vandelay.strip_field( parsed_target, field);
+
+    IF xml_output <> parsed_target  AND field ~ E'~' THEN
+        -- we removed something, and there was a regexp restriction in the field definition, so proceed
+        xml_output := vandelay.add_field( xml_output, source_xml, field, 1 );
+    ELSIF field !~ E'~' THEN
+        -- No regexp restriction, add the field
+        xml_output := vandelay.add_field( xml_output, source_xml, field, 0 );
+    END IF;
+
+    RETURN xml_output;
+END;
+$_$ LANGUAGE PLPGSQL;
+
+COMMIT;
+