From e9455e8d55ca1233db40349999b422944bb7d7d8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sun, 5 May 2019 12:41:46 -0500 Subject: [PATCH] Bug 22571: Handle control fields in MMT for conditionals Control fields are not handled correctly by Koha::SimpleMARC when comparaison (with or without regex) is done. Which means we did not support something like: Do something if control field 008 equals or matches "a string" Test plan: Create a new MARC modification template and a new action, like: Add new field 100$a with value "foo bar" if 008 (or any other control fields) matches (or equals) a regex Then use the record mofication tool and confirm that the new field is create if the regex matches 008 of the bib record Signed-off-by: Mark Tompsett Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize (cherry picked from commit c59586aebe1d8eab56d3cd32b5156fc1a61f11ec) Signed-off-by: Fridolin Somers --- Koha/SimpleMARC.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm index de76cd313e..5a916bdb03 100644 --- a/Koha/SimpleMARC.pm +++ b/Koha/SimpleMARC.pm @@ -415,9 +415,15 @@ sub field_equals { my @field_numbers = (); my $current_field_number = 1; FIELDS: for my $field ( $record->field( $fieldName ) ) { - my @subfield_values = $subfieldName - ? $field->subfield( $subfieldName ) - : map { $_->[1] } $field->subfields; + my @subfield_values; + if ( $field->is_control_field ) { + push @subfield_values, $field->data; + } else { + @subfield_values = + $subfieldName + ? $field->subfield($subfieldName) + : map { $_->[1] } $field->subfields; + } SUBFIELDS: for my $subfield_value ( @subfield_values ) { if ( -- 2.39.5