From 0dc22bc59e51df1e3662e4e7f0e2f772ac8f7ddf 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 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 Bug 24715: Improve code of _check_split This routine may check repeatability in a specific framework, and return the framework hash. The handling of $mss2 to store that hash is improved here. Adding a test in TransformKohaToMarc.t to see if we hit the cache. Test plan: Run t/db_dependent/Biblio/TransformKohaToMarc.t Signed-off-by: Marcel de Rooy Bug 24715: (QA follow-up) Remove $mss2 tric As requested by QA, removing the $mss2 variable. This may lead to repeated calls to the cache. Signed-off-by: Jonathan Druart Patches have been squashed for readability. I also re-add the existing syntax for the _check_split call --- C4/Biblio.pm | 12 +++++++++--- t/db_dependent/Biblio/TransformKohaToMarc.t | 6 ++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index d8a96a6062..f0977fb7e7 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1990,7 +1990,7 @@ 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 $tag_hr = {}; while ( my ($kohafield, $value) = each %$hash ) { foreach my $fld ( @{ $mss->{$kohafield} } ) { @@ -2023,6 +2023,7 @@ sub TransformKohaToMarc { } sub _check_split { +# Checks if $value must be split; may consult passed framework my ($params, $fld, $value) = @_; return if index($value,'|') == -1; # nothing to worry about return if $params->{no_split}; @@ -2031,8 +2032,13 @@ 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; + my $mss = GetMarcSubfieldStructure($params->{framework}, { unsafe => 1 }); + foreach my $fld2 ( @{ $mss->{ $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..377dbab6a5 100644 --- a/t/db_dependent/Biblio/TransformKohaToMarc.t +++ b/t/db_dependent/Biblio/TransformKohaToMarc.t @@ -79,7 +79,7 @@ subtest "Working with control fields" => sub { }; subtest "Add tests for _check_split" => sub { - plan tests => 7; + plan tests => 8; Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'a' })->delete; Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '952', tagsubfield => 'a', kohafield => 'items.fld1' })->store; @@ -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' ); @@ -105,9 +105,11 @@ subtest "Add tests for _check_split" => sub { $record = C4::Biblio::TransformKohaToMarc( { @cols } ); is( $record->subfield( '952', 'a' ), '01 | 02', 'Check composite in 952a' ); # Test with other framework (repeatable) + Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-". $fw ); $record = C4::Biblio::TransformKohaToMarc( { @cols }, { framework => $fw } ); is( ($record->subfield( '952', 'a' ))[0], '01', "Framework $fw first 952a" ); is( ($record->subfield( '952', 'a' ))[1], '02', "Framework $fw second 952a" ); + is( ref(Koha::Caches->get_instance->get_from_cache( "MarcSubfieldStructure-". $fw )), 'HASH', 'We did hit the cache' ); }; # Cleanup -- 2.20.1