From 29b62b63a37bdab8f66010bebbc4e44e8d8012e7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 19 May 2022 20:10:35 +0000 Subject: [PATCH] Bug 30813: Adjust TransformMarcToKoha to take kohafields parameter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Joonas Kylmälä Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- C4/Biblio.pm | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 24eef00a08..90cc4382fd 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -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; } -- 2.39.5