From 02d47e15eb39035bafb3be511fbddf49fdcdb741 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 6 Dec 2016 12:14:28 +0100 Subject: [PATCH] Bug 17729: Move IsItemOnHoldAndFound to Koha::Holds I don't think this is ready yet, since we are in loops, that can introduce speed improvement regressions --- C4/Circulation.pm | 3 ++- C4/Reserves.pm | 29 ++--------------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index b505031..96c7dcc 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2781,8 +2781,9 @@ sub CanBookBeRenewed { foreach my $b (@borrowernumbers) { my ($borr) = C4::Members::GetMember( borrowernumber => $b); foreach my $i (@itemnumbers) { + my $hold = Koha::Holds->find( { itemnumber => $i } ); my $item = GetItem($i); - if ( !IsItemOnHoldAndFound($i) + if ( ( not $hold or not $hold->is_found ) && IsAvailableForItemLevelRequest( $item, $borr ) && CanItemBeReserved( $b, $i ) ) { diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 9ef33ad..62f7163 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -145,8 +145,6 @@ BEGIN { &GetReservesControlBranch - IsItemOnHoldAndFound - GetMaxPatronHoldsForRecord ); @EXPORT_OK = qw( MergeHolds ); @@ -1512,12 +1510,13 @@ sub IsAvailableForItemLevelRequest { my $any_available = 0; foreach my $i (@items) { + my $hold = Koha::Holds->find( { itemnumber => $i } ); $any_available = 1 unless $i->itemlost || $i->{notforloan} > 0 || $i->withdrawn || $i->onloan - || IsItemOnHoldAndFound( $i->id ) + || ( $hold and $hold->is_found ) || ( $i->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems') ) || Koha::ItemTypes->find( $i->effective_itemtype() )->notforloan; @@ -2445,30 +2444,6 @@ sub CalculatePriority { return @row ? $row[0]+1 : 1; } -=head2 IsItemOnHoldAndFound - - my $bool = IsItemFoundHold( $itemnumber ); - - Returns true if the item is currently on hold - and that hold has a non-null found status ( W, T, etc. ) - -=cut - -sub IsItemOnHoldAndFound { - my ($itemnumber) = @_; - - my $rs = Koha::Database->new()->schema()->resultset('Reserve'); - - my $found = $rs->count( - { - itemnumber => $itemnumber, - found => { '!=' => undef } - } - ); - - return $found; -} - =head2 GetMaxPatronHoldsForRecord my $holds_per_record = ReservesControlBranch( $borrowernumber, $biblionumber ); -- 2.9.3