View | Details | Raw Unified | Return to bug 24715
Collapse All | Expand All

(-)a/C4/Biblio.pm (-3 / +9 lines)
Lines 1990-1996 sub TransformKohaToMarc { Link Here
1990
1990
1991
    # In the next call we use the Default framework, since it is considered
1991
    # In the next call we use the Default framework, since it is considered
1992
    # authoritative for Koha to Marc mappings.
1992
    # authoritative for Koha to Marc mappings.
1993
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # do not change framewok
1993
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # do not change framework
1994
    my $tag_hr = {};
1994
    my $tag_hr = {};
1995
    while ( my ($kohafield, $value) = each %$hash ) {
1995
    while ( my ($kohafield, $value) = each %$hash ) {
1996
        foreach my $fld ( @{ $mss->{$kohafield} } ) {
1996
        foreach my $fld ( @{ $mss->{$kohafield} } ) {
Lines 2023-2028 sub TransformKohaToMarc { Link Here
2023
}
2023
}
2024
2024
2025
sub _check_split {
2025
sub _check_split {
2026
# Checks if $value must be split; may consult passed framework
2026
    my ($params, $fld, $value) = @_;
2027
    my ($params, $fld, $value) = @_;
2027
    return if index($value,'|') == -1; # nothing to worry about
2028
    return if index($value,'|') == -1; # nothing to worry about
2028
    return if $params->{no_split};
2029
    return if $params->{no_split};
Lines 2031-2038 sub _check_split { Link Here
2031
    return $fld->{repeatable} if !$params->{framework};
2032
    return $fld->{repeatable} if !$params->{framework};
2032
2033
2033
    # here we need to check the specific framework
2034
    # here we need to check the specific framework
2034
    my $mss = Koha::MarcSubfieldStructures->find( $params->{framework}, $fld->{tagfield}, $fld->{tagsubfield} );
2035
    my $mss = GetMarcSubfieldStructure($params->{framework}, { unsafe => 1 });
2035
    return 1 if $mss && $mss->repeatable;
2036
    foreach my $fld2 ( @{ $mss->{ $fld->{kohafield} } } ) {
2037
        next if $fld2->{tagfield} ne $fld->{tagfield};
2038
        next if $fld2->{tagsubfield} ne $fld->{tagsubfield};
2039
        return 1 if $fld2->{repeatable};
2040
    }
2041
    return;
2036
}
2042
}
2037
2043
2038
=head2 PrepHostMarcField
2044
=head2 PrepHostMarcField
(-)a/t/db_dependent/Biblio/TransformKohaToMarc.t (-3 / +4 lines)
Lines 79-85 subtest "Working with control fields" => sub { Link Here
79
};
79
};
80
80
81
subtest "Add tests for _check_split" => sub {
81
subtest "Add tests for _check_split" => sub {
82
    plan tests => 7;
82
    plan tests => 8;
83
83
84
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'a' })->delete;
84
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'a' })->delete;
85
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '952', tagsubfield => 'a', kohafield => 'items.fld1' })->store;
85
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '952', tagsubfield => 'a', kohafield => 'items.fld1' })->store;
Lines 88-94 subtest "Add tests for _check_split" => sub { Link Here
88
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
88
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
89
    # add 952a repeatable in another framework
89
    # add 952a repeatable in another framework
90
    my $fw =  $builder->build({ source => 'BiblioFramework' })->{frameworkcode};
90
    my $fw =  $builder->build({ source => 'BiblioFramework' })->{frameworkcode};
91
    Koha::MarcSubfieldStructure->new({ frameworkcode => $fw, tagfield => '952', tagsubfield => 'a', repeatable => 1 })->store;
91
    Koha::MarcSubfieldStructure->new({ frameworkcode => $fw, tagfield => '952', tagsubfield => 'a', repeatable => 1, kohafield => 'items.fld1' })->store;
92
92
93
    # Test single value in fld1
93
    # Test single value in fld1
94
    my @cols = ( 'items.fld1' => '01' );
94
    my @cols = ( 'items.fld1' => '01' );
Lines 105-113 subtest "Add tests for _check_split" => sub { Link Here
105
    $record = C4::Biblio::TransformKohaToMarc( { @cols } );
105
    $record = C4::Biblio::TransformKohaToMarc( { @cols } );
106
    is( $record->subfield( '952', 'a' ), '01 | 02', 'Check composite in 952a' );
106
    is( $record->subfield( '952', 'a' ), '01 | 02', 'Check composite in 952a' );
107
    # Test with other framework (repeatable)
107
    # Test with other framework (repeatable)
108
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-". $fw );
108
    $record =  C4::Biblio::TransformKohaToMarc( { @cols }, { framework => $fw } );
109
    $record =  C4::Biblio::TransformKohaToMarc( { @cols }, { framework => $fw } );
109
    is( ($record->subfield( '952', 'a' ))[0], '01', "Framework $fw first 952a" );
110
    is( ($record->subfield( '952', 'a' ))[0], '01', "Framework $fw first 952a" );
110
    is( ($record->subfield( '952', 'a' ))[1], '02', "Framework $fw second 952a" );
111
    is( ($record->subfield( '952', 'a' ))[1], '02', "Framework $fw second 952a" );
112
    is( ref(Koha::Caches->get_instance->get_from_cache( "MarcSubfieldStructure-". $fw )), 'HASH', 'We did hit the cache' );
111
};
113
};
112
114
113
# Cleanup
115
# Cleanup
114
- 

Return to bug 24715