JBAS-1470 Multi target replaces only subfields
authorBill Erickson <berickxx@gmail.com>
Wed, 3 Jan 2018 16:22:13 +0000 (11:22 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
When performing wholesale replacement of a bib field, only replace as
many target fields as exist on the source record.  I.e. avoid
propagating and repating the same whole field multiple times into the
target record.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/sql/schema/deploy/auth-prop-partial-matches.sql

index 8fe051c..3bf6c67 100644 (file)
@@ -265,17 +265,18 @@ CREATE OR REPLACE FUNCTION vandelay.replace_field
             # If the target record has multiple matching bib fields,
             # replace them from matching fields on the source record
             # in a predictable order to avoid replacing with them with
-            # same source field repeatedly.  However, if there are more
-            # target fields than source fields, use the last available
-            # source field as the input for all remaining target fields.
-            # TODO: there may be cases where we do not want a single 
-            # source field to affect multiple target fields.  It works 
-            # well when replacing multiple bib 700a values with a single 
-            # 100a authority record value, but maybe not when overlaying
-            # one bib record onto another.  Should this be flag/setting?
+            # same source field repeatedly.
             my @source_fields = $source_r->field($f);
-            my $source_field = $source_fields[++$tag_idx] 
-                || $source_fields[$#source_fields];
+            my $source_field = $source_fields[++$tag_idx];
+
+            if (!$source_field && @controlled_subfields) {
+                # When there are more target fields than source fields
+                # and we are replacing values for subfields and not
+                # performing wholesale field replacment, use the last
+                # available source field as the input for all remaining
+                # target fields.
+                $source_field = $source_fields[$#source_fields];
+            }
 
             if (!$source_field) {
                 # No source field exists.  Delete all affected target