Bug 14695 [QA Followup] - Fix clearing of all holds by patron at checkout
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 22 Jan 2016 15:25:20 +0000 (15:25 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Sat, 3 Sep 2016 00:21:21 +0000 (00:21 +0000)
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jason M. Burds <JBurds@dubuque.lib.ia.us>
Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no>

C4/Reserves.pm
Koha/Old/Hold.pm [new file with mode: 0644]
Koha/Old/Holds.pm [new file with mode: 0644]

index 3fa5192..537d061 100644 (file)
@@ -40,6 +40,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;
@@ -1228,56 +1229,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 (file)
index 0000000..ede5833
--- /dev/null
@@ -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 <kyle@bywatersolutions.com>
+
+=cut
+
+1;
diff --git a/Koha/Old/Holds.pm b/Koha/Old/Holds.pm
new file mode 100644 (file)
index 0000000..16fce12
--- /dev/null
@@ -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 <kyle@bywatersolutions.com>
+
+=cut
+
+1;