From b582f7d495fceda68a7972f7eab0d4e5d16bdcdf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 17 Oct 2022 16:00:25 +0200 Subject: [PATCH] Bug 31154: Avoid unecessary loop We don't need to loop over the subfield and enter this block if there is no record. Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- Koha/UI/Form/Builder/Item.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm index 568a00e401..3a478ee05e 100644 --- a/Koha/UI/Form/Builder/Item.pm +++ b/Koha/UI/Form/Builder/Item.pm @@ -152,7 +152,8 @@ sub generate_subfield_form { && !$value && $subfield->{kohafield} && $subfield->{kohafield} eq 'items.itemcallnumber' - && $pref_itemcallnumber ) + && $pref_itemcallnumber + && $marc_record ) { foreach my $pref_itemcallnumber_part ( split( /,/, $pref_itemcallnumber ) ) @@ -162,7 +163,7 @@ sub generate_subfield_form { my $CNsubfields = substr( $pref_itemcallnumber_part, 3 ); # Any and all subfields $CNsubfields = undef if $CNsubfields eq ''; - my $temp2 = $marc_record ? $marc_record->field($CNtag) : undef; + my $temp2 = $marc_record->field($CNtag); next unless $temp2; $value = $temp2->as_string( $CNsubfields, ' ' ); -- 2.39.5