From 20eb2760f47f6c678669cb807b982611a837cefe Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 28 Jan 2021 17:23:45 -0300 Subject: [PATCH] Bug 23830: Adapt callers This patch is the result of making the same changes we did on the t/db_dependent/AuthorisedValues.t file (replacing the calls to Koha::AuthorisedValues->search with the tricky branchcode param, and call ->search_with_library_limits, with the library_id as a third parameter. What I did was: $ git grep 'Koha::AuthorisedValues\->search' and then revisited each of the grep results to check if they added the 'branchcode' parameter to the filters. This patch changes the calls to ->search, for ->search_with_library_limits in all the places that require it in the current codebase [1]. To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Charges/Sales.t \ t/db_dependent/Ill* 3. Verify the batchmod.pl script is working and filtering the authorised values keeps working [1] Some places like the Koha/Template/Plugin/AuthorisedValues.pm plugin don't seem to be tested, at first glance. Signed-off-by: Martin Renvoize --- Koha/Charges/Sales.pm | 9 ++++---- Koha/Illrequest.pm | 27 +++++++++++++++--------- Koha/Template/Plugin/AuthorisedValues.pm | 6 +++--- acqui/ajax-getauthvaluedropbox.pl | 6 +++--- tools/batchMod.pl | 8 ++++++- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Koha/Charges/Sales.pm b/Koha/Charges/Sales.pm index 71e3d9138d..5d99474868 100644 --- a/Koha/Charges/Sales.pm +++ b/Koha/Charges/Sales.pm @@ -105,11 +105,12 @@ sub _get_valid_payments { my $self = shift; $self->{valid_payments} //= { - map { $_ => 1 } Koha::AuthorisedValues->search( + map { $_ => 1 } Koha::AuthorisedValues->search_with_library_limits( { - category => 'PAYMENT_TYPE', - branchcode => $self->{cash_register}->branch - } + category => 'PAYMENT_TYPE' + }, + {}, + $self->{cash_register}->branch # filter by cash_register branch )->get_column('authorised_value') }; diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index 39cf0eabf8..74d9b84d10 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -136,11 +136,14 @@ sub statusalias { # We can't know which result is the right one if there are multiple # ILLSTATUS authorised values with the same authorised_value column value # so we just use the first - return Koha::AuthorisedValues->search({ - branchcode => $self->branchcode, - category => 'ILLSTATUS', - authorised_value => $self->SUPER::status_alias - })->next; + return Koha::AuthorisedValues->search( + { + category => 'ILLSTATUS', + authorised_value => $self->SUPER::status_alias + }, + {}, + $self->branchcode + )->next; } =head3 illrequestattributes @@ -231,11 +234,15 @@ sub status_alias { # We can't know which result is the right one if there are multiple # ILLSTATUS authorised values with the same authorised_value column value # so we just use the first - my $alias = Koha::AuthorisedValues->search({ - branchcode => $self->branchcode, - category => 'ILLSTATUS', - authorised_value => $self->SUPER::status_alias - })->next; + my $alias = Koha::AuthorisedValues->search( + { + category => 'ILLSTATUS', + authorised_value => $self->SUPER::status_alias + }, + {}, + $self->branchcode + )->next; + if ($alias) { return $alias->authorised_value; } else { diff --git a/Koha/Template/Plugin/AuthorisedValues.pm b/Koha/Template/Plugin/AuthorisedValues.pm index a4e163430a..31d3748f51 100644 --- a/Koha/Template/Plugin/AuthorisedValues.pm +++ b/Koha/Template/Plugin/AuthorisedValues.pm @@ -42,14 +42,14 @@ sub Get { sub GetAuthValueDropbox { my ( $self, $category ) = @_; my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; - return Koha::AuthorisedValues->search( + return Koha::AuthorisedValues->search_with_library_limits( { - branchcode => $branch_limit, category => $category, }, { order_by => [ 'category', 'lib', 'lib_opac' ], - } + }, + $branch_limit ); } diff --git a/acqui/ajax-getauthvaluedropbox.pl b/acqui/ajax-getauthvaluedropbox.pl index 2693a25042..41c0a8db41 100755 --- a/acqui/ajax-getauthvaluedropbox.pl +++ b/acqui/ajax-getauthvaluedropbox.pl @@ -69,14 +69,14 @@ my $default = $input->param('default'); $default = C4::Charset::NormalizeString($default); my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; -my $avs = Koha::AuthorisedValues->search( +my $avs = Koha::AuthorisedValues->search_with_library_limits( { - branchcode => $branch_limit, category => $category, }, { order_by => [ 'category', 'lib', 'lib_opac' ], - } + }, + $branch_limit ); my $html = qq|