Lines 1074-1091
sub GetUsedMarcStructure {
Link Here
|
1074 |
return $sth->fetchall_arrayref( {} ); |
1074 |
return $sth->fetchall_arrayref( {} ); |
1075 |
} |
1075 |
} |
1076 |
|
1076 |
|
|
|
1077 |
=pod |
1078 |
|
1077 |
=head2 GetMarcSubfieldStructure |
1079 |
=head2 GetMarcSubfieldStructure |
1078 |
|
1080 |
|
|
|
1081 |
my $structure = GetMarcSubfieldStructure($frameworkcode, [$params]); |
1082 |
|
1083 |
Returns a reference to hash representing MARC subfield structure |
1084 |
for framework with framework code C<$frameworkcode>, C<$params> is |
1085 |
optional and may contain additional options. |
1086 |
|
1087 |
=over 4 |
1088 |
|
1089 |
=item C<$frameworkcode> |
1090 |
|
1091 |
The framework code. |
1092 |
|
1093 |
=item C<$params> |
1094 |
|
1095 |
An optional hash reference with additional options. |
1096 |
The following options are supported: |
1097 |
|
1098 |
=over 4 |
1099 |
|
1100 |
=item unsafe |
1101 |
|
1102 |
Pass { unsafe => 1 } do disable cached object cloning, |
1103 |
and instead get a shared reference, resulting in better |
1104 |
performance (but care must be taken so that retured object |
1105 |
is never modified). |
1106 |
|
1107 |
Note: If you call GetMarcSubfieldStructure with unsafe => 1, do not modify or |
1108 |
even autovivify its contents. It is a cached/shared data structure. Your |
1109 |
changes would be passed around in subsequent calls. |
1110 |
|
1111 |
=back |
1112 |
|
1079 |
=cut |
1113 |
=cut |
1080 |
|
1114 |
|
1081 |
sub GetMarcSubfieldStructure { |
1115 |
sub GetMarcSubfieldStructure { |
1082 |
my ( $frameworkcode ) = @_; |
1116 |
my ( $frameworkcode, $params ) = @_; |
1083 |
|
1117 |
|
1084 |
$frameworkcode //= ''; |
1118 |
$frameworkcode //= ''; |
1085 |
|
1119 |
|
1086 |
my $cache = Koha::Caches->get_instance(); |
1120 |
my $cache = Koha::Caches->get_instance(); |
1087 |
my $cache_key = "MarcSubfieldStructure-$frameworkcode"; |
1121 |
my $cache_key = "MarcSubfieldStructure-$frameworkcode"; |
1088 |
my $cached = $cache->get_from_cache($cache_key); |
1122 |
my $cached = $cache->get_from_cache($cache_key, { unsafe => ($params && $params->{unsafe}) }); |
1089 |
return $cached if $cached; |
1123 |
return $cached if $cached; |
1090 |
|
1124 |
|
1091 |
my $dbh = C4::Context->dbh; |
1125 |
my $dbh = C4::Context->dbh; |
Lines 1129-1135
sub GetMarcFromKohaField {
Link Here
|
1129 |
return unless $kohafield; |
1163 |
return unless $kohafield; |
1130 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1164 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1131 |
# for all Koha to MARC mappings. |
1165 |
# for all Koha to MARC mappings. |
1132 |
my $mss = GetMarcSubfieldStructure( '' ); # Do not change framework |
1166 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
1133 |
my @retval; |
1167 |
my @retval; |
1134 |
foreach( @{ $mss->{$kohafield} } ) { |
1168 |
foreach( @{ $mss->{$kohafield} } ) { |
1135 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1169 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
Lines 1156-1162
sub GetMarcSubfieldStructureFromKohaField {
Link Here
|
1156 |
|
1190 |
|
1157 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1191 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1158 |
# for all Koha to MARC mappings. |
1192 |
# for all Koha to MARC mappings. |
1159 |
my $mss = GetMarcSubfieldStructure(''); # Do not change framework |
1193 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
1160 |
return unless $mss->{$kohafield}; |
1194 |
return unless $mss->{$kohafield}; |
1161 |
return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; |
1195 |
return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; |
1162 |
} |
1196 |
} |
Lines 2188-2194
sub TransformKohaToMarc {
Link Here
|
2188 |
|
2222 |
|
2189 |
# In the next call we use the Default framework, since it is considered |
2223 |
# In the next call we use the Default framework, since it is considered |
2190 |
# authoritative for Koha to Marc mappings. |
2224 |
# authoritative for Koha to Marc mappings. |
2191 |
my $mss = GetMarcSubfieldStructure( '' ); # do not change framework |
2225 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # do not change framewok |
2192 |
my $tag_hr = {}; |
2226 |
my $tag_hr = {}; |
2193 |
while ( my ($kohafield, $value) = each %$hash ) { |
2227 |
while ( my ($kohafield, $value) = each %$hash ) { |
2194 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
2228 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
Lines 2601-2607
sub TransformMarcToKoha {
Link Here
|
2601 |
|
2635 |
|
2602 |
# The next call acknowledges Default as the authoritative framework |
2636 |
# The next call acknowledges Default as the authoritative framework |
2603 |
# for Koha to MARC mappings. |
2637 |
# for Koha to MARC mappings. |
2604 |
my $mss = GetMarcSubfieldStructure(''); # Do not change framework |
2638 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
2605 |
foreach my $kohafield ( keys %{ $mss } ) { |
2639 |
foreach my $kohafield ( keys %{ $mss } ) { |
2606 |
my ( $table, $column ) = split /[.]/, $kohafield, 2; |
2640 |
my ( $table, $column ) = split /[.]/, $kohafield, 2; |
2607 |
next unless $tables{$table}; |
2641 |
next unless $tables{$table}; |
2608 |
- |
|
|