From 78eff9c7424f502d2e41410dff7d5673988b9b03 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 22 Feb 2022 16:54:03 +0000 Subject: [PATCH] Bug 30155: Don't get items that can fillholds if there are no holds This makes two changes: 1 - We no longer call get_items_that_can_fill if there are no holds 2 - The subroutine will return an empty Koha::Items object if there are no holds passed Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Tomas Cohen Arazi Signed-off-by: Fridolin Somers --- Koha/Holds.pm | 3 +++ circ/pendingreserves.pl | 6 ++++-- t/db_dependent/Koha/Holds.t | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Koha/Holds.pm b/Koha/Holds.pm index cfaeb4583a..32d9138b37 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -111,6 +111,9 @@ Items that are not: sub get_items_that_can_fill { my ( $self ) = @_; + return Koha::Items->new->empty() + unless $self->count() > 0; + my @itemnumbers = $self->search({ 'me.itemnumber' => { '!=' => undef } })->get_column('itemnumber'); my @biblionumbers = $self->search({ 'me.itemnumber' => undef })->get_column('biblionumber'); my @bibs_or_items; diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 8ca7245b3c..3ac6d37043 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -193,8 +193,10 @@ my $holds = Koha::Holds->search( my @biblionumbers = $holds->get_column('biblionumber'); my $all_items; -foreach my $item ( $holds->get_items_that_can_fill ) { - push @{$all_items->{$item->biblionumber}}, $item; +if ( $holds->count ) { + foreach my $item ( $holds->get_items_that_can_fill ) { + push @{ $all_items->{ $item->biblionumber } }, $item; + } } # patrons count per biblio diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t index adbb588f86..e1ab03b0be 100755 --- a/t/db_dependent/Koha/Holds.t +++ b/t/db_dependent/Koha/Holds.t @@ -410,7 +410,7 @@ subtest 'Desks' => sub { }; subtest 'get_items_that_can_fill' => sub { - plan tests => 3; + plan tests => 5; my $biblio = $builder->build_sample_biblio; my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); # For 1, 2, 3, 4 @@ -502,6 +502,11 @@ subtest 'get_items_that_can_fill' => sub { is_deeply( [ map { $_->itemnumber } $items->as_list ], [ $item_2->itemnumber ], 'Only item 2 is available for filling the hold' ); + my $no_holds = Koha::Holds->new->empty(); + my $no_items = $no_holds->get_items_that_can_fill(); + is( ref $no_items, "Koha::Items", "Routine returns a Koha::Items object"); + is( $no_items->count, 0, "Object is empty when called on no holds"); + }; $schema->storage->txn_rollback; -- 2.39.5