JBAS-1470 Support multiple target field replacements
authorBill Erickson <berickxx@gmail.com>
Tue, 2 Jan 2018 22:45:43 +0000 (17:45 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Allow a single (e.g. authority) record field to act as the basis for
replacing multiple like values on a target bib record.

E.g. replace multiple bib 700a values from a single authority 100a
value.

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

index 06ab428..8fe051c 100644 (file)
@@ -265,8 +265,17 @@ 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.
-            my $source_field = ($source_r->field($f))[++$tag_idx];
+            # 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?
+            my @source_fields = $source_r->field($f);
+            my $source_field = $source_fields[++$tag_idx] 
+                || $source_fields[$#source_fields];
 
             if (!$source_field) {
                 # No source field exists.  Delete all affected target