From 2503cb6bc104e18741edd61fb63cfa39b4087947 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 22 Jan 2016 15:25:20 +0000 Subject: [PATCH] Bug 14695 [QA Followup] - Fix clearing of all holds by patron at checkout Signed-off-by: Nick Clemens Signed-off-by: Jason M. Burds --- C4/Reserves.pm | 60 ++++++++++++++++----------------------------------- Koha/Old/Hold.pm | 51 ++++++++++++++++++++++++++++++++++++++++++++ Koha/Old/Holds.pm | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 42 deletions(-) create mode 100644 Koha/Old/Hold.pm create mode 100644 Koha/Old/Holds.pm diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 49e19f1..a6d1d01 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -39,6 +39,7 @@ use Koha::DateUtils; use Koha::Calendar; use Koha::Database; use Koha::Hold; +use Koha::Old::Hold; use Koha::Holds; use Koha::Libraries; use Koha::Items; @@ -1216,56 +1217,31 @@ whose keys are fields from the reserves table in the Koha database. sub ModReserveFill { my ($res) = @_; - my $dbh = C4::Context->dbh; - # fill in a reserve record.... my $reserve_id = $res->{'reserve_id'}; - my $biblionumber = $res->{'biblionumber'}; - my $borrowernumber = $res->{'borrowernumber'}; - my $resdate = $res->{'reservedate'}; + + my $dbh = C4::Context->dbh; + + my $hold = Koha::Holds->find($reserve_id); # get the priority on this record.... - my $priority; - my $query = "SELECT priority - FROM reserves - WHERE biblionumber = ? - AND borrowernumber = ? - AND reservedate = ?"; - my $sth = $dbh->prepare($query); - $sth->execute( $biblionumber, $borrowernumber, $resdate ); - ($priority) = $sth->fetchrow_array; + my $priority = $hold->priority; - # update the database... - $query = "UPDATE reserves - SET found = 'F', - priority = 0 - WHERE biblionumber = ? - AND reservedate = ? - AND borrowernumber = ? - "; - $sth = $dbh->prepare($query); - $sth->execute( $biblionumber, $resdate, $borrowernumber ); - - # move to old_reserves - $query = "INSERT INTO old_reserves - SELECT * FROM reserves - WHERE biblionumber = ? - AND reservedate = ? - AND borrowernumber = ? - "; - $sth = $dbh->prepare($query); - $sth->execute( $biblionumber, $resdate, $borrowernumber ); - $query = "DELETE FROM reserves - WHERE biblionumber = ? - AND reservedate = ? - AND borrowernumber = ? - "; - $sth = $dbh->prepare($query); - $sth->execute( $biblionumber, $resdate, $borrowernumber ); + # update the hold statuses, no need to store it though, we will be deleting it anyway + $hold->set( + { + found => 'F', + priority => 0, + } + ); + + my $old_hold = Koha::Old::Hold->new( $hold->unblessed() )->store(); + + $hold->delete(); # now fix the priority on the others (if the priority wasn't # already sorted!).... unless ( $priority == 0 ) { - _FixPriority({ reserve_id => $reserve_id, biblionumber => $biblionumber }); + _FixPriority( { reserve_id => $reserve_id, biblionumber => $hold->biblionumber } ); } } diff --git a/Koha/Old/Hold.pm b/Koha/Old/Hold.pm new file mode 100644 index 0000000..ede5833 --- /dev/null +++ b/Koha/Old/Hold.pm @@ -0,0 +1,51 @@ +package Koha::Old::Hold; + +# Copyright ByWater Solutions 2014 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use base qw(Koha::Hold); + +=head1 NAME + +Koha::Old::Hold - Koha Old Hold object class + +This object represents a hold that has been filled or canceled + +=head1 API + +=head2 Class Methods + +=cut + + +=head3 type + +=cut + +sub type { + return 'OldReserve'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Old/Holds.pm b/Koha/Old/Holds.pm new file mode 100644 index 0000000..16fce12 --- /dev/null +++ b/Koha/Old/Holds.pm @@ -0,0 +1,64 @@ +package Koha::Old::Holds; + +# Copyright ByWater Solutions 2014 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Old::Hold; + +use base qw(Koha::Holds); + +=head1 NAME + +Koha::Old::Holds - Koha Old Hold object set class + +This object represents a set of holds that have been filled or canceled + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'OldReserve'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Old::Hold'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; -- 2.1.4