From e06ae3a64a8c7f46159585a9bce80804749401bb Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 24 Feb 2020 12:52:13 +0000 Subject: [PATCH] Bug 24715: Cache repeatable subfield in TransformKohaToMarc Content-Type: text/plain; charset=utf-8 Implemented by calling GetMarcSubfieldStructure. Test plan: Run t/db_dependent/Biblio/TransformKohaToMarc.t Optionally, follow the test plan of bug 21800#comment7. Signed-off-by: Marcel de Rooy Signed-off-by: Ere Maijala --- C4/Biblio.pm | 17 ++++++++++++----- t/db_dependent/Biblio/TransformKohaToMarc.t | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index d8a96a6062..051e44528c 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1990,7 +1990,8 @@ sub TransformKohaToMarc { # In the next call we use the Default framework, since it is considered # authoritative for Koha to Marc mappings. - my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # do not change framewok + my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # do not change framework + my $mss2; # belongs to $params->{framework} only filled when needed my $tag_hr = {}; while ( my ($kohafield, $value) = each %$hash ) { foreach my $fld ( @{ $mss->{$kohafield} } ) { @@ -1999,7 +2000,7 @@ sub TransformKohaToMarc { next if !$tagfield; # BZ 21800: split value if field is repeatable. - my @values = _check_split($params, $fld, $value) + my @values = _check_split($params, $mss2, $fld, $value) ? split(/\s?\|\s?/, $value, -1) : ( $value ); foreach my $value ( @values ) { @@ -2023,7 +2024,7 @@ sub TransformKohaToMarc { } sub _check_split { - my ($params, $fld, $value) = @_; + my ($params, $mss2, $fld, $value) = @_; return if index($value,'|') == -1; # nothing to worry about return if $params->{no_split}; @@ -2031,8 +2032,14 @@ sub _check_split { return $fld->{repeatable} if !$params->{framework}; # here we need to check the specific framework - my $mss = Koha::MarcSubfieldStructures->find( $params->{framework}, $fld->{tagfield}, $fld->{tagsubfield} ); - return 1 if $mss && $mss->repeatable; + $mss2 = GetMarcSubfieldStructure($params->{framework}, { unsafe => 1 }) + if !$mss2; + foreach my $fld2 ( @{ $mss2->{ $fld->{kohafield} } } ) { + next if $fld2->{tagfield} ne $fld->{tagfield}; + next if $fld2->{tagsubfield} ne $fld->{tagsubfield}; + return 1 if $fld2->{repeatable}; + } + return; } =head2 PrepHostMarcField diff --git a/t/db_dependent/Biblio/TransformKohaToMarc.t b/t/db_dependent/Biblio/TransformKohaToMarc.t index fac328d0a5..f22297959b 100644 --- a/t/db_dependent/Biblio/TransformKohaToMarc.t +++ b/t/db_dependent/Biblio/TransformKohaToMarc.t @@ -88,7 +88,7 @@ subtest "Add tests for _check_split" => sub { Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); # add 952a repeatable in another framework my $fw = $builder->build({ source => 'BiblioFramework' })->{frameworkcode}; - Koha::MarcSubfieldStructure->new({ frameworkcode => $fw, tagfield => '952', tagsubfield => 'a', repeatable => 1 })->store; + Koha::MarcSubfieldStructure->new({ frameworkcode => $fw, tagfield => '952', tagsubfield => 'a', repeatable => 1, kohafield => 'items.fld1' })->store; # Test single value in fld1 my @cols = ( 'items.fld1' => '01' ); -- 2.11.0