Bug 17251: Koha::AuthorisedValues - Remove GetKohaAuthorisedValuesMapping

This subroutine was only used once in GetItemsForInventory.
It can be replaced with a quite simple search on AV join on
authorised_value_categories and marc_subfield_structures tables.

Note that the "interface" parameter was always set to "staff" and was
useless.

Test plan:
Play with the inventory and confirm that the AV descriptions are
correctly displayed.

The tests in t/db_dependent/Items/GetItemsForInventory.t cover this
change and should still pass.

Signed-off-by: Claire Gravely <claire_gravely@hotmail.com>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-08-10 12:29:57 +01:00 committed by Kyle M Hall
parent 0b6f129ac3
commit 8323db303d
6 changed files with 19 additions and 110 deletions

View File

@ -1045,7 +1045,6 @@ sub GetLostItems {
offset => $offset,
size => $size,
statushash => $statushash,
interface => $interface,
} );
Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
@ -1076,7 +1075,6 @@ sub GetItemsForInventory {
my $offset = $parameters->{'offset'} // '';
my $size = $parameters->{'size'} // '';
my $statushash = $parameters->{'statushash'} // '';
my $interface = $parameters->{'interface'} // '';
my $dbh = C4::Context->dbh;
my ( @bind_params, @where_strings );
@ -1156,9 +1154,19 @@ sub GetItemsForInventory {
$sth->execute( @bind_params );
my ($iTotalRecords) = $sth->fetchrow_array();
my $avmapping = C4::Koha::GetKohaAuthorisedValuesMapping( {
interface => $interface
} );
my @avs = Koha::AuthorisedValues->search(
{ 'marc_subfield_structures.kohafield' => { '>' => '' },
'me.authorised_value' => { '>' => '' },
},
{ join => { category => 'marc_subfield_structures' },
distinct => ['marc_subfield_structures.kohafield, me.category, frameworkcode, me.authorised_value'],
'+select' => [ 'marc_subfield_structures.kohafield', 'marc_subfield_structures.frameworkcode', 'me.authorised_value', 'me.lib' ],
'+as' => [ 'kohafield', 'frameworkcode', 'authorised_value', 'lib' ],
}
);
my $avmapping = { map { $_->get_column('kohafield') . ',' . $_->get_column('frameworkcode') . ',' . $_->get_column('authorised_value') => $_->get_column('lib') } @avs };
foreach my $row (@$tmpresults) {
# Auth values

View File

@ -26,6 +26,7 @@ use strict;
use C4::Context;
use Koha::Caches;
use Koha::DateUtils qw(dt_from_string);
use Koha::AuthorisedValues;
use Koha::Libraries;
use Koha::MarcSubfieldStructures;
use DateTime::Format::MySQL;
@ -54,7 +55,6 @@ BEGIN {
&GetAuthorisedValues
&GetAuthorisedValueCategories
&GetKohaAuthorisedValues
&GetKohaAuthorisedValuesMapping
&GetAuthorisedValueByCode
&GetNormalizedUPC
&GetNormalizedISBN
@ -1014,50 +1014,6 @@ sub GetKohaAuthorisedValues {
return $values;
}
=head2 GetKohaAuthorisedValuesMapping
Takes a hash as a parameter. The interface key indicates the
description to use in the mapping.
Returns hashref of:
"{kohafield},{frameworkcode},{authorised_value}" => "{description}"
for all the kohafields, frameworkcodes, and authorised values.
Returns undef if nothing is found.
=cut
sub GetKohaAuthorisedValuesMapping {
my ($parameter) = @_;
my $interface = $parameter->{'interface'} // '';
my $query_mapping = q{
SELECT TA.kohafield,TA.authorised_value AS category,
TA.frameworkcode,TB.authorised_value,
IF(TB.lib_opac>'',TB.lib_opac,TB.lib) AS OPAC,
TB.lib AS Intranet,TB.lib_opac
FROM marc_subfield_structure AS TA JOIN
authorised_values as TB ON
TA.authorised_value=TB.category
WHERE TA.kohafield>'' AND TA.authorised_value>'';
};
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare($query_mapping);
$sth->execute();
my $avmapping;
if ($interface eq 'opac') {
while (my $row = $sth->fetchrow_hashref) {
$avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{OPAC};
}
}
else {
while (my $row = $sth->fetchrow_hashref) {
$avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{Intranet};
}
}
return $avmapping;
}
=head2 xml_escape
my $escaped_string = C4::Koha::xml_escape($string);

View File

@ -45,7 +45,7 @@ my @objects = Koha::AuthorisedValues->search($params);
=cut
sub search {
my ( $self, $params ) = @_;
my ( $self, $params, $attributes ) = @_;
my $branchcode = $params->{branchcode};
delete( $params->{branchcode} );
@ -60,7 +60,9 @@ sub search {
}
: {};
my $join = $branchcode ? { join => 'authorised_values_branches' } : {};
return $self->SUPER::search( { %$params, %$or, }, $join );
$attributes //= {};
$attributes = { %$attributes, %$join };
return $self->SUPER::search( { %$params, %$or, }, $attributes );
}
sub search_by_marc_field {

View File

@ -38,7 +38,7 @@ $dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
my ($oldResults, $oldCount) = OldWay($dbh);
my ($newResults, $newCount) = GetItemsForInventory( { interface => 'staff' } );
my ($newResults, $newCount) = GetItemsForInventory;
is_deeply($newResults,$oldResults,"Inventory results unchanged.");
@ -58,7 +58,6 @@ sub OldWay {
my $offset = '';
my $size = '';
my $statushash = '';
my $interface = '';
my ( @bind_params, @where_strings );

View File

@ -1,54 +0,0 @@
#!/usr/bin/perl
#
# This file is part of Koha.
#
# Copyright (c) 2015 Mark Tompsett
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use C4::Context;
use Test::More tests => 8;
BEGIN {
use_ok('C4::Context');
use_ok('C4::Koha');
}
can_ok('C4::Koha','GetKohaAuthorisedValuesMapping');
my $avMappingOPAC;
my $avMappingStaff;
my $avMappingUndef1;
my $avMappingUndef2;
my $avMappingUndef3;
SKIP: {
my $dbh = C4::Context->dbh;
my $count = $dbh->selectrow_arrayref("SELECT COUNT(*) FROM marc_subfield_structure WHERE kohafield LIKE 'item%';");
skip "Lacking item mappings in marc_subfield_structure",5 unless ($count && $count->[0]>0);
$count = $dbh->selectrow_arrayref("SELECT COUNT(*) FROM authorised_values;");
skip "Lacking authorised_values",5 unless ($count && $count->[0]>0);
$avMappingOPAC = GetKohaAuthorisedValuesMapping( { interface => 'opac' });
$avMappingStaff = GetKohaAuthorisedValuesMapping( { interface => 'staff' });
$avMappingUndef1 = GetKohaAuthorisedValuesMapping( { interface => undef });
$avMappingUndef2 = GetKohaAuthorisedValuesMapping( { } );
$avMappingUndef3 = GetKohaAuthorisedValuesMapping();
is_deeply($avMappingUndef1,$avMappingStaff,"Undefined interface = Staff test 1");
is_deeply($avMappingUndef2,$avMappingStaff,"Undefined interface = Staff test 2");
is_deeply($avMappingUndef3,$avMappingStaff,"Undefined interface = Staff test 3");
isnt($avMappingOPAC ,undef,"OPAC has a mapping");
isnt($avMappingStaff,undef,"Staff has a mapping");
}

View File

@ -246,7 +246,6 @@ if ( $markseen or $op ) {
offset => 0,
size => undef,
statushash => $staton,
interface => 'staff',
} );
# For the items that may be marked as "wrong place", we only check the location (callnumbers, location and branch)
@ -262,7 +261,6 @@ if ( $markseen or $op ) {
offset => 0,
size => undef,
statushash => undef,
interface => 'staff',
} );
}