Lines 1000-1017
sub GetUsedMarcStructure {
Link Here
|
1000 |
return $sth->fetchall_arrayref( {} ); |
1000 |
return $sth->fetchall_arrayref( {} ); |
1001 |
} |
1001 |
} |
1002 |
|
1002 |
|
|
|
1003 |
=pod |
1004 |
|
1003 |
=head2 GetMarcSubfieldStructure |
1005 |
=head2 GetMarcSubfieldStructure |
1004 |
|
1006 |
|
|
|
1007 |
my $structure = GetMarcSubfieldStructure($frameworkcode, [$params]); |
1008 |
|
1009 |
Returns a reference to hash representing MARC subfield structure |
1010 |
for framework with framework code C<$frameworkcode>, C<$params> is |
1011 |
optional and may contain additional options. |
1012 |
|
1013 |
=over 4 |
1014 |
|
1015 |
=item C<$frameworkcode> |
1016 |
|
1017 |
The framework code. |
1018 |
|
1019 |
=item C<$params> |
1020 |
|
1021 |
An optional hash reference with additional options. |
1022 |
The following options are supported: |
1023 |
|
1024 |
=over 4 |
1025 |
|
1026 |
=item unsafe |
1027 |
|
1028 |
Pass { unsafe => 1 } do disable cached object cloning, |
1029 |
and instead get a shared reference, resulting in better |
1030 |
performance (but care must be taken so that retured object |
1031 |
is never modified). |
1032 |
|
1033 |
Note: If you call GetMarcSubfieldStructure with unsafe => 1, do not modify or |
1034 |
even autovivify its contents. It is a cached/shared data structure. Your |
1035 |
changes would be passed around in subsequent calls. |
1036 |
|
1037 |
=back |
1038 |
|
1005 |
=cut |
1039 |
=cut |
1006 |
|
1040 |
|
1007 |
sub GetMarcSubfieldStructure { |
1041 |
sub GetMarcSubfieldStructure { |
1008 |
my ( $frameworkcode ) = @_; |
1042 |
my ( $frameworkcode, $params ) = @_; |
1009 |
|
1043 |
|
1010 |
$frameworkcode //= ''; |
1044 |
$frameworkcode //= ''; |
1011 |
|
1045 |
|
1012 |
my $cache = Koha::Caches->get_instance(); |
1046 |
my $cache = Koha::Caches->get_instance(); |
1013 |
my $cache_key = "MarcSubfieldStructure-$frameworkcode"; |
1047 |
my $cache_key = "MarcSubfieldStructure-$frameworkcode"; |
1014 |
my $cached = $cache->get_from_cache($cache_key); |
1048 |
my $cached = $cache->get_from_cache($cache_key, { unsafe => ($params && $params->{unsafe}) }); |
1015 |
return $cached if $cached; |
1049 |
return $cached if $cached; |
1016 |
|
1050 |
|
1017 |
my $dbh = C4::Context->dbh; |
1051 |
my $dbh = C4::Context->dbh; |
Lines 1055-1061
sub GetMarcFromKohaField {
Link Here
|
1055 |
return unless $kohafield; |
1089 |
return unless $kohafield; |
1056 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1090 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1057 |
# for all Koha to MARC mappings. |
1091 |
# for all Koha to MARC mappings. |
1058 |
my $mss = GetMarcSubfieldStructure( '' ); # Do not change framework |
1092 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
1059 |
my @retval; |
1093 |
my @retval; |
1060 |
foreach( @{ $mss->{$kohafield} } ) { |
1094 |
foreach( @{ $mss->{$kohafield} } ) { |
1061 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1095 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
Lines 1082-1088
sub GetMarcSubfieldStructureFromKohaField {
Link Here
|
1082 |
|
1116 |
|
1083 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1117 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1084 |
# for all Koha to MARC mappings. |
1118 |
# for all Koha to MARC mappings. |
1085 |
my $mss = GetMarcSubfieldStructure(''); # Do not change framework |
1119 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
1086 |
return unless $mss->{$kohafield}; |
1120 |
return unless $mss->{$kohafield}; |
1087 |
return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; |
1121 |
return wantarray ? @{$mss->{$kohafield}} : $mss->{$kohafield}->[0]; |
1088 |
} |
1122 |
} |
Lines 2118-2124
sub TransformKohaToMarc {
Link Here
|
2118 |
|
2152 |
|
2119 |
# In the next call we use the Default framework, since it is considered |
2153 |
# In the next call we use the Default framework, since it is considered |
2120 |
# authoritative for Koha to Marc mappings. |
2154 |
# authoritative for Koha to Marc mappings. |
2121 |
my $mss = GetMarcSubfieldStructure( '' ); # do not change framework |
2155 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # do not change framewok |
2122 |
my $tag_hr = {}; |
2156 |
my $tag_hr = {}; |
2123 |
while ( my ($kohafield, $value) = each %$hash ) { |
2157 |
while ( my ($kohafield, $value) = each %$hash ) { |
2124 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
2158 |
foreach my $fld ( @{ $mss->{$kohafield} } ) { |
Lines 2536-2542
sub TransformMarcToKoha {
Link Here
|
2536 |
|
2570 |
|
2537 |
# The next call acknowledges Default as the authoritative framework |
2571 |
# The next call acknowledges Default as the authoritative framework |
2538 |
# for Koha to MARC mappings. |
2572 |
# for Koha to MARC mappings. |
2539 |
my $mss = GetMarcSubfieldStructure(''); # Do not change framework |
2573 |
my $mss = GetMarcSubfieldStructure( '', { unsafe => 1 } ); # Do not change framework |
2540 |
foreach my $kohafield ( keys %{ $mss } ) { |
2574 |
foreach my $kohafield ( keys %{ $mss } ) { |
2541 |
my ( $table, $column ) = split /[.]/, $kohafield, 2; |
2575 |
my ( $table, $column ) = split /[.]/, $kohafield, 2; |
2542 |
next unless $tables{$table}; |
2576 |
next unless $tables{$table}; |
2543 |
- |
|
|