From 4b19e4bb6a0582ddeb94fc94bdcfb0c4448ef372 Mon Sep 17 00:00:00 2001 From: Mason James Date: Wed, 20 Sep 2017 15:59:27 +1200 Subject: [PATCH] Revert "Bug 17249: Remove GetKohaAuthorisedValuesFromField - Add search_by_marc_field" This reverts commit c8fbb9c58bd72031b77d52327004ba441e71cdb9. --- C4/Koha.pm | 1 - C4/Record.pm | 11 +++------- Koha/AuthorisedValues.pm | 18 ---------------- t/db_dependent/AuthorisedValues.t | 35 +------------------------------ 4 files changed, 4 insertions(+), 61 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 66e17a5950..bb3581123d 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -28,7 +28,6 @@ use C4::Branch; # Can be removed? use Koha::Cache; use Koha::DateUtils qw(dt_from_string); use Koha::Libraries; -use Koha::MarcSubfieldStructures; use DateTime::Format::MySQL; use Business::ISBN; use autouse 'Data::cselectall_arrayref' => qw(Dumper); diff --git a/C4/Record.pm b/C4/Record.pm index d081ac782a..440b48e924 100644 --- a/C4/Record.pm +++ b/C4/Record.pm @@ -37,7 +37,6 @@ use Text::CSV::Encoded; #marc2csv use Koha::SimpleMARC qw(read_field); use Koha::XSLT_Handler; use Koha::CsvProfiles; -use Koha::AuthorisedValues; use Carp; use vars qw(@ISA @EXPORT); @@ -586,22 +585,18 @@ sub marcrecord2csv { # If it is a subfield my @loop_values; if ( $tag->{subfieldtag} ) { - my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, tagsubfield => $tag->{subfieldtag}, }); - $av = $av->count ? $av->unblessed : []; - my $av_description_mapping = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av }; # For each field foreach my $field (@fields) { my @subfields = $field->subfield( $tag->{subfieldtag} ); foreach my $subfield (@subfields) { - push @loop_values, (defined $av_description_mapping->{$subfield}) ? $av_description_mapping->{$subfield} : $subfield; + my $authvalues = GetKohaAuthorisedValuesFromField( $tag->{fieldtag}, $tag->{subfieldtag}, $frameworkcode, undef); + push @loop_values, (defined $authvalues->{$subfield}) ? $authvalues->{$subfield} : $subfield; } } # Or a field } else { - my $av = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => $frameworkcode, tagfield => $tag->{fieldtag}, }); - $av = $av->count ? $av->unblessed : []; - my $authvalues = { map { ( $_->{authorised_value} => $_->{lib} ) } @$av }; + my $authvalues = GetKohaAuthorisedValuesFromField( $tag->{fieldtag}, undef, $frameworkcode, undef); foreach my $field ( @fields ) { my $value; diff --git a/Koha/AuthorisedValues.pm b/Koha/AuthorisedValues.pm index cbab8deb39..d0eea2a332 100644 --- a/Koha/AuthorisedValues.pm +++ b/Koha/AuthorisedValues.pm @@ -24,7 +24,6 @@ use Carp; use Koha::Database; use Koha::AuthorisedValue; -use Koha::MarcSubfieldStructures; use base qw(Koha::Objects); @@ -63,23 +62,6 @@ sub search { return $self->SUPER::search( { %$params, %$or, }, $join ); } -sub search_by_marc_field { - my ( $self, $params ) = @_; - my $frameworkcode = $params->{frameworkcode} || ''; - my $tagfield = $params->{tagfield}; - my $tagsubfield = $params->{tagsubfield}; - - return unless $tagfield or $tagsubfield; - - return $self->SUPER::search( - { 'marc_subfield_structures.frameworkcode' => $frameworkcode, - ( defined $tagfield ? ( 'marc_subfield_structures.tagfield' => $tagfield ) : () ), - ( defined $tagsubfield ? ( 'marc_subfield_structures.tagsubfield' => $tagsubfield ) : () ), - }, - { join => { category => 'marc_subfield_structures' } } - ); -} - sub categories { my ( $self ) = @_; my $rs = $self->_resultset->search( diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t index a4c2a70d69..a1cbfef459 100644 --- a/t/db_dependent/AuthorisedValues.t +++ b/t/db_dependent/AuthorisedValues.t @@ -1,13 +1,11 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 15; +use Test::More tests => 14; use C4::Context; use Koha::AuthorisedValue; use Koha::AuthorisedValues; -use Koha::AuthorisedValueCategories; -use Koha::MarcSubfieldStructures; my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; @@ -97,34 +95,3 @@ my @categories = Koha::AuthorisedValues->new->categories; is( @categories, 2, 'There should have 2 categories inserted' ); is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' ); is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' ); - -subtest 'search_by_*_field' => sub { - plan tests => 1; - my $loc_cat = Koha::AuthorisedValueCategories->find('LOC'); - $loc_cat->delete if $loc_cat; - my $mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'c', frameworkcode => '' } ); - $mss->delete if $mss; - $mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'd', frameworkcode => '' } ); - $mss->delete if $mss; - Koha::AuthorisedValueCategory->new( { category_name => 'LOC' } )->store; - Koha::AuthorisedValueCategory->new( { category_name => 'ANOTHER_4_TESTS' } )->store; - Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => '', authorised_value => 'LOC', kohafield => 'items.location' } )->store; - Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => 'ACQ', authorised_value => 'LOC', kohafield => 'items.location' } )->store; - Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'd', frameworkcode => '', authorised_value => 'ANOTHER_4_TESTS', kohafield => 'items.another_field' } )->store; - Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_1' } )->store; - Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_2' } )->store; - Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_3' } )->store; - Koha::AuthorisedValue->new( { category => 'ANOTHER_4_TESTS', authorised_value => 'an_av' } )->store; - Koha::AuthorisedValue->new( { category => 'ANOTHER_4_TESTS', authorised_value => 'another_av' } )->store; - subtest 'search_by_marc_field' => sub { - plan tests => 4; - my $avs; - $avs = Koha::AuthorisedValues->search_by_marc_field(); - is ( $avs, undef ); - $avs = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => '' }); - is ( $avs, undef ); - $avs = Koha::AuthorisedValues->search_by_marc_field({ tagfield => 952, tagsubfield => 'c'}); - is( $avs->count, 3, 'default fk'); - is( $avs->next->authorised_value, 'location_1', ); - }; -}; -- 2.39.5