From 21bddb399d7f88a33c6dff474d07190a09e627dc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 21 Apr 2017 13:05:47 -0300 Subject: [PATCH] Bug 18467: Handle orders with deleted biblio when viewing a basket If the bibliographic record of an order has been removed, $order->{bibionumber} is undefined. We need to handle this specific case correctly. To test: 1 - Create a basket 2 - Order a bib 3 - Cancel order and delete record 4 - You cannot view basket 5 - Apply patch 6 - View basket 7 - There should not be an error r calling count on undefined bib in basket.pl if order cancelled and record deleted Followed test plan, works as intended Signed-off-by: Alex Buckley Signed-off-by: Nick Clemens Signed-off-by: Kyle M Hall --- acqui/basket.pl | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/acqui/basket.pl b/acqui/basket.pl index e556be2e94..55aca4cf0d 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -463,27 +463,29 @@ sub get_order_infos { } my $biblionumber = $order->{'biblionumber'}; - my $biblio = Koha::Biblios->find( $biblionumber ); - my $countbiblio = CountBiblioInOrders($biblionumber); - my $ordernumber = $order->{'ordernumber'}; - my @subscriptions = GetSubscriptionsId ($biblionumber); - my $itemcount = $biblio->items->count; - my $holds_count = $biblio->holds->count; - my @items = GetItemnumbersFromOrder( $ordernumber ); - my $itemholds = $biblio ? $biblio->holds->search({ itemnumber => { -in => \@items } })->count : 0; - - # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 - $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds_count); - $line{items} = ($itemcount) - (scalar @items); - $line{left_item} = 1 if $line{items} >= 1; - $line{left_biblio} = 1 if $countbiblio > 1; - $line{biblios} = $countbiblio - 1; - $line{left_subscription} = 1 if scalar @subscriptions >= 1; - $line{subscriptions} = scalar @subscriptions; - ($holds_count >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; - $line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); - $line{holds} = $holds_count; - $line{holds_on_order} = $itemholds?$itemholds:$holds_count if $line{left_holds_on_order}; + if ( $biblionumber ) { # The biblio still exists + my $biblio = Koha::Biblios->find( $biblionumber ); + my $countbiblio = CountBiblioInOrders($biblionumber); + my $ordernumber = $order->{'ordernumber'}; + my @subscriptions = GetSubscriptionsId ($biblionumber); + my $itemcount = $biblio->items->count; + my $holds_count = $biblio->holds->count; + my @items = GetItemnumbersFromOrder( $ordernumber ); + my $itemholds = $biblio->holds->search({ itemnumber => { -in => \@items } })->count; + + # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 + $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds_count); + $line{items} = ($itemcount) - (scalar @items); + $line{left_item} = 1 if $line{items} >= 1; + $line{left_biblio} = 1 if $countbiblio > 1; + $line{biblios} = $countbiblio - 1; + $line{left_subscription} = 1 if scalar @subscriptions >= 1; + $line{subscriptions} = scalar @subscriptions; + ($holds_count >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; + $line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); + $line{holds} = $holds_count; + $line{holds_on_order} = $itemholds?$itemholds:$holds_count if $line{left_holds_on_order}; + } my $suggestion = GetSuggestionInfoFromBiblionumber($line{biblionumber}); -- 2.39.5