From a31033379ccf8bc229100ca628ea9cddc8f8588b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 13 Dec 2013 17:42:55 +0100 Subject: [PATCH] Bug 11336: Priority is not updated on deleting holds There are a lot of places where a hold deletion is possible. But I just found 1 place where it works! To reproduce: - select or create 2 users U1 and U2 - select or create an holdable item - place on hold for both U1 and U2. U1 has priority 1 and U2 has priority 2. - delete the hold for U1 - go on circ/circulation.pl?borrowernumber=XXXX for U2 (or in the DB directly) and verify the priority has not been set to 1 The issue is repeatable (at least) on these 2 pages: * circ/circulation.pl?borrowernumber=XXXX (tab 'Holds', select "yes" in the dropdown list and submit the form) * reserve/request.pl?biblionumber=XXXX (clic on the red cross) --- C4/Reserves.pm | 9 +++++++++ t/db_dependent/Holds.t | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index d1bca25..7fd39dc 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -252,6 +252,8 @@ sub AddReserve { $res = GetReserve( $reserve_id ); + Return the current reserve or the old reserve. + =cut sub GetReserve { @@ -262,6 +264,13 @@ sub GetReserve { my $sth = $dbh->prepare( $query ); $sth->execute( $reserve_id ); my $res = $sth->fetchrow_hashref(); + + unless ( $res ) { + $res = $dbh->selectrow_hashref(q| + SELECT * FROM old_reserves WHERE reserve_id = ? + |, {}, $reserve_id); + } + return $res; } diff --git a/t/db_dependent/Holds.t b/t/db_dependent/Holds.t index 74cecfa..b22f5a1 100755 --- a/t/db_dependent/Holds.t +++ b/t/db_dependent/Holds.t @@ -1,13 +1,12 @@ #!/usr/bin/perl -use strict; -use warnings; +use Modern::Perl; use t::lib::Mocks; use C4::Context; use C4::Branch; -use Test::More tests => 22; +use Test::More tests => 23; use MARC::Record; use C4::Biblio; use C4::Items; @@ -215,6 +214,49 @@ ok( '... unless canreservefromotherbranches is ON (bug 2394)' ); +# Regression test for bug 11336 +($bibnum, $title, $bibitemnum) = create_helper_biblio(); +my ( $hold1, $hold2 ); +($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); +AddReserve( + $branch, + $borrowernumbers[0], + $bibnum, + 'a', + '', + 1, +); + +my $reserveid1 = C4::Reserves::GetReserveId( + { + biblionumber => $bibnum, + borrowernumber => $borrowernumbers[0] + } +); + +($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum); +AddReserve( + $branch, + $borrowernumbers[1], + $bibnum, + 'a', + '', + 2, +); +my $reserveid2 = C4::Reserves::GetReserveId( + { + biblionumber => $bibnum, + borrowernumber => $borrowernumbers[1] + } +); + +CancelReserve({ reserve_id => $reserveid1 }); + +$reserve2 = GetReserve( $reserveid2 ); +is( $reserve2->{priority}, 1, "After cancelreserve, the 2nd reserve become the first on the waiting list" ); + + + # Helper method to set up a Biblio. sub create_helper_biblio { my $bib = MARC::Record->new(); -- 1.7.10.4