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

(-)a/C4/Biblio.pm (-10 / +11 lines)
Lines 1161-1184 sub GetMarcSubfieldStructure { Link Here
1161
1161
1162
=head2 GetMarcFromKohaField
1162
=head2 GetMarcFromKohaField
1163
1163
1164
    ( $field,$subfield ) = GetMarcFromKohaField( $kohafield );
1164
    my ( $field, $subfield )    = GetMarcFromKohaField($kohafield);
1165
    @fields = GetMarcFromKohaField( $kohafield );
1165
    my ( $f1, $sf1, $f2, $sf2 ) = GetMarcFromKohaField($kohafield);
1166
    $field = GetMarcFromKohaField( $kohafield );
1167
1166
1168
    Returns the MARC fields & subfields mapped to $kohafield.
1167
    Returns list of MARC fields and subfields mapped to $kohafield.
1169
    Since the Default framework is considered as authoritative for such
1168
    Since the Default framework is considered as authoritative for such
1170
    mappings, the former frameworkcode parameter is obsoleted.
1169
    mappings, the former frameworkcode parameter is obsoleted.
1171
1170
1172
    In list context all mappings are returned; there can be multiple
1171
    NOTE: There may be multiple mappings! In the first example above
1173
    mappings. Note that in the above example you could miss a second
1172
    you could miss the second mapping (altough only a few of these
1174
    mappings in the first call.
1173
    will normally exist).
1175
    In scalar context only the field tag of the first mapping is returned.
1174
    Calling in scalar context has been deprecated as of 10/2023.
1176
1175
1177
=cut
1176
=cut
1178
1177
1179
sub GetMarcFromKohaField {
1178
sub GetMarcFromKohaField {
1180
    my ( $kohafield ) = @_;
1179
    my ($kohafield) = @_;
1180
    warn "GetMarcFromKohaField: framework parameter has been obsoleted for long" if @_ > 1;    # TODO Remove later
1181
    return unless $kohafield;
1181
    return unless $kohafield;
1182
1182
    # The next call uses the Default framework since it is AUTHORITATIVE
1183
    # The next call uses the Default framework since it is AUTHORITATIVE
1183
    # for all Koha to MARC mappings.
1184
    # for all Koha to MARC mappings.
1184
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1185
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
Lines 1186-1192 sub GetMarcFromKohaField { Link Here
1186
    foreach( @{ $mss->{$kohafield} } ) {
1187
    foreach( @{ $mss->{$kohafield} } ) {
1187
        push @retval, $_->{tagfield}, $_->{tagsubfield};
1188
        push @retval, $_->{tagfield}, $_->{tagsubfield};
1188
    }
1189
    }
1189
    return wantarray ? @retval : ( @retval ? $retval[0] : undef );
1190
    return @retval;
1190
}
1191
}
1191
1192
1192
=head2 GetMarcSubfieldStructureFromKohaField
1193
=head2 GetMarcSubfieldStructureFromKohaField
(-)a/t/db_dependent/Biblio.t (-16 / +10 lines)
Lines 157-165 subtest "GetMarcSubfieldStructure" => sub { Link Here
157
};
157
};
158
158
159
subtest "GetMarcFromKohaField" => sub {
159
subtest "GetMarcFromKohaField" => sub {
160
    plan tests => 8;
160
    plan tests => 7;
161
161
162
    #NOTE: We are building on data from the previous subtest
162
    # NOTE: We are building on data from the previous subtest
163
    # With: field 399 / mytable.nicepages
163
    # With: field 399 / mytable.nicepages
164
164
165
    # Check call in list context for multiple mappings
165
    # Check call in list context for multiple mappings
Lines 171-189 subtest "GetMarcFromKohaField" => sub { Link Here
171
    is( $retval[3], 'b', 'Check second subfield' );
171
    is( $retval[3], 'b', 'Check second subfield' );
172
172
173
    # Check same call in scalar context
173
    # Check same call in scalar context
174
    is( C4::Biblio::GetMarcFromKohaField('mytable.nicepages'), '399',
174
    is( C4::Biblio::GetMarcFromKohaField('mytable.nicepages'), 4,
175
        'GetMarcFromKohaField returns first tag in scalar context' );
175
        'GetMarcFromKohaField returns list count in scalar context' );
176
176
177
    # Bug 19096 Default is authoritative
177
    # Check for warning about obsoleted framework parameter
178
    # If we add a new empty framework, we should still get the mappings
178
    warning_like
179
    # from Default. CAUTION: This test passes intentionally the obsoleted
179
        { @retval = C4::Biblio::GetMarcFromKohaField( 'mytable.nicepages', 1 ) }
180
    # framework parameter.
180
        qr/obsoleted for long/,
181
    my $new_fw = t::lib::TestBuilder->new->build({source => 'BiblioFramework'});
181
        'Found warning about obsoleted parameter';
182
    @retval = C4::Biblio::GetMarcFromKohaField(
183
        'mytable.nicepages', $new_fw->{frameworkcode},
184
    );
185
    is( @retval, 4, 'Still got two pairs of tags/subfields' );
186
    is( $retval[0].$retval[1], '399a', 'Including 399a' );
187
};
182
};
188
183
189
subtest "Authority creation with default linker" => sub {
184
subtest "Authority creation with default linker" => sub {
190
- 

Return to bug 19097