From fd7a612c6ed4dc85049fa2ef6a786d2657501d74 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Thu, 23 Sep 2021 13:40:48 -0400 Subject: [PATCH] Bug 29100: Remove unnecessary loops Remove loops that only operate one one result only Signed-off-by: Felicity Brown Signed-off-by: George Veranis Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- misc/cronjobs/advance_notices.pl | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/misc/cronjobs/advance_notices.pl b/misc/cronjobs/advance_notices.pl index 4ea14ed07f..e964873e0c 100755 --- a/misc/cronjobs/advance_notices.pl +++ b/misc/cronjobs/advance_notices.pl @@ -293,12 +293,8 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { my $item = Koha::Items->find( $upcoming->{itemnumber} ); my $letter_type = 'DUE'; $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},'0'); - my $titles = ""; - my @issues; - while ( my $item_info = $sth->fetchrow_hashref()) { - push( @issues, $item_info ); - $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } ); - } + my $item_info = $sth->fetchrow_hashref(); + my $title = C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } ); ## Get branch info for borrowers home library. foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) { @@ -309,8 +305,8 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { biblionumber => $item->biblionumber, itemnumber => $upcoming->{'itemnumber'}, substitute => { - 'items.content' => $titles, - issue => $issues[0], + 'items.content' => $title, + issue => $item_info, }, message_transport_type => $transport, } ) @@ -346,12 +342,8 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { my $item = Koha::Items->find( $upcoming->{itemnumber} ); my $letter_type = 'PREDUE'; $sth->execute($upcoming->{'borrowernumber'},$upcoming->{'itemnumber'},$borrower_preferences->{'days_in_advance'}); - my $titles = ""; - my @issues; - while ( my $item_info = $sth->fetchrow_hashref()) { - push( @issues, $item_info ); - $titles .= C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } ); - } + my $item_info = $sth->fetchrow_hashref(); + my $title = C4::Letters::get_item_content( { item => $item_info, item_content_fields => \@item_content_fields } ); ## Get branch info for borrowers home library. foreach my $transport ( keys %{$borrower_preferences->{'transports'}} ) { @@ -362,8 +354,8 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { biblionumber => $item->biblionumber, itemnumber => $upcoming->{'itemnumber'}, substitute => { - 'items.content' => $titles, - issue => $issues[0], + 'items.content' => $title, + issue => $item_info, }, message_transport_type => $transport, } ) -- 2.39.5