From: Jason Stephenson Date: Fri, 11 Jan 2013 14:22:05 +0000 (-0500) Subject: Fix a data destruction bug when authorities are updated. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8ba0246be6a072e8644eb81f4717ff46ded0aa41;p=working%2FEvergreen.git Fix a data destruction bug when authorities are updated. 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 --- diff --git a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql index 8f9ad968b2..722cdae615 100644 --- a/Open-ILS/src/sql/Pg/012.schema.vandelay.sql +++ b/Open-ILS/src/sql/Pg/012.schema.vandelay.sql @@ -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.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.vandelay.merge_record_xml.sql new file mode 100644 index 0000000000..0e7998878c --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.vandelay.merge_record_xml.sql @@ -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;