Bug 18467: Handle orders with deleted biblio when viewing a basket
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 21 Apr 2017 16:05:47 +0000 (13:05 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 28 Apr 2017 10:44:05 +0000 (06:44 -0400)
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 <alexbuckley@catalyst.net.nz>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
acqui/basket.pl

index e556be2..55aca4c 100755 (executable)
@@ -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});