Lines 1085-1097
sub GetMarcSubfieldStructure {
Link Here
|
1085 |
return $cached if $cached; |
1085 |
return $cached if $cached; |
1086 |
|
1086 |
|
1087 |
my $dbh = C4::Context->dbh; |
1087 |
my $dbh = C4::Context->dbh; |
1088 |
my $subfield_structure = $dbh->selectall_hashref( q| |
1088 |
# We moved to selectall_arrayref since selectall_hashref does not |
|
|
1089 |
# keep duplicate mappings on kohafield (like place in 260 vs 264) |
1090 |
my $subfield_aref = $dbh->selectall_arrayref( q| |
1089 |
SELECT * |
1091 |
SELECT * |
1090 |
FROM marc_subfield_structure |
1092 |
FROM marc_subfield_structure |
1091 |
WHERE frameworkcode = ? |
1093 |
WHERE frameworkcode = ? |
1092 |
AND kohafield > '' |
1094 |
AND kohafield > '' |
1093 |
|, 'kohafield', {}, $frameworkcode ); |
1095 |
ORDER BY frameworkcode,tagfield,tagsubfield |
1094 |
|
1096 |
|, { Slice => {} }, $frameworkcode ); |
|
|
1097 |
# Now map the output to a hash structure |
1098 |
my $subfield_structure = {}; |
1099 |
foreach my $row ( @$subfield_aref ) { |
1100 |
push @{ $subfield_structure->{ $row->{kohafield} }}, $row; |
1101 |
} |
1095 |
$cache->set_in_cache( $cache_key, $subfield_structure ); |
1102 |
$cache->set_in_cache( $cache_key, $subfield_structure ); |
1096 |
return $subfield_structure; |
1103 |
return $subfield_structure; |
1097 |
} |
1104 |
} |
Lines 1109-1115
sub GetMarcFromKohaField {
Link Here
|
1109 |
my ( $kohafield, $frameworkcode ) = @_; |
1116 |
my ( $kohafield, $frameworkcode ) = @_; |
1110 |
return (0, undef) unless $kohafield; |
1117 |
return (0, undef) unless $kohafield; |
1111 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
1118 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
1112 |
return ( $mss->{$kohafield}{tagfield}, $mss->{$kohafield}{tagsubfield} ); |
1119 |
my @retval; |
|
|
1120 |
foreach( @{ $mss->{$kohafield} } ) { |
1121 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1122 |
} |
1123 |
return wantarray ? @retval : $retval[0]; |
1113 |
} |
1124 |
} |
1114 |
|
1125 |
|
1115 |
=head2 GetMarcSubfieldStructureFromKohaField |
1126 |
=head2 GetMarcSubfieldStructureFromKohaField |
Lines 1118-1123
sub GetMarcFromKohaField {
Link Here
|
1118 |
|
1129 |
|
1119 |
Returns a hashref where keys are marc_subfield_structure column names for the |
1130 |
Returns a hashref where keys are marc_subfield_structure column names for the |
1120 |
row where kohafield=$kohafield for the given framework code. |
1131 |
row where kohafield=$kohafield for the given framework code. |
|
|
1132 |
In list context returns a list of those hashrefs in case duplicate Koha to |
1133 |
MARC mappings exist. |
1121 |
|
1134 |
|
1122 |
$frameworkcode is optional. If not given, then the default framework is used. |
1135 |
$frameworkcode is optional. If not given, then the default framework is used. |
1123 |
|
1136 |
|
Lines 1129-1137
sub GetMarcSubfieldStructureFromKohaField {
Link Here
|
1129 |
return unless $kohafield; |
1142 |
return unless $kohafield; |
1130 |
|
1143 |
|
1131 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
1144 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
1132 |
return exists $mss->{$kohafield} |
1145 |
return unless $mss->{$kohafield}; |
1133 |
? $mss->{$kohafield} |
1146 |
return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; |
1134 |
: undef; |
|
|
1135 |
} |
1147 |
} |
1136 |
|
1148 |
|
1137 |
=head2 GetMarcBiblio |
1149 |
=head2 GetMarcBiblio |
Lines 2140-2160
entry from user entry
Link Here
|
2140 |
|
2152 |
|
2141 |
|
2153 |
|
2142 |
sub TransformKohaToMarc { |
2154 |
sub TransformKohaToMarc { |
2143 |
my $hash = shift; |
2155 |
my ( $hash, $frameworkcode, $params ) = @_; |
2144 |
my $record = MARC::Record->new(); |
2156 |
my $record = MARC::Record->new(); |
2145 |
SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); |
2157 |
SetMarcUnicodeFlag( $record, C4::Context->preference("marcflavour") ); |
2146 |
# FIXME Do not we want to get the marc subfield structure for the biblio framework? |
2158 |
# NOTE: Many older calls do not include a frameworkcode. In that case |
2147 |
my $mss = GetMarcSubfieldStructure(); |
2159 |
# we default to Default framework. |
|
|
2160 |
my $mss = GetMarcSubfieldStructure( $frameworkcode//'' ); |
2148 |
my $tag_hr = {}; |
2161 |
my $tag_hr = {}; |
2149 |
while ( my ($kohafield, $value) = each %$hash ) { |
2162 |
while ( my ($kohafield, $value) = each %$hash ) { |
2150 |
next unless exists $mss->{$kohafield}; |
2163 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
2151 |
next unless $mss->{$kohafield}; |
2164 |
my $tagfield = $fld->{tagfield}; |
2152 |
my $tagfield = $mss->{$kohafield}{tagfield} . ''; |
2165 |
my $tagsubfield = $fld->{tagsubfield}; |
2153 |
my $tagsubfield = $mss->{$kohafield}{tagsubfield}; |
2166 |
next if !$tagfield; |
2154 |
foreach my $value ( split(/\s?\|\s?/, $value, -1) ) { |
2167 |
my @values = $params->{no_split} |
2155 |
next if $value eq ''; |
2168 |
? ( $value ) |
2156 |
$tag_hr->{$tagfield} //= []; |
2169 |
: split(/\s?\|\s?/, $value, -1); |
2157 |
push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)]; |
2170 |
foreach my $value ( @values ) { |
|
|
2171 |
next if $value eq ''; |
2172 |
$tag_hr->{$tagfield} //= []; |
2173 |
push @{$tag_hr->{$tagfield}}, [($tagsubfield, $value)]; |
2174 |
} |
2158 |
} |
2175 |
} |
2159 |
} |
2176 |
} |
2160 |
foreach my $tag (sort keys %$tag_hr) { |
2177 |
foreach my $tag (sort keys %$tag_hr) { |
Lines 2542-2548
sub TransformMarcToKoha {
Link Here
|
2542 |
return $result; |
2559 |
return $result; |
2543 |
} |
2560 |
} |
2544 |
$limit_table = $limit_table || 0; |
2561 |
$limit_table = $limit_table || 0; |
2545 |
$frameworkcode = '' unless defined $frameworkcode; |
2562 |
$frameworkcode //= ''; |
2546 |
|
2563 |
|
2547 |
my $inverted_field_map = _get_inverted_marc_field_map($frameworkcode); |
2564 |
my $inverted_field_map = _get_inverted_marc_field_map($frameworkcode); |
2548 |
|
2565 |
|
Lines 2563-2576
sub TransformMarcToKoha {
Link Here
|
2563 |
my $kohafields = $inverted_field_map->{$tag}->{list}; |
2580 |
my $kohafields = $inverted_field_map->{$tag}->{list}; |
2564 |
ENTRY: foreach my $entry ( @{$kohafields} ) { |
2581 |
ENTRY: foreach my $entry ( @{$kohafields} ) { |
2565 |
my ( $subfield, $table, $column ) = @{$entry}; |
2582 |
my ( $subfield, $table, $column ) = @{$entry}; |
|
|
2583 |
my $value = $field->data; |
2566 |
next ENTRY unless exists $tables{$table}; |
2584 |
next ENTRY unless exists $tables{$table}; |
|
|
2585 |
next ENTRY if !$value; |
2567 |
my $key = _disambiguate( $table, $column ); |
2586 |
my $key = _disambiguate( $table, $column ); |
2568 |
if ( $result->{$key} ) { |
2587 |
if ( $result->{$key} ) { |
2569 |
unless ( ( $key eq "biblionumber" or $key eq "biblioitemnumber" ) and ( $field->data() eq "" ) ) { |
2588 |
$result->{$key} .= " | " . $value |
2570 |
$result->{$key} .= " | " . $field->data(); |
2589 |
unless $result->{$key} eq $value; |
2571 |
} |
|
|
2572 |
} else { |
2590 |
} else { |
2573 |
$result->{$key} = $field->data(); |
2591 |
$result->{$key} = $value; |
2574 |
} |
2592 |
} |
2575 |
} |
2593 |
} |
2576 |
} else { |
2594 |
} else { |
Lines 2583-2593
sub TransformMarcToKoha {
Link Here
|
2583 |
SFENTRY: foreach my $entry ( @{ $inverted_field_map->{$tag}->{sfs}->{$code} } ) { |
2601 |
SFENTRY: foreach my $entry ( @{ $inverted_field_map->{$tag}->{sfs}->{$code} } ) { |
2584 |
my ( $table, $column ) = @{$entry}; |
2602 |
my ( $table, $column ) = @{$entry}; |
2585 |
next SFENTRY unless exists $tables{$table}; |
2603 |
next SFENTRY unless exists $tables{$table}; |
|
|
2604 |
next SFENTRY if !$value; |
2586 |
my $key = _disambiguate( $table, $column ); |
2605 |
my $key = _disambiguate( $table, $column ); |
2587 |
if ( $result->{$key} ) { |
2606 |
if ( $result->{$key} ) { |
2588 |
unless ( ( $key eq "biblionumber" or $key eq "biblioitemnumber" ) and ( $value eq "" ) ) { |
2607 |
$result->{$key} .= " | " . $value |
2589 |
$result->{$key} .= " | " . $value; |
2608 |
unless $result->{$key} eq $value; |
2590 |
} |
|
|
2591 |
} else { |
2609 |
} else { |
2592 |
$result->{$key} = $value; |
2610 |
$result->{$key} = $value; |
2593 |
} |
2611 |
} |
Lines 2628-2639
sub _get_inverted_marc_field_map {
Link Here
|
2628 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
2646 |
my $mss = GetMarcSubfieldStructure( $frameworkcode ); |
2629 |
|
2647 |
|
2630 |
foreach my $kohafield ( keys %{ $mss } ) { |
2648 |
foreach my $kohafield ( keys %{ $mss } ) { |
2631 |
next unless exists $mss->{$kohafield}; # not all columns are mapped to MARC tag & subfield |
2649 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
2632 |
my $tag = $mss->{$kohafield}{tagfield}; |
2650 |
my $tag = $fld->{tagfield}; |
2633 |
my $subfield = $mss->{$kohafield}{tagsubfield}; |
2651 |
my $subfield = $fld->{tagsubfield}; |
2634 |
my ( $table, $column ) = split /[.]/, $kohafield, 2; |
2652 |
my ( $table, $column ) = split /[.]/, $kohafield, 2; |
2635 |
push @{ $field_map->{$tag}->{list} }, [ $subfield, $table, $column ]; |
2653 |
push @{ $field_map->{$tag}->{list} }, |
2636 |
push @{ $field_map->{$tag}->{sfs}->{$subfield} }, [ $table, $column ]; |
2654 |
[ $subfield, $table, $column ]; |
|
|
2655 |
push @{ $field_map->{$tag}->{sfs}->{$subfield} }, |
2656 |
[ $table, $column ]; |
2657 |
} |
2637 |
} |
2658 |
} |
2638 |
return $field_map; |
2659 |
return $field_map; |
2639 |
} |
2660 |
} |
Lines 2686-2803
sub _disambiguate {
Link Here
|
2686 |
|
2707 |
|
2687 |
} |
2708 |
} |
2688 |
|
2709 |
|
2689 |
=head2 get_koha_field_from_marc |
|
|
2690 |
|
2691 |
$result->{_disambiguate($table, $field)} = |
2692 |
get_koha_field_from_marc($table,$field,$record,$frameworkcode); |
2693 |
|
2694 |
Internal function to map data from the MARC record to a specific non-MARC field. |
2695 |
FIXME: this is meant to replace TransformMarcToKohaOneField after more testing. |
2696 |
|
2697 |
=cut |
2698 |
|
2699 |
sub get_koha_field_from_marc { |
2700 |
my ( $koha_table, $koha_column, $record, $frameworkcode ) = @_; |
2701 |
my ( $tagfield, $subfield ) = GetMarcFromKohaField( $koha_table . '.' . $koha_column, $frameworkcode ); |
2702 |
my $kohafield; |
2703 |
foreach my $field ( $record->field($tagfield) ) { |
2704 |
if ( $field->tag() < 10 ) { |
2705 |
if ($kohafield) { |
2706 |
$kohafield .= " | " . $field->data(); |
2707 |
} else { |
2708 |
$kohafield = $field->data(); |
2709 |
} |
2710 |
} else { |
2711 |
if ( $field->subfields ) { |
2712 |
my @subfields = $field->subfields(); |
2713 |
foreach my $subfieldcount ( 0 .. $#subfields ) { |
2714 |
if ( $subfields[$subfieldcount][0] eq $subfield ) { |
2715 |
if ($kohafield) { |
2716 |
$kohafield .= " | " . $subfields[$subfieldcount][1]; |
2717 |
} else { |
2718 |
$kohafield = $subfields[$subfieldcount][1]; |
2719 |
} |
2720 |
} |
2721 |
} |
2722 |
} |
2723 |
} |
2724 |
} |
2725 |
return $kohafield; |
2726 |
} |
2727 |
|
2728 |
=head2 TransformMarcToKohaOneField |
2710 |
=head2 TransformMarcToKohaOneField |
2729 |
|
2711 |
|
2730 |
$result = TransformMarcToKohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode ) |
2712 |
$value = TransformMarcToKohaOneField( 'biblio.title', $record, $frameworkcode ); |
2731 |
|
2713 |
|
2732 |
=cut |
2714 |
=cut |
2733 |
|
2715 |
|
2734 |
sub TransformMarcToKohaOneField { |
2716 |
sub TransformMarcToKohaOneField { |
2735 |
|
2717 |
my ( $kohafield, $marc, $frameworkcode ) = @_; |
2736 |
# FIXME ? if a field has a repeatable subfield that is used in old-db, |
2718 |
|
2737 |
# only the 1st will be retrieved... |
2719 |
# It is not really useful to repeat all code from TransformMarcToKoha here. |
2738 |
my ( $kohatable, $kohafield, $record, $result, $frameworkcode ) = @_; |
2720 |
# Since it is fast enough (by caching), we just extract the field. |
2739 |
my $res = ""; |
2721 |
my $koharec = TransformMarcToKoha( $marc, $frameworkcode ); |
2740 |
my ( $tagfield, $subfield ) = GetMarcFromKohaField( $kohatable . "." . $kohafield, $frameworkcode ); |
2722 |
my @temp = split /\./, $kohafield, 2; |
2741 |
foreach my $field ( $record->field($tagfield) ) { |
2723 |
$kohafield = _disambiguate( @temp ) if @temp > 1; |
2742 |
if ( $field->tag() < 10 ) { |
2724 |
return $koharec ? $koharec->{$kohafield} : undef; |
2743 |
if ( $result->{$kohafield} ) { |
|
|
2744 |
$result->{$kohafield} .= " | " . $field->data(); |
2745 |
} else { |
2746 |
$result->{$kohafield} = $field->data(); |
2747 |
} |
2748 |
} else { |
2749 |
if ( $field->subfields ) { |
2750 |
my @subfields = $field->subfields(); |
2751 |
foreach my $subfieldcount ( 0 .. $#subfields ) { |
2752 |
if ( $subfields[$subfieldcount][0] eq $subfield ) { |
2753 |
if ( $result->{$kohafield} ) { |
2754 |
$result->{$kohafield} .= " | " . $subfields[$subfieldcount][1]; |
2755 |
} else { |
2756 |
$result->{$kohafield} = $subfields[$subfieldcount][1]; |
2757 |
} |
2758 |
} |
2759 |
} |
2760 |
} |
2761 |
} |
2762 |
} |
2763 |
return $result; |
2764 |
} |
2725 |
} |
2765 |
|
2726 |
|
2766 |
|
|
|
2767 |
#" |
2768 |
|
2769 |
# |
2770 |
# true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates |
2771 |
# at the same time |
2772 |
# replaced by a zebraqueue table, that is filled with ModZebra to run. |
2773 |
# the table is emptied by misc/cronjobs/zebraqueue_start.pl script |
2774 |
# =head2 ModZebrafiles |
2775 |
# |
2776 |
# &ModZebrafiles( $dbh, $biblionumber, $record, $folder, $server ); |
2777 |
# |
2778 |
# =cut |
2779 |
# |
2780 |
# sub ModZebrafiles { |
2781 |
# |
2782 |
# my ( $dbh, $biblionumber, $record, $folder, $server ) = @_; |
2783 |
# |
2784 |
# my $op; |
2785 |
# my $zebradir = |
2786 |
# C4::Context->zebraconfig($server)->{directory} . "/" . $folder . "/"; |
2787 |
# unless ( opendir( DIR, "$zebradir" ) ) { |
2788 |
# warn "$zebradir not found"; |
2789 |
# return; |
2790 |
# } |
2791 |
# closedir DIR; |
2792 |
# my $filename = $zebradir . $biblionumber; |
2793 |
# |
2794 |
# if ($record) { |
2795 |
# open( OUTPUT, ">", $filename . ".xml" ); |
2796 |
# print OUTPUT $record; |
2797 |
# close OUTPUT; |
2798 |
# } |
2799 |
# } |
2800 |
|
2801 |
=head2 ModZebra |
2727 |
=head2 ModZebra |
2802 |
|
2728 |
|
2803 |
ModZebra( $biblionumber, $op, $server, $record ); |
2729 |
ModZebra( $biblionumber, $op, $server, $record ); |