Bug 19056: Replace C4::Reserves::GetReserveCount with Koha::Patron->holds->count
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 7 Aug 2017 20:29:43 +0000 (17:29 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 1 Sep 2017 16:00:05 +0000 (13:00 -0300)
This subroutine is only used once and can easily be replaced with
Koha::Patron->holds->count

Test plan:
- Set maxreserves=5
- Place 3 holds for a given patron
- Place again 3 holds for this patron
3+3 > 5 => The holds must not be placed

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Reserves.pm
reserve/request.pl
t/db_dependent/Holds.t

index f07dd7f..924ce5f 100644 (file)
@@ -106,7 +106,6 @@ BEGIN {
 
         &GetReserve
         &GetReservesForBranch
-        &GetReserveCount
         &GetReserveStatus
 
         &GetOtherReserves
@@ -475,30 +474,6 @@ sub CanReserveBeCanceledFromOpac {
 
 }
 
-=head2 GetReserveCount
-
-  $number = &GetReserveCount($borrowernumber);
-
-this function returns the number of reservation for a borrower given on input arg.
-
-=cut
-
-sub GetReserveCount {
-    my ($borrowernumber) = @_;
-
-    my $dbh = C4::Context->dbh;
-
-    my $query = "
-        SELECT COUNT(*) AS counter
-        FROM reserves
-        WHERE borrowernumber = ?
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($borrowernumber);
-    my $row = $sth->fetchrow_hashref;
-    return $row->{counter};
-}
-
 =head2 GetOtherReserves
 
   ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
index 7cda03d..2728170 100755 (executable)
@@ -142,8 +142,7 @@ if ($borrowernumber_hold && !$action) {
     # we check the reserves of the user, and if they can reserve a document
     # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
 
-    my $reserves_count =
-      GetReserveCount( $patron->borrowernumber );
+    my $reserves_count = $patron->holds->count;
 
     my $new_reserves_count = scalar( @biblionumbers );
 
index 584acb2..871d687 100755 (executable)
@@ -7,7 +7,7 @@ use t::lib::TestBuilder;
 
 use C4::Context;
 
-use Test::More tests => 57;
+use Test::More tests => 56;
 use MARC::Record;
 use C4::Biblio;
 use C4::Items;
@@ -127,9 +127,6 @@ $holds = $patron->holds;
 is( $holds->next->borrowernumber, $borrowernumbers[0], "Test Koha::Patron->holds");
 
 
-ok( GetReserveCount( $borrowernumbers[0] ), "Test GetReserveCount()" );
-
-
 CancelReserve({ 'reserve_id' => $reserve_id });
 $holds = $biblio->holds;
 is( $holds->count, $borrowers_count - 1, "Test CancelReserve()" );