|
Lines 344-350
sub ModBiblio {
Link Here
|
| 344 |
|
344 |
|
| 345 |
=head2 _strip_item_fields |
345 |
=head2 _strip_item_fields |
| 346 |
|
346 |
|
| 347 |
_strip_item_fields($record, $frameworkcode) |
347 |
_strip_item_fields($record) |
| 348 |
|
348 |
|
| 349 |
Utility routine to remove item tags from a |
349 |
Utility routine to remove item tags from a |
| 350 |
MARC bib. |
350 |
MARC bib. |
|
Lines 355-361
sub _strip_item_fields {
Link Here
|
| 355 |
my $record = shift; |
355 |
my $record = shift; |
| 356 |
my $frameworkcode = shift; |
356 |
my $frameworkcode = shift; |
| 357 |
# get the items before and append them to the biblio before updating the record, atm we just have the biblio |
357 |
# get the items before and append them to the biblio before updating the record, atm we just have the biblio |
| 358 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
358 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); |
| 359 |
|
359 |
|
| 360 |
# delete any item fields from incoming record to avoid |
360 |
# delete any item fields from incoming record to avoid |
| 361 |
# duplication or incorrect data - use AddItem() or ModItem() |
361 |
# duplication or incorrect data - use AddItem() or ModItem() |
|
Lines 1053-1066
sub GetMarcSubfieldStructure {
Link Here
|
| 1053 |
sub GetMarcFromKohaField { |
1053 |
sub GetMarcFromKohaField { |
| 1054 |
my ( $kohafield ) = @_; |
1054 |
my ( $kohafield ) = @_; |
| 1055 |
return unless $kohafield; |
1055 |
return unless $kohafield; |
| 1056 |
# The next call uses the Default framework since it is AUTHORITATIVE |
1056 |
|
| 1057 |
# for all Koha to MARC mappings. |
1057 |
my $cache = Koha::Caches->get_instance(); |
| 1058 |
my $mss = GetMarcSubfieldStructure( '' ); # Do not change framework |
1058 |
my $cache_key = "MarcFromKohaField-$kohafield"; |
| 1059 |
my @retval; |
1059 |
my $cached = $cache->get_from_cache($cache_key); |
| 1060 |
foreach( @{ $mss->{$kohafield} } ) { |
1060 |
if ( !defined $cached ) { |
| 1061 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
1061 |
# The next call uses the Default framework since it is AUTHORITATIVE |
| 1062 |
} |
1062 |
# for all Koha to MARC mappings. |
| 1063 |
return wantarray ? @retval : ( @retval ? $retval[0] : undef ); |
1063 |
my $mss = GetMarcSubfieldStructure( '' ); # Do not change framework |
|
|
1064 |
my @retval; |
| 1065 |
foreach( @{ $mss->{$kohafield} } ) { |
| 1066 |
push @retval, $_->{tagfield}, $_->{tagsubfield}; |
| 1067 |
} |
| 1068 |
$cached = \@retval; |
| 1069 |
$cache->set_in_cache( $cache_key, $cached ); |
| 1070 |
} |
| 1071 |
return wantarray ? @$cached : ( @$cached ? $cached->[0] : undef ); |
| 1064 |
} |
1072 |
} |
| 1065 |
|
1073 |
|
| 1066 |
=head2 GetMarcSubfieldStructureFromKohaField |
1074 |
=head2 GetMarcSubfieldStructureFromKohaField |
|
Lines 1137-1146
sub GetMarcBiblio {
Link Here
|
| 1137 |
return; |
1145 |
return; |
| 1138 |
} |
1146 |
} |
| 1139 |
|
1147 |
|
| 1140 |
my $dbh = C4::Context->dbh; |
1148 |
# Use state to speed up repeated calls in batch processes |
| 1141 |
my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? "); |
1149 |
state $sth = C4::Context->dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=? "); |
| 1142 |
$sth->execute($biblionumber); |
1150 |
$sth->execute($biblionumber); |
| 1143 |
my $row = $sth->fetchrow_hashref; |
1151 |
my $row = $sth->fetchrow_hashref; |
|
|
1152 |
$sth->finish; |
| 1144 |
my $biblioitemnumber = $row->{'biblioitemnumber'}; |
1153 |
my $biblioitemnumber = $row->{'biblioitemnumber'}; |
| 1145 |
my $marcxml = GetXmlBiblio( $biblionumber ); |
1154 |
my $marcxml = GetXmlBiblio( $biblionumber ); |
| 1146 |
$marcxml = StripNonXmlChars( $marcxml ); |
1155 |
$marcxml = StripNonXmlChars( $marcxml ); |
|
Lines 1179-1195
The XML should only contain biblio information (item information is no longer st
Link Here
|
| 1179 |
|
1188 |
|
| 1180 |
sub GetXmlBiblio { |
1189 |
sub GetXmlBiblio { |
| 1181 |
my ($biblionumber) = @_; |
1190 |
my ($biblionumber) = @_; |
| 1182 |
my $dbh = C4::Context->dbh; |
|
|
| 1183 |
return unless $biblionumber; |
1191 |
return unless $biblionumber; |
| 1184 |
my ($marcxml) = $dbh->selectrow_array( |
1192 |
|
|
|
1193 |
# Use state to speed up repeated calls in batch processes |
| 1194 |
state $sth = C4::Context->dbh->prepare( |
| 1185 |
q| |
1195 |
q| |
| 1186 |
SELECT metadata |
1196 |
SELECT metadata |
| 1187 |
FROM biblio_metadata |
1197 |
FROM biblio_metadata |
| 1188 |
WHERE biblionumber=? |
1198 |
WHERE biblionumber=? |
| 1189 |
AND format='marcxml' |
1199 |
AND format='marcxml' |
| 1190 |
AND marcflavour=? |
1200 |
AND marcflavour=? |
| 1191 |
|, undef, $biblionumber, C4::Context->preference('marcflavour') |
1201 |
| |
| 1192 |
); |
1202 |
); |
|
|
1203 |
|
| 1204 |
$sth->execute( $biblionumber, C4::Context->preference('marcflavour') ); |
| 1205 |
my ($marcxml) = $sth->fetchrow(); |
| 1206 |
$sth->finish; |
| 1193 |
return $marcxml; |
1207 |
return $marcxml; |
| 1194 |
} |
1208 |
} |
| 1195 |
|
1209 |
|
|
Lines 2090-2099
sub UpsertMarcControlField {
Link Here
|
| 2090 |
|
2104 |
|
| 2091 |
sub GetFrameworkCode { |
2105 |
sub GetFrameworkCode { |
| 2092 |
my ($biblionumber) = @_; |
2106 |
my ($biblionumber) = @_; |
| 2093 |
my $dbh = C4::Context->dbh; |
2107 |
# Use state to speed up repeated calls in batch processes |
| 2094 |
my $sth = $dbh->prepare("SELECT frameworkcode FROM biblio WHERE biblionumber=?"); |
2108 |
state $sth = C4::Context->dbh->prepare("SELECT frameworkcode FROM biblio WHERE biblionumber=?"); |
| 2095 |
$sth->execute($biblionumber); |
2109 |
$sth->execute($biblionumber); |
| 2096 |
my ($frameworkcode) = $sth->fetchrow; |
2110 |
my ($frameworkcode) = $sth->fetchrow; |
|
|
2111 |
$sth->finish; |
| 2097 |
return $frameworkcode; |
2112 |
return $frameworkcode; |
| 2098 |
} |
2113 |
} |
| 2099 |
|
2114 |
|
|
Lines 2756-2791
sub EmbedItemsInMarcBiblio {
Link Here
|
| 2756 |
|
2771 |
|
| 2757 |
$itemnumbers = [] unless defined $itemnumbers; |
2772 |
$itemnumbers = [] unless defined $itemnumbers; |
| 2758 |
|
2773 |
|
| 2759 |
my $frameworkcode = GetFrameworkCode($biblionumber); |
2774 |
_strip_item_fields($marc); |
| 2760 |
_strip_item_fields($marc, $frameworkcode); |
2775 |
|
|
|
2776 |
my $hidingrules = {}; |
| 2777 |
my $yaml = $opac ? C4::Context->preference('OpacHiddenItems') : ''; |
| 2778 |
if ( $yaml =~ /\S/ ) { |
| 2779 |
$yaml = "$yaml\n\n"; # YAML is anal on ending \n. Surplus does not hurt |
| 2780 |
eval { |
| 2781 |
$hidingrules = YAML::Load($yaml); |
| 2782 |
}; |
| 2783 |
if ($@) { |
| 2784 |
carp "Unable to parse OpacHiddenItems syspref : $@"; |
| 2785 |
} |
| 2786 |
} |
| 2761 |
|
2787 |
|
| 2762 |
# ... and embed the current items |
|
|
| 2763 |
my $dbh = C4::Context->dbh; |
| 2764 |
my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); |
| 2765 |
$sth->execute($biblionumber); |
| 2766 |
my @item_fields; |
| 2767 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); |
| 2768 |
my @items; |
| 2769 |
my $opachiddenitems = $opac |
| 2770 |
&& ( C4::Context->preference('OpacHiddenItems') !~ /^\s*$/ ); |
| 2771 |
require C4::Items; |
2788 |
require C4::Items; |
| 2772 |
while ( my ($itemnumber) = $sth->fetchrow_array ) { |
2789 |
|
| 2773 |
next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers; |
2790 |
my $item_fields = C4::Items::GetMarcItemFields( $biblionumber, $itemnumbers, $hidingrules ); |
| 2774 |
my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef; |
2791 |
|
| 2775 |
push @items, { itemnumber => $itemnumber, item => $i }; |
2792 |
$marc->append_fields(@$item_fields) if ( @$item_fields ); |
| 2776 |
} |
|
|
| 2777 |
my @hiddenitems = |
| 2778 |
$opachiddenitems |
| 2779 |
? C4::Items::GetHiddenItemnumbers( map { $_->{item} } @items ) |
| 2780 |
: (); |
| 2781 |
# Convert to a hash for quick searching |
| 2782 |
my %hiddenitems = map { $_ => 1 } @hiddenitems; |
| 2783 |
foreach my $itemnumber ( map { $_->{itemnumber} } @items ) { |
| 2784 |
next if $hiddenitems{$itemnumber}; |
| 2785 |
my $item_marc = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); |
| 2786 |
push @item_fields, $item_marc->field($itemtag); |
| 2787 |
} |
| 2788 |
$marc->append_fields(@item_fields); |
| 2789 |
} |
2793 |
} |
| 2790 |
|
2794 |
|
| 2791 |
=head1 INTERNAL FUNCTIONS |
2795 |
=head1 INTERNAL FUNCTIONS |