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

(-)a/C4/Biblio.pm (-10 / +11 lines)
Lines 1169-1192 sub GetMarcSubfieldStructure { Link Here
1169
1169
1170
=head2 GetMarcFromKohaField
1170
=head2 GetMarcFromKohaField
1171
1171
1172
    ( $field,$subfield ) = GetMarcFromKohaField( $kohafield );
1172
    my ( $field, $subfield )    = GetMarcFromKohaField($kohafield);
1173
    @fields = GetMarcFromKohaField( $kohafield );
1173
    my ( $f1, $sf1, $f2, $sf2 ) = GetMarcFromKohaField($kohafield);
1174
    $field = GetMarcFromKohaField( $kohafield );
1175
1174
1176
    Returns the MARC fields & subfields mapped to $kohafield.
1175
    Returns list of MARC fields and subfields mapped to $kohafield.
1177
    Since the Default framework is considered as authoritative for such
1176
    Since the Default framework is considered as authoritative for such
1178
    mappings, the former frameworkcode parameter is obsoleted.
1177
    mappings, the former frameworkcode parameter is obsoleted.
1179
1178
1180
    In list context all mappings are returned; there can be multiple
1179
    NOTE: There may be multiple mappings! In the first example above
1181
    mappings. Note that in the above example you could miss a second
1180
    you could miss the second mapping (altough only a few of these
1182
    mappings in the first call.
1181
    will normally exist).
1183
    In scalar context only the field tag of the first mapping is returned.
1182
    Calling in scalar context has been deprecated as of 10/2023.
1184
1183
1185
=cut
1184
=cut
1186
1185
1187
sub GetMarcFromKohaField {
1186
sub GetMarcFromKohaField {
1188
    my ( $kohafield ) = @_;
1187
    my ($kohafield) = @_;
1188
    warn "GetMarcFromKohaField: framework parameter has been obsoleted for long" if @_ > 1;    # TODO Remove later
1189
    return unless $kohafield;
1189
    return unless $kohafield;
1190
1190
    # The next call uses the Default framework since it is AUTHORITATIVE
1191
    # The next call uses the Default framework since it is AUTHORITATIVE
1191
    # for all Koha to MARC mappings.
1192
    # for all Koha to MARC mappings.
1192
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
1193
    my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
Lines 1194-1200 sub GetMarcFromKohaField { Link Here
1194
    foreach( @{ $mss->{$kohafield} } ) {
1195
    foreach( @{ $mss->{$kohafield} } ) {
1195
        push @retval, $_->{tagfield}, $_->{tagsubfield};
1196
        push @retval, $_->{tagfield}, $_->{tagsubfield};
1196
    }
1197
    }
1197
    return wantarray ? @retval : ( @retval ? $retval[0] : undef );
1198
    return @retval;
1198
}
1199
}
1199
1200
1200
=head2 GetMarcSubfieldStructureFromKohaField
1201
=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