From d511c599a50fa3a627b3c26c2b0f2caa369bea15 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 6 Jun 2019 15:14:28 -0500 Subject: [PATCH] Bug 23070: Use Koha::Hold in C4::Reserves::RevertWaitingStatus We are using raw SQL statements, we should use Koha::Hold instead. This patch does not seem optimal, we would like to increment priority in only 1 statement and without the need to fetch and loop all holds. --- C4/Reserves.pm | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 1bb3e8532a..dac88240ba 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1962,31 +1962,21 @@ sub RevertWaitingStatus { my $dbh = C4::Context->dbh; ## Get the waiting reserve we want to revert - my $query = " - SELECT * FROM reserves - WHERE itemnumber = ? - AND found IS NOT NULL - "; - my $sth = $dbh->prepare( $query ); - $sth->execute( $itemnumber ); - my $reserve = $sth->fetchrow_hashref(); - - my $hold = Koha::Holds->find( $reserve->{reserve_id} ); # TODO Remove the next raw SQL statements and use this instead + my $hold = Koha::Holds->search( + { + itemnumber => $itemnumber, + found => { not => undef }, + } + )->next; ## Increment the priority of all other non-waiting ## reserves for this bib record - $query = " - UPDATE reserves - SET - priority = priority + 1 - WHERE - biblionumber = ? - AND - priority > 0 - "; - $sth = $dbh->prepare( $query ); - $sth->execute( $reserve->{'biblionumber'} ); + my $holds = Koha::Holds->search({ biblionumber => $hold->biblionumber, priority => { '>' => 0 } }); + while ( my $h = $holds->next ) { + $h->priority( $h->priority + 1 )->store; + } + ## Fix up the currently waiting reserve $hold->set( { priority => 1, -- 2.11.0