From 39f805031bf5bcb9ab4d805a39c5d133152ccbb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick=20Capovilla?= Date: Fri, 23 Dec 2011 10:38:50 -0500 Subject: [PATCH] Remove Koha-specific fields from records imported via Z39.50 - Corrected RemoveItemsAndAuthidsFromRecord should now use the system preferences. --- C4/Biblio.pm | 38 ++++++++++++++++++++++++++++++++++++++ acqui/neworderempty.pl | 6 ++---- cataloguing/addbiblio.pl | 1 + 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 4a9735f..6125083 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -133,6 +133,7 @@ BEGIN { &TransformHtmlToXml &PrepareItemrecordDisplay &GetNoZebraIndexes + &RemoveItemsAndAuthidsFromRecord ); } @@ -2831,6 +2832,43 @@ sub GetNoZebraIndexes { return %indexes; } +=head2 RemoveItemsAndAuthidsFromRecord + + RemoveItemsAndAuthidsFromRecord($record); + + Remove all items (952) from the record. + Also removes all authids (subfield 9 in headings) + +=cut + +sub RemoveItemsAndAuthidsFromRecord { + my $record = shift; + my $frameworkcode = shift || ''; + + my $marcflavour = C4::Context->preference("marcflavour"); + my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); + + # Remove all the items from the record + foreach my $item ($record->field($itemtag)) { + $record->delete_field($item); + } + + # Remove all authid links ($9) in the record (MARC21 Version) + if ( $marcflavour eq "MARC21" ) { + foreach my $heading qw(100 110 111 130 440 600 610 611 630 648 650 651 655 700 710 711 730 800 810 811 830) { + foreach my $field ($record->field($heading)) { + $field->delete_subfield(code => '9'); + unless($field->subfields()) { + $record->delete_field($field); + } + } + } + } + + # TODO : Add code to remove authority links for other marcflavours + +} + =head2 EmbedItemsInMarcBiblio EmbedItemsInMarcBiblio($marc, $biblionumber); diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 6361125..7b1d46f 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -132,10 +132,8 @@ if ( $ordernumber eq '' and defined $params->{'breedingid'}){ my ($marcrecord, $encoding) = MARCfindbreeding($params->{'breedingid'}); die("Could not find the selected record in the reservoir, bailing") unless $marcrecord; - # Remove all the items (952) from the imported record - foreach my $item ($marcrecord->field('952')) { - $marcrecord->delete_field($item); - } + # Do a cleanup on the imported record + RemoveItemsAndAuthidsFromRecord($marcrecord, $params->{'frameworkcode'}); my $duplicatetitle; #look for duplicates diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index 1a82989..f6b6e04 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -909,6 +909,7 @@ if (($biblionumber) && !($breedingid)){ } if ($breedingid) { ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ; + RemoveItemsAndAuthidsFromRecord($record, $frameworkcode) if $record; } #populate hostfield if hostbiblionumber is available if ($hostbiblionumber){ -- 1.7.2.5