From 79f4afe26a54061eb74d97e4753f6b73cb9e703e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 4 Feb 2016 15:24:12 +0000 Subject: [PATCH] Bug 15758: Koha::Libraries - Move mybranch to C4::Context Signed-off-by: Owen Leonard Signed-off-by: Kyle M Hall --- C4/Branch.pm | 9 +-------- C4/Circulation.pm | 4 ++-- admin/branch_transfer_limits.pl | 4 ++-- admin/smart-rules.pl | 4 ++-- t/db_dependent/Branch.t | 4 ---- tools/letter.pl | 2 +- tools/overduerules.pl | 2 +- 7 files changed, 9 insertions(+), 20 deletions(-) diff --git a/C4/Branch.pm b/C4/Branch.pm index f2d7bf1d03..7f1b713e76 100644 --- a/C4/Branch.pm +++ b/C4/Branch.pm @@ -29,9 +29,8 @@ BEGIN { @EXPORT = qw( &GetBranch &GetBranches - &mybranch ); - @EXPORT_OK = qw( &onlymine &mybranch ); + @EXPORT_OK = qw( &onlymine ); } =head1 NAME @@ -126,12 +125,6 @@ sub onlymine { && C4::Context->userenv->{branch}; } -# always returns a string for OK comparison via "eq" or "ne" -sub mybranch { - C4::Context->userenv or return ''; - return C4::Context->userenv->{branch} || ''; -} - =head2 GetBranch $branch = GetBranch( $query, $branches ); diff --git a/C4/Circulation.pm b/C4/Circulation.pm index ad715f5abd..6a71464601 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -170,7 +170,7 @@ System Pref options. # sub barcodedecode { my ($barcode, $filter) = @_; - my $branch = C4::Branch::mybranch(); + my $branch = C4::Context::mybranch(); $filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter; $filter or return $barcode; # ensure filter is defined, else return untouched barcode if ($filter eq 'whitespace') { @@ -3141,7 +3141,7 @@ sub GetIssuingCharges { if ( my $item_data = $sth->fetchrow_hashref ) { $item_type = $item_data->{itemtype}; $charge = $item_data->{rentalcharge}; - my $branch = C4::Branch::mybranch(); + my $branch = C4::Context::mybranch(); my $discount_query = q|SELECT rentaldiscount, issuingrules.itemtype, issuingrules.branchcode FROM borrowers diff --git a/admin/branch_transfer_limits.pl b/admin/branch_transfer_limits.pl index d1e59c77fc..b745136dcb 100755 --- a/admin/branch_transfer_limits.pl +++ b/admin/branch_transfer_limits.pl @@ -41,9 +41,9 @@ my ($template, $loggedinuser, $cookie) my $dbh = C4::Context->dbh; my $branchcode; -if((!defined($input->param('branchcode'))) & mybranch() ne '') +if((!defined($input->param('branchcode'))) & C4::Context::mybranch() ne '') { - $branchcode = mybranch(); + $branchcode = C4::Context::mybranch(); } else { diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index 6019214ef8..0f7da21362 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -55,10 +55,10 @@ my $type=$input->param('type'); my $branch = $input->param('branch'); unless ( $branch ) { if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) { - $branch = Koha::Libraries->search->count() == 1 ? undef : C4::Branch::mybranch(); + $branch = Koha::Libraries->search->count() == 1 ? undef : C4::Context::mybranch(); } else { - $branch = C4::Branch::onlymine() ? ( C4::Branch::mybranch() || '*' ) : '*'; + $branch = C4::Branch::onlymine() ? ( C4::Context::mybranch() || '*' ) : '*'; } } $branch = '*' if $branch eq 'NO_LIBRARY_SET'; diff --git a/t/db_dependent/Branch.t b/t/db_dependent/Branch.t index 348adb36f9..9d4a5b94ba 100644 --- a/t/db_dependent/Branch.t +++ b/t/db_dependent/Branch.t @@ -38,7 +38,6 @@ can_ok( 'C4::Branch', qw( GetBranch GetBranches - mybranch ) ); @@ -194,7 +193,4 @@ is_deeply( $b2info->get_categories->count, 1, 'BRB has the category CAT1' ); Koha::LibraryCategory->new($cat2)->store; is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" ); -#TODO later: test mybranchine and onlymine -# Actually we cannot mock C4::Context->userenv in unit tests - $schema->storage->txn_rollback; diff --git a/tools/letter.pl b/tools/letter.pl index 0f72cd6296..39b2aa25aa 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -358,7 +358,7 @@ sub default_display { unless ( defined $branchcode ) { if ( C4::Context->preference('DefaultToLoggedInLibraryNoticesSlips') ) { - $branchcode = C4::Branch::mybranch(); + $branchcode = C4::Context::mybranch(); } } diff --git a/tools/overduerules.pl b/tools/overduerules.pl index f21092d411..5c35a8c7fa 100755 --- a/tools/overduerules.pl +++ b/tools/overduerules.pl @@ -74,7 +74,7 @@ my $type = $input->param('type'); my $branch = $input->param('branch'); $branch = defined $branch ? $branch - : C4::Context->preference('DefaultToLoggedInLibraryOverdueTriggers') ? C4::Branch::mybranch() + : C4::Context->preference('DefaultToLoggedInLibraryOverdueTriggers') ? C4::Context::mybranch() : Koha::Libraries->search->count() == 1 ? undef : undef; $branch ||= q{}; -- 2.39.5