Bug 15295: Koha::Libraries - Remove GetBranchesCount
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 3 Dec 2015 14:47:50 +0000 (14:47 +0000)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Thu, 14 Jan 2016 15:45:31 +0000 (15:45 +0000)
This is replaced with Koha::Libraries->search->count.

Signed-off-by: Marc VĂ©ron <veron@veron.ch>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
http://bugs.koha-community.org/show_bug.cgi?id=15294

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
C4/Branch.pm
C4/Koha.pm
t/db_dependent/Branch.t

index e6c4853..c4e4cc1 100644 (file)
@@ -40,7 +40,6 @@ BEGIN {
                &GetBranchesInCategory
                &ModBranchCategoryInfo
                &mybranch
-               &GetBranchesCount
        );
     @EXPORT_OK = qw( &onlymine &mybranch );
 }
@@ -403,15 +402,6 @@ sub ModBranchCategoryInfo {
         $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) );
     }
 }
-sub GetBranchesCount {
-    my $dbh = C4::Context->dbh();
-    my $query = "SELECT COUNT(*) AS branches_count FROM branches";
-    my $sth = $dbh->prepare( $query );
-    $sth->execute();
-    my $row = $sth->fetchrow_hashref();
-    return $row->{'branches_count'};
-}
-
 1;
 __END__
 
index 8959010..0bb2bd7 100644 (file)
@@ -24,9 +24,10 @@ use strict;
 #use warnings; FIXME - Bug 2505
 
 use C4::Context;
-use C4::Branch qw(GetBranchesCount);
+use C4::Branch; # Can be removed?
 use Koha::Cache;
 use Koha::DateUtils qw(dt_from_string);
+use Koha::Libraries;
 use DateTime::Format::MySQL;
 use Business::ISBN;
 use autouse 'Data::cselectall_arrayref' => qw(Dumper);
@@ -794,7 +795,7 @@ sub getFacets {
             ];
 
             unless ( C4::Context->preference("singleBranchMode")
-                || GetBranchesCount() == 1 )
+                || Koha::Libraries->search->count == 1 )
             {
                 my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
                 if (   $DisplayLibraryFacets eq 'both'
@@ -876,7 +877,7 @@ sub getFacets {
             ];
 
             unless ( C4::Context->preference("singleBranchMode")
-                || GetBranchesCount() == 1 )
+                || Koha::Libraries->search->count == 1 )
             {
                 my $DisplayLibraryFacets = C4::Context->preference('DisplayLibraryFacets');
                 if (   $DisplayLibraryFacets eq 'both'
index 2595704..791f545 100644 (file)
@@ -45,7 +45,7 @@ can_ok(
       GetBranchesInCategory
       ModBranchCategoryInfo
       mybranch
-      GetBranchesCount)
+      )
 );
 
 
@@ -59,7 +59,7 @@ $dbh->do('DELETE FROM branchcategories');
 
 # Start test
 
-my $count = GetBranchesCount();
+my $count = Koha::Libraries->search->count;
 like( $count, '/^\d+$/', "the count is a number" );
 
 #add 2 branches
@@ -111,10 +111,10 @@ is( ModBranch($b2), undef, 'the field add is missing' );
 
 $b2->{add} = 1;
 ModBranch($b2);
-is( GetBranchesCount(), $count + 2, "two branches added" );
+is( Koha::Libraries->search->count, $count + 2, "two branches added" );
 
 is( Koha::Libraries->find( $b2->{branchcode} )->delete, 1,          "One row affected" );
-is( GetBranchesCount(),             $count + 1, "branch BRB deleted" );
+is( Koha::Libraries->search->count,             $count + 1, "branch BRB deleted" );
 
 #Test GetBranchName
 is( GetBranchName( $b1->{branchcode} ),
@@ -129,7 +129,7 @@ is_deeply( $branchdetail, $b1, 'branchdetail is right' );
 #Test Getbranches
 my $branches = GetBranches();
 is( scalar( keys %$branches ),
-    GetBranchesCount(), "GetBranches returns the right number of branches" );
+    Koha::Libraries->search->count, "GetBranches returns the right number of branches" );
 
 #Test ModBranch
 
@@ -156,7 +156,7 @@ $b1 = {
 };
 
 ModBranch($b1);
-is( GetBranchesCount(), $count + 1,
+is( Koha::Libraries->search->count, $count + 1,
     "A branch has been modified, no new branch added" );
 $branchdetail = GetBranchDetail( $b1->{branchcode} );
 $b1->{issuing} = undef;
@@ -211,7 +211,7 @@ is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 dele
 
 $b2->{CAT1} = 1;
 ModBranch($b2);
-is( GetBranchesCount(), $count + 2, 'BRB added' );
+is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
 
 #Test GetBranchInfo
 my $b1info = GetBranchInfo( $b1->{branchcode} );
@@ -297,7 +297,7 @@ is_deeply( $brCat1, \@b, 'CAT1 has branch BRB and BRC' );
 
 #Test GetBranchesLoop
 my $loop = GetBranchesLoop;
-is( scalar(@$loop), GetBranchesCount(), 'There is the right number of branches' );
+is( scalar(@$loop), Koha::Libraries->search->count, 'There is the right number of branches' );
 
 # End transaction
 $dbh->rollback;