Lines 1089-1101
sub GetMarcSubfieldStructure {
Link Here
|
1089 |
return $cached if $cached; |
1089 |
return $cached if $cached; |
1090 |
|
1090 |
|
1091 |
my $dbh = C4::Context->dbh; |
1091 |
my $dbh = C4::Context->dbh; |
1092 |
my $subfield_structure = $dbh->selectall_hashref( q| |
1092 |
# We moved to selectall_arrayref since selectall_hashref does not |
|
|
1093 |
# keep duplicate mappings on kohafield (like place in 260 vs 264) |
1094 |
my $subfield_aref = $dbh->selectall_arrayref( q| |
1093 |
SELECT * |
1095 |
SELECT * |
1094 |
FROM marc_subfield_structure |
1096 |
FROM marc_subfield_structure |
1095 |
WHERE frameworkcode = ? |
1097 |
WHERE frameworkcode = ? |
1096 |
AND kohafield > '' |
1098 |
AND kohafield > '' |
1097 |
|, 'kohafield', {}, $frameworkcode ); |
1099 |
ORDER BY frameworkcode,tagfield,tagsubfield |
1098 |
|
1100 |
|, { Slice => {} }, $frameworkcode ); |
|
|
1101 |
# Now map the output to a hash structure |
1102 |
my $subfield_structure = {}; |
1103 |
foreach my $row ( @$subfield_aref ) { |
1104 |
push @{ $subfield_structure->{ $row->{kohafield} }}, $row; |
1105 |
} |
1099 |
$cache->set_in_cache( $cache_key, $subfield_structure ); |
1106 |
$cache->set_in_cache( $cache_key, $subfield_structure ); |
1100 |
return $subfield_structure; |
1107 |
return $subfield_structure; |
1101 |
} |
1108 |
} |
Lines 1113-1119
sub GetMarcFromKohaField {
Link Here
|
1113 |
my ( $kohafield, $frameworkcode ) = @_; |
1120 |
my ( $kohafield, $frameworkcode ) = @_; |
1114 |
return (0, undef) unless $kohafield; |
1121 |
return (0, undef) unless $kohafield; |
1115 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
1122 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
1116 |
return ( $mss->{$kohafield}{tagfield}, $mss->{$kohafield}{tagsubfield} ); |
1123 |
my @retval; |
|
|
1124 |
foreach( @{ $mss->{$kohafield} } ) { |
1125 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1126 |
} |
1127 |
return wantarray ? @retval : $retval[0]; |
1117 |
} |
1128 |
} |
1118 |
|
1129 |
|
1119 |
=head2 GetMarcSubfieldStructureFromKohaField |
1130 |
=head2 GetMarcSubfieldStructureFromKohaField |
Lines 1122-1127
sub GetMarcFromKohaField {
Link Here
|
1122 |
|
1133 |
|
1123 |
Returns a hashref where keys are marc_subfield_structure column names for the |
1134 |
Returns a hashref where keys are marc_subfield_structure column names for the |
1124 |
row where kohafield=$kohafield for the given framework code. |
1135 |
row where kohafield=$kohafield for the given framework code. |
|
|
1136 |
In list context returns a list of those hashrefs in case duplicate Koha to |
1137 |
MARC mappings exist. |
1125 |
|
1138 |
|
1126 |
$frameworkcode is optional. If not given, then the default framework is used. |
1139 |
$frameworkcode is optional. If not given, then the default framework is used. |
1127 |
|
1140 |
|
Lines 1133-1141
sub GetMarcSubfieldStructureFromKohaField {
Link Here
|
1133 |
return unless $kohafield; |
1146 |
return unless $kohafield; |
1134 |
|
1147 |
|
1135 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
1148 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
1136 |
return exists $mss->{$kohafield} |
1149 |
return unless $mss->{$kohafield}; |
1137 |
? $mss->{$kohafield} |
1150 |
return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; |
1138 |
: undef; |
|
|
1139 |
} |
1151 |
} |
1140 |
|
1152 |
|
1141 |
=head2 GetMarcBiblio |
1153 |
=head2 GetMarcBiblio |
Lines 2158-2178
entry from user entry
Link Here
|
2158 |
|
2170 |
|
2159 |
|
2171 |
|
2160 |
sub TransformKohaToMarc { |
2172 |
sub TransformKohaToMarc { |
2161 |
my $hash = shift; |
2173 |
my ( $hash, $frameworkcode, $params ) = @_; |
2162 |
my $record = MARC::Record->new(); |
2174 |
my $record = MARC::Record->new(); |
2163 |
SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); |
2175 |
SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); |
2164 |
# FIXME Do not we want to get the marc subfield structure for the biblio framework? |
2176 |
# NOTE: Many older calls do not include a frameworkcode. In that case |
2165 |
my $mss = GetMarcSubfieldStructure(); |
2177 |
# we default to Default framework. |
|
|
2178 |
my $mss = GetMarcSubfieldStructure( $frameworkcode//'' ); |
2166 |
my $tag_hr = {}; |
2179 |
my $tag_hr = {}; |
2167 |
while ( my ($kohafield, $value) = each %$hash ) { |
2180 |
while ( my ($kohafield, $value) = each %$hash ) { |
2168 |
next unless exists $mss->{$kohafield}; |
2181 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
2169 |
next unless $mss->{$kohafield}; |
2182 |
my $tagfield = $fld->{tagfield}; |
2170 |
my $tagfield = $mss->{$kohafield}{tagfield} . ''; |
2183 |
my $tagsubfield = $fld->{tagsubfield}; |
2171 |
my $tagsubfield = $mss->{$kohafield}{tagsubfield}; |
2184 |
next if !$tagfield; |
2172 |
foreach my $value ( split(/\s?\|\s?/, $value, -1) ) { |
2185 |
my @values = $params->{no_split} |
2173 |
next if $value eq ''; |
2186 |
? ( $value ) |
2174 |
$tag_hr->{$tagfield} //= []; |
2187 |
: split(/\s?\|\s?/, $value, -1); |
2175 |
push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)]; |
2188 |
foreach my $value ( @values ) { |
|
|
2189 |
next if $value eq ''; |
2190 |
$tag_hr->{$tagfield} //= []; |
2191 |
push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)]; |
2192 |
} |
2176 |
} |
2193 |
} |
2177 |
} |
2194 |
} |
2178 |
foreach my $tag (sort keys %$tag_hr) { |
2195 |
foreach my $tag (sort keys %$tag_hr) { |
Lines 2560-2566
sub TransformMarcToKoha {
Link Here
|
2560 |
return $result; |
2577 |
return $result; |
2561 |
} |
2578 |
} |
2562 |
$limit_table = $limit_table || 0; |
2579 |
$limit_table = $limit_table || 0; |
2563 |
$frameworkcode = '' unless defined $frameworkcode; |
2580 |
$frameworkcode //= ''; |
2564 |
|
2581 |
|
2565 |
my $inverted_field_map = _get_inverted_marc_field_map($frameworkcode); |
2582 |
my $inverted_field_map = _get_inverted_marc_field_map($frameworkcode); |
2566 |
|
2583 |
|
Lines 2581-2594
sub TransformMarcToKoha {
Link Here
|
2581 |
my $kohafields = $inverted_field_map->{$tag}->{list}; |
2598 |
my $kohafields = $inverted_field_map->{$tag}->{list}; |
2582 |
ENTRY: foreach my $entry ( @{$kohafields} ) { |
2599 |
ENTRY: foreach my $entry ( @{$kohafields} ) { |
2583 |
my ( $subfield, $table, $column ) = @{$entry}; |
2600 |
my ( $subfield, $table, $column ) = @{$entry}; |
|
|
2601 |
my $value = $field->data; |
2584 |
next ENTRY unless exists $tables{$table}; |
2602 |
next ENTRY unless exists $tables{$table}; |
|
|
2603 |
next ENTRY if !$value; |
2585 |
my $key = _disambiguate( $table, $column ); |
2604 |
my $key = _disambiguate( $table, $column ); |
2586 |
if ( $result->{$key} ) { |
2605 |
if ( $result->{$key} ) { |
2587 |
unless ( ( $key eq "biblionumber" or $key eq "biblioitemnumber" ) and ( $field->data() eq "" ) ) { |
2606 |
$result->{$key} .= " | " . $value |
2588 |
$result->{$key} .= " | " . $field->data(); |
2607 |
unless $result->{$key} eq $value; |
2589 |
} |
|
|
2590 |
} else { |
2608 |
} else { |
2591 |
$result->{$key} = $field->data(); |
2609 |
$result->{$key} = $value; |
2592 |
} |
2610 |
} |
2593 |
} |
2611 |
} |
2594 |
} else { |
2612 |
} else { |
Lines 2601-2611
sub TransformMarcToKoha {
Link Here
|
2601 |
SFENTRY: foreach my $entry ( @{ $inverted_field_map->{$tag}->{sfs}->{$code} } ) { |
2619 |
SFENTRY: foreach my $entry ( @{ $inverted_field_map->{$tag}->{sfs}->{$code} } ) { |
2602 |
my ( $table, $column ) = @{$entry}; |
2620 |
my ( $table, $column ) = @{$entry}; |
2603 |
next SFENTRY unless exists $tables{$table}; |
2621 |
next SFENTRY unless exists $tables{$table}; |
|
|
2622 |
next SFENTRY if !$value; |
2604 |
my $key = _disambiguate( $table, $column ); |
2623 |
my $key = _disambiguate( $table, $column ); |
2605 |
if ( $result->{$key} ) { |
2624 |
if ( $result->{$key} ) { |
2606 |
unless ( ( $key eq "biblionumber" or $key eq "biblioitemnumber" ) and ( $value eq "" ) ) { |
2625 |
$result->{$key} .= " | " . $value |
2607 |
$result->{$key} .= " | " . $value; |
2626 |
unless $result->{$key} eq $value; |
2608 |
} |
|
|
2609 |
} else { |
2627 |
} else { |
2610 |
$result->{$key} = $value; |
2628 |
$result->{$key} = $value; |
2611 |
} |
2629 |
} |
Lines 2646-2657
sub _get_inverted_marc_field_map {
Link Here
|
2646 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
2664 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
2647 |
|
2665 |
|
2648 |
foreach my $kohafield ( keys %{ $mss } ) { |
2666 |
foreach my $kohafield ( keys %{ $mss } ) { |
2649 |
next unless exists $mss->{$kohafield}; # not all columns are mapped to MARC tag & subfield |
2667 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
2650 |
my $tag = $mss->{$kohafield}{tagfield}; |
2668 |
my $tag = $fld->{tagfield}; |
2651 |
my $subfield = $mss->{$kohafield}{tagsubfield}; |
2669 |
my $subfield = $fld->{tagsubfield}; |
2652 |
my ( $table, $column ) = split /[.]/, $kohafield, 2; |
2670 |
my ( $table, $column ) = split /[.]/, $kohafield, 2; |
2653 |
push @{ $field_map->{$tag}->{list} }, [ $subfield, $table, $column ]; |
2671 |
push @{ $field_map->{$tag}->{list} }, |
2654 |
push @{ $field_map->{$tag}->{sfs}->{$subfield} }, [ $table, $column ]; |
2672 |
[ $subfield, $table, $column ]; |
|
|
2673 |
push @{ $field_map->{$tag}->{sfs}->{$subfield} }, |
2674 |
[ $table, $column ]; |
2675 |
} |
2655 |
} |
2676 |
} |
2656 |
return $field_map; |
2677 |
return $field_map; |
2657 |
} |
2678 |
} |
Lines 2704-2821
sub _disambiguate {
Link Here
|
2704 |
|
2725 |
|
2705 |
} |
2726 |
} |
2706 |
|
2727 |
|
2707 |
=head2 get_koha_field_from_marc |
|
|
2708 |
|
2709 |
$result->{_disambiguate($table, $field)} = |
2710 |
get_koha_field_from_marc($table,$field,$record,$frameworkcode); |
2711 |
|
2712 |
Internal function to map data from the MARC record to a specific non-MARC field. |
2713 |
FIXME: this is meant to replace TransformMarcToKohaOneField after more testing. |
2714 |
|
2715 |
=cut |
2716 |
|
2717 |
sub get_koha_field_from_marc { |
2718 |
my ( $koha_table, $koha_column, $record, $frameworkcode ) = @_; |
2719 |
my ( $tagfield, $subfield ) = GetMarcFromKohaField( $koha_table . '.' . $koha_column, $frameworkcode ); |
2720 |
my $kohafield; |
2721 |
foreach my $field ( $record->field($tagfield) ) { |
2722 |
if ( $field->tag() < 10 ) { |
2723 |
if ($kohafield) { |
2724 |
$kohafield .= " | " . $field->data(); |
2725 |
} else { |
2726 |
$kohafield = $field->data(); |
2727 |
} |
2728 |
} else { |
2729 |
if ( $field->subfields ) { |
2730 |
my @subfields = $field->subfields(); |
2731 |
foreach my $subfieldcount ( 0 .. $#subfields ) { |
2732 |
if ( $subfields[$subfieldcount][0] eq $subfield ) { |
2733 |
if ($kohafield) { |
2734 |
$kohafield .= " | " . $subfields[$subfieldcount][1]; |
2735 |
} else { |
2736 |
$kohafield = $subfields[$subfieldcount][1]; |
2737 |
} |
2738 |
} |
2739 |
} |
2740 |
} |
2741 |
} |
2742 |
} |
2743 |
return $kohafield; |
2744 |
} |
2745 |
|
2746 |
=head2 TransformMarcToKohaOneField |
2728 |
=head2 TransformMarcToKohaOneField |
2747 |
|
2729 |
|
2748 |
$result = TransformMarcToKohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode ) |
2730 |
$value = TransformMarcToKohaOneField( 'biblio.title', $record, $frameworkcode ); |
2749 |
|
2731 |
|
2750 |
=cut |
2732 |
=cut |
2751 |
|
2733 |
|
2752 |
sub TransformMarcToKohaOneField { |
2734 |
sub TransformMarcToKohaOneField { |
2753 |
|
2735 |
my ( $kohafield, $marc, $frameworkcode ) = @_; |
2754 |
# FIXME ? if a field has a repeatable subfield that is used in old-db, |
2736 |
|
2755 |
# only the 1st will be retrieved... |
2737 |
# It is not really useful to repeat all code from TransformMarcToKoha here. |
2756 |
my ( $kohatable, $kohafield, $record, $result, $frameworkcode ) = @_; |
2738 |
# Since it is fast enough (by caching), we just extract the field. |
2757 |
my $res = ""; |
2739 |
my $koharec = TransformMarcToKoha( $marc, $frameworkcode ); |
2758 |
my ( $tagfield, $subfield ) = GetMarcFromKohaField( $kohatable . "." . $kohafield, $frameworkcode ); |
2740 |
my @temp = split /\./, $kohafield, 2; |
2759 |
foreach my $field ( $record->field($tagfield) ) { |
2741 |
$kohafield = _disambiguate( @temp ) if @temp > 1; |
2760 |
if ( $field->tag() < 10 ) { |
2742 |
return $koharec ? $koharec->{$kohafield} : undef; |
2761 |
if ( $result->{$kohafield} ) { |
|
|
2762 |
$result->{$kohafield} .= " | " . $field->data(); |
2763 |
} else { |
2764 |
$result->{$kohafield} = $field->data(); |
2765 |
} |
2766 |
} else { |
2767 |
if ( $field->subfields ) { |
2768 |
my @subfields = $field->subfields(); |
2769 |
foreach my $subfieldcount ( 0 .. $#subfields ) { |
2770 |
if ( $subfields[$subfieldcount][0] eq $subfield ) { |
2771 |
if ( $result->{$kohafield} ) { |
2772 |
$result->{$kohafield} .= " | " . $subfields[$subfieldcount][1]; |
2773 |
} else { |
2774 |
$result->{$kohafield} = $subfields[$subfieldcount][1]; |
2775 |
} |
2776 |
} |
2777 |
} |
2778 |
} |
2779 |
} |
2780 |
} |
2781 |
return $result; |
2782 |
} |
2743 |
} |
2783 |
|
2744 |
|
2784 |
|
|
|
2785 |
#" |
2786 |
|
2787 |
# |
2788 |
# true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates |
2789 |
# at the same time |
2790 |
# replaced by a zebraqueue table, that is filled with ModZebra to run. |
2791 |
# the table is emptied by misc/cronjobs/zebraqueue_start.pl script |
2792 |
# =head2 ModZebrafiles |
2793 |
# |
2794 |
# &ModZebrafiles( $dbh, $biblionumber, $record, $folder, $server ); |
2795 |
# |
2796 |
# =cut |
2797 |
# |
2798 |
# sub ModZebrafiles { |
2799 |
# |
2800 |
# my ( $dbh, $biblionumber, $record, $folder, $server ) = @_; |
2801 |
# |
2802 |
# my $op; |
2803 |
# my $zebradir = |
2804 |
# C4::Context->zebraconfig($server)->{directory} . "/" . $folder . "/"; |
2805 |
# unless ( opendir( DIR, "$zebradir" ) ) { |
2806 |
# warn "$zebradir not found"; |
2807 |
# return; |
2808 |
# } |
2809 |
# closedir DIR; |
2810 |
# my $filename = $zebradir . $biblionumber; |
2811 |
# |
2812 |
# if ($record) { |
2813 |
# open( OUTPUT, ">", $filename . ".xml" ); |
2814 |
# print OUTPUT $record; |
2815 |
# close OUTPUT; |
2816 |
# } |
2817 |
# } |
2818 |
|
2819 |
=head2 ModZebra |
2745 |
=head2 ModZebra |
2820 |
|
2746 |
|
2821 |
ModZebra( $biblionumber, $op, $server, $record ); |
2747 |
ModZebra( $biblionumber, $op, $server, $record ); |