Browse Source

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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Tomás Cohen Arazi 3 years ago
committed by Jonathan Druart
parent
commit
ba5eff837b
  1. 9
      Koha/Charges/Sales.pm
  2. 27
      Koha/Illrequest.pm
  3. 6
      Koha/Template/Plugin/AuthorisedValues.pm
  4. 6
      acqui/ajax-getauthvaluedropbox.pl
  5. 8
      tools/batchMod.pl

9
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')
};

27
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 {

6
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
);
}

6
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|<select id="$name" name="$name">|;
while ( my $av = $avs->next ) {

8
tools/batchMod.pl

@ -523,7 +523,13 @@ foreach my $tag (sort keys %{$tagslib}) {
else {
push @authorised_values, ""; # unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
my @avs = Koha::AuthorisedValues->search({ category => $tagslib->{$tag}->{$subfield}->{authorised_value}, branchcode => $branch_limit },{order_by=>'lib'});
my @avs = Koha::AuthorisedValues->search_with_library_limits(
{
category => $tagslib->{$tag}->{$subfield}->{authorised_value}
},
{ order_by => 'lib' },
$branch_limit
);
for my $av ( @avs ) {
push @authorised_values, $av->authorised_value;
$authorised_lib{$av->authorised_value} = $av->lib;

Loading…
Cancel
Save