Bug 30813: Adjust TransformMarcToKoha to take kohafields parameter

This adjusts the routine to accept an arrayref of koha fields to process

To test:
prove -v t/db_dependent/Biblio/TransformMarcToKoha.t t/Biblio.t

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2022-05-19 20:10:35 +00:00 committed by Tomas Cohen Arazi
parent ee669178f6
commit 29b62b63a3
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 26 additions and 4 deletions

View File

@ -2307,6 +2307,7 @@ sub TransformMarcToKoha {
my $record = $params->{record};
my $limit_table = $params->{limit_table} // q{};
my $kohafields = $params->{kohafields};
my $result = {};
if (!defined $record) {
@ -2324,13 +2325,34 @@ sub TransformMarcToKoha {
# The next call acknowledges Default as the authoritative framework
# for Koha to MARC mappings.
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework
foreach my $kohafield ( keys %{ $mss } ) {
@{$kohafields} = keys %{ $mss } unless $kohafields;
foreach my $kohafield ( @{$kohafields} ) {
my ( $table, $column ) = split /[.]/, $kohafield, 2;
next unless $tables{$table};
my $val = TransformMarcToKohaOneField( $kohafield, $record );
next if !defined $val;
my ( $value, @values );
foreach my $fldhash ( @{$mss->{$kohafield}} ) {
my $tag = $fldhash->{tagfield};
my $sub = $fldhash->{tagsubfield};
foreach my $fld ( $record->field($tag) ) {
if( $sub eq '@' || $fld->is_control_field ) {
push @values, $fld->data if $fld->data;
} else {
push @values, grep { $_ } $fld->subfield($sub);
}
}
}
if ( @values ){
$value = join ' | ', uniq(@values);
# Additional polishing for individual kohafields
if( $kohafield =~ /copyrightdate|publicationyear/ ) {
$value = _adjust_pubyear( $value );
}
}
next if !defined $value;
my $key = _disambiguate( $table, $column );
$result->{$key} = $val;
$result->{$key} = $value;
}
return $result;
}