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

(-)a/C4/Biblio.pm (-8 / +13 lines)
Lines 1993-1998 sub TransformKohaToMarc { Link Here
1993
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # do not change framework
1993
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # do not change framework
1994
    my $mss2; # belongs to $params->{framework} only filled when needed
1994
    my $mss2; # belongs to $params->{framework} only filled when needed
1995
    my $tag_hr = {};
1995
    my $tag_hr = {};
1996
    my $need_split;
1996
    while ( my ($kohafield, $value) = each %$hash ) {
1997
    while ( my ($kohafield, $value) = each %$hash ) {
1997
        foreach my $fld ( @{ $mss->{$kohafield} } ) {
1998
        foreach my $fld ( @{ $mss->{$kohafield} } ) {
1998
            my $tagfield    = $fld->{tagfield};
1999
            my $tagfield    = $fld->{tagfield};
Lines 2000-2006 sub TransformKohaToMarc { Link Here
2000
            next if !$tagfield;
2001
            next if !$tagfield;
2001
2002
2002
            # BZ 21800: split value if field is repeatable.
2003
            # BZ 21800: split value if field is repeatable.
2003
            my @values = _check_split($params, $mss2, $fld, $value)
2004
            ( $need_split, $mss2 ) = _check_split($params, $mss2, $fld, $value);
2005
            my @values = $need_split
2004
                ? split(/\s?\|\s?/, $value, -1)
2006
                ? split(/\s?\|\s?/, $value, -1)
2005
                : ( $value );
2007
                : ( $value );
2006
            foreach my $value ( @values ) {
2008
            foreach my $value ( @values ) {
Lines 2024-2045 sub TransformKohaToMarc { Link Here
2024
}
2026
}
2025
2027
2026
sub _check_split {
2028
sub _check_split {
2029
# Checks if $value must be split; may consult passed framework
2030
# Returns 0|1, and framework hash if consulted
2027
    my ($params, $mss2, $fld, $value) = @_;
2031
    my ($params, $mss2, $fld, $value) = @_;
2028
    return if index($value,'|') == -1; # nothing to worry about
2032
    return (0, $mss2) if index($value,'|') == -1; # nothing to worry about
2029
    return if $params->{no_split};
2033
    return (0, $mss2) if $params->{no_split};
2030
2034
2031
    # if we did not get a specific framework, check default in $mss
2035
    # if we did not get a specific framework, check default in $mss
2032
    return $fld->{repeatable} if !$params->{framework};
2036
    return ( $fld->{repeatable}, $mss2) if !$params->{framework};
2033
2037
2034
    # here we need to check the specific framework
2038
    # here we need to check the specific framework
2035
    $mss2 = GetMarcSubfieldStructure($params->{framework}, { unsafe => 1 })
2039
    if(!$mss2) {
2036
        if !$mss2;
2040
        $mss2 = GetMarcSubfieldStructure($params->{framework}, { unsafe => 1 });
2041
    }
2037
    foreach my $fld2 ( @{ $mss2->{ $fld->{kohafield} } } ) {
2042
    foreach my $fld2 ( @{ $mss2->{ $fld->{kohafield} } } ) {
2038
        next if $fld2->{tagfield} ne $fld->{tagfield};
2043
        next if $fld2->{tagfield} ne $fld->{tagfield};
2039
        next if $fld2->{tagsubfield} ne $fld->{tagsubfield};
2044
        next if $fld2->{tagsubfield} ne $fld->{tagsubfield};
2040
        return 1 if $fld2->{repeatable};
2045
        return (1, $mss2) if $fld2->{repeatable};
2041
    }
2046
    }
2042
    return;
2047
    return (0, $mss2);
2043
}
2048
}
2044
2049
2045
=head2 PrepHostMarcField
2050
=head2 PrepHostMarcField
(-)a/t/db_dependent/Biblio/TransformKohaToMarc.t (-2 / +3 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 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