From 057afcfa8791a949d1371d722d85300c92b1cc74 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 19 Mar 2020 04:37:34 +0000 Subject: [PATCH] Bug 24900: Some fixes to how MARC modification template actions work CASE 1: Delete field 020 if field 020$z exists BROKEN BEHAVIOUR (before patch): 020$z field was deleted, even though we wanted all 020 fields to be deleted EXPECTED BEHAVIOUR (corrected by patch): all 020 fields are deleted CASE 2: Delete 1st field 020 if 651$z exists BROKEN BEHAVIOUR (before patch): deletes the 2nd instance of 020 instead of 1st EXPECTED BEHAVIOUR (corrected by patch): deletes the 1st instance of 020 CASE 3: Delete 1st field 020 if 020$z exists BROKEN BEHAVIOUR (before patch): deletes the 3rd instance of 020 which contains subfield z EXPECTED BEHAVIOUR (corrected by patch): deletes the 1st instance of 020 CASE 4: Delete 1st field 020 if 651$z matches Berlin. (must include '.') BROKEN BEHAVIOUR (before patch): deletes the 2nd instance of 020 EXPECTED BEHAVIOUR (corrected by patch): deletes the 1st instance of 020 CASE 5: Delete 1st field 020 if 020$z matches 9781460708385 BROKEN BEHAVIOUR (before patch): deletes the 3rd instance of 020 which contains subfield z EXPECTED BEHAVIOUR (corrected by patch): deletes the 1st instance of 020 Sponsored-by: Catalyst IT --- C4/MarcModificationTemplates.pm | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/C4/MarcModificationTemplates.pm b/C4/MarcModificationTemplates.pm index 54846e5956..c80aa84b40 100644 --- a/C4/MarcModificationTemplates.pm +++ b/C4/MarcModificationTemplates.pm @@ -573,21 +573,9 @@ sub ModifyRecordWithTemplate { subfield => $conditional_subfield, is_regex => $conditional_regex, }); - my $all_fields = [ - 1 .. scalar @{ - field_exists( - { - record => $record, - field => $conditional_field, - subfield => $conditional_subfield - } - ) - } - ]; - $field_numbers = [Koha::MoreUtils::singleton ( @$field_numbers, @$all_fields ) ]; $do = $conditional eq 'if' - ? @$field_numbers - : not @$field_numbers; + ? not @$field_numbers + : @$field_numbers; } } @@ -600,7 +588,13 @@ sub ModifyRecordWithTemplate { if ( @$field_numbers > 0 ) { if ( $field_number == 1 ) { # We want only the first matching - $field_numbers = [ $field_numbers->[0] ]; + $field_numbers = [ 1 ]; + } else { + $field_numbers = field_exists({ + record => $record, + field => $from_field, + subfield => $from_subfield, + }); } } # There was no condition -- 2.11.0