Browse Source

Bug 24715: Cache repeatable subfield in TransformKohaToMarc

Implemented by calling GetMarcSubfieldStructure and improving
_check_split which may check repeatability in a specific framework,
and return the framework hash.

Test plan:
Run t/db_dependent/Biblio/TransformKohaToMarc.t
Optionally, follow the test plan of bug 21800#comment7.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Marcel de Rooy 4 years ago
committed by Martin Renvoize
parent
commit
1be518588b
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 12
      C4/Biblio.pm
  2. 6
      t/db_dependent/Biblio/TransformKohaToMarc.t

12
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

6
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

Loading…
Cancel
Save