Fix a data destruction bug when authorities are updated. user/dyrcona/lp1081641
authorJason Stephenson <jstephenson@mvlc.org>
Thu, 3 Jan 2013 18:27:27 +0000 (13:27 -0500)
committerJason Stephenson <jstephenson@mvlc.org>
Thu, 3 Jan 2013 18:27:27 +0000 (13:27 -0500)
Modify the two-argument form of vandelay.merge_record_xml to return
the target_marc when the add_rule, preserve_rule, replace_rule are
all empty.

This method is used by authority.propagate_changes and would replace
the bibliographic record's marc with the overlay template when the
above would happen. By returning the biblographic record entry's own
marc in that case, we prevent data destruction.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/sql/Pg/012.schema.vandelay.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.function.vandelay_merge_record_xml_bib_destruction_fix.sql [new file with mode: 0644]

index 8f9ad96..722cdae 100644 (file)
@@ -1314,7 +1314,10 @@ BEGIN
         RETURN NULL;
     END IF;
 
-    IF dyn_profile.replace_rule <> '' THEN
+    IF dyn_profile.replace_rule = '' AND dyn_profile.preserve_rule = '' AND dyn_profile.add_rule = '' THEN
+        --Since we have nothing to do, just return what we were given.
+        RETURN target_marc;
+    ELSIF dyn_profile.replace_rule <> '' THEN
         trgt_marc = target_marc;
         tmpl_marc = template_marc;
         replace_rule = dyn_profile.replace_rule;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.vandelay_merge_record_xml_bib_destruction_fix.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.vandelay_merge_record_xml_bib_destruction_fix.sql
new file mode 100644 (file)
index 0000000..0e79988
--- /dev/null
@@ -0,0 +1,51 @@
+-- Change the two argument form of vandelay.merge_record_xml to
+-- prevent bibliographic record destruction when there is nothing to
+-- do.
+
+BEGIN;
+
+-- Check whether patch can be applied.
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION vandelay.merge_record_xml ( target_marc TEXT, template_marc TEXT ) RETURNS TEXT AS $$
+DECLARE
+    dyn_profile     vandelay.compile_profile%ROWTYPE;
+    replace_rule    TEXT;
+    tmp_marc        TEXT;
+    trgt_marc        TEXT;
+    tmpl_marc        TEXT;
+    match_count     INT;
+BEGIN
+
+    IF target_marc IS NULL OR template_marc IS NULL THEN
+        -- RAISE NOTICE 'no marc for target or template record';
+        RETURN NULL;
+    END IF;
+
+    dyn_profile := vandelay.compile_profile( template_marc );
+
+    IF dyn_profile.replace_rule <> '' AND dyn_profile.preserve_rule <> '' THEN
+        -- RAISE NOTICE 'both replace [%] and preserve [%] specified', dyn_profile.replace_rule, dyn_profile.preserve_rule;
+        RETURN NULL;
+    END IF;
+
+    IF dyn_profile.replace_rule = '' AND dyn_profile.preserve_rule = '' AND dyn_profile.add_rule = '' THEN
+        --Since we have nothing to do, just return what we were given.
+        RETURN target_marc;
+    ELSIF dyn_profile.replace_rule <> '' THEN
+        trgt_marc = target_marc;
+        tmpl_marc = template_marc;
+        replace_rule = dyn_profile.replace_rule;
+    ELSE
+        tmp_marc = target_marc;
+        trgt_marc = template_marc;
+        tmpl_marc = tmp_marc;
+        replace_rule = dyn_profile.preserve_rule;
+    END IF;
+
+    RETURN vandelay.merge_record_xml( trgt_marc, tmpl_marc, dyn_profile.add_rule, replace_rule, dyn_profile.strip_rule );
+
+END;
+$$ LANGUAGE PLPGSQL;
+
+COMMIT;