From 006b36896a8541c78a1b25159a0b26b89b008712 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 14 Mar 2014 10:52:03 +0100 Subject: [PATCH] Bug 8868: Remove CancelReserveFromId CancelReserve does the same job. Signed-off-by: Benjamin Rokseth Signed-off-by: Kyle M Hall --- C4/ILSDI/Services.pm | 2 +- C4/Reserves.pm | 91 +++++++------------------------------------- t/db_dependent/Reserves.t | 9 ++-- 3 files changed, 21 insertions(+), 81 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index f2a5111..e3a7fa6 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -742,7 +742,7 @@ sub CancelHold { return { code => 'RecordNotFound' } unless $reserve; return { code => 'RecordNotFound' } unless ($reserve->{borrowernumber} == $borrowernumber); - C4::Reserves::CancelReserveFromId($reserve_id); + C4::Reserves::CancelReserve({reserve_id => $reserve_id}); return { code => 'Canceled' }; } diff --git a/C4/Reserves.pm b/C4/Reserves.pm index fe9f5f9..80e96d9 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -117,9 +117,8 @@ BEGIN { &CheckReserves &CanBookBeReserved - &CanItemBeReserved + &CanItemBeReserved &CancelReserve - &CancelReserveFromId &CancelExpiredReserves &AutoUnsuspendReserves @@ -1031,86 +1030,26 @@ sub CancelReserve { return unless ( $reserve_id ); my $dbh = C4::Context->dbh; - my $reserve = GetReserve( $reserve_id ); - - my $query = " - UPDATE reserves - SET cancellationdate = now(), - found = Null, - priority = 0 - WHERE reserve_id = ? - "; - my $sth = $dbh->prepare($query); - $sth->execute( $reserve_id ); - - $query = " - INSERT INTO old_reserves - SELECT * FROM reserves - WHERE reserve_id = ? - "; - $sth = $dbh->prepare($query); - $sth->execute( $reserve_id ); - - $query = " - DELETE FROM reserves - WHERE reserve_id = ? - "; - $sth = $dbh->prepare($query); - $sth->execute( $reserve_id ); - - # now fix the priority on the others.... - _FixPriority({ biblionumber => $reserve->{biblionumber} }); -} - -=head2 CancelReserveFromId - - C4::Reserves::CancelReserveFromId($reserve_id); - -Cancel a reserve, given its reserve_id - -=cut - -sub CancelReserveFromId { - my ($reserve_id) = @_; - - my $reserve = GetReserve($reserve_id); if ($reserve) { - my $dbh = C4::Context->dbh; - - # update the database, removing the record... - my $query = qq{ + my $query = " UPDATE reserves - SET cancellationdate = NOW(), - found = NULL, - priority = 0 - WHERE reserve_id = ? - }; + SET cancellationdate = now(), + found = Null, + priority = 0 + WHERE reserve_id = ? + "; my $sth = $dbh->prepare($query); - $sth->execute($reserve_id); - $sth->finish; + $sth->execute( $reserve_id ); - $query = qq{ - INSERT INTO old_reserves - SELECT * FROM reserves - WHERE reserve_id = ? - }; + $query = " + DELETE FROM reserves + WHERE reserve_id = ? + "; $sth = $dbh->prepare($query); - my $rv = $sth->execute($reserve_id); - - if ($rv) { - $query = qq{ - DELETE FROM reserves - WHERE reserve_id = ? - }; - $sth = $dbh->prepare($query); - $sth->execute($reserve_id); - } else { - warn "ERROR: Failed to move reserve $reserve_id to table old_reserves."; - return; - } + $sth->execute( $reserve_id ); - # now fix the priority on the others... + # now fix the priority on the others.... _FixPriority({ biblionumber => $reserve->{biblionumber} }); } diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 8401c21..a4fd43a 100644 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -238,15 +238,16 @@ $reserve = GetReserve($reserve_id); isa_ok($reserve, 'HASH', "GetReserve return"); is($reserve->{biblionumber}, $biblionumber); -$reserve = CancelReserveFromId($reserve_id); -isa_ok($reserve, 'HASH', "CancelReserveFromId return"); +$reserve = CancelReserve({reserve_id => $reserve_id}); +isa_ok($reserve, 'HASH', "CancelReserve return"); is($reserve->{biblionumber}, $biblionumber); $reserve = GetReserve($reserve_id); is($reserve, undef, "GetReserve returns undef after deletion"); -$reserve = CancelReserveFromId($reserve_id); -is($reserve, undef, "CancelReserveFromId return undef if reserve does not exist"); +$reserve = CancelReserve({reserve_id => $reserve_id}); +is($reserve, undef, "CancelReserve return undef if reserve does not exist"); + # Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn # Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does) -- 1.7.2.5