From 61ba35c2b33c4f7aedaf1701814f3c783c54a19c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 3 Dec 2015 14:47:50 +0000 Subject: [PATCH] Bug 15295: Koha::Libraries - Remove GetBranchesCount MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is replaced with Koha::Libraries->search->count. Signed-off-by: Marc Véron Signed-off-by: Martin Renvoize http://bugs.koha-community.org/show_bug.cgi?id=15294 Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- C4/Branch.pm | 10 ---------- C4/Koha.pm | 7 ++++--- t/db_dependent/Branch.t | 16 ++++++++-------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/C4/Branch.pm b/C4/Branch.pm index e6c485316a..c4e4cc1190 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -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__ diff --git a/C4/Koha.pm b/C4/Koha.pm index 8959010dde..0bb2bd7565 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -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' diff --git a/t/db_dependent/Branch.t b/t/db_dependent/Branch.t index 25957041da..791f5454d8 100644 --- a/t/db_dependent/Branch.t +++ b/t/db_dependent/Branch.t @@ -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; -- 2.39.5