From 2810216e7e0851f5e1b84ce2fa428680d6151bc3 Mon Sep 17 00:00:00 2001 From: simith Date: Thu, 14 Aug 2014 13:34:28 -0400 Subject: [PATCH] Bug 6681 - When importing a biblio record via Z39.50, authority links also get imported --- C4/Biblio.pm | 36 ++++++++++++++++++++++++++++++++++++ acqui/neworderempty.pl | 6 ++---- cataloguing/addbiblio.pl | 3 ++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index d465cf6..ec405b1 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -136,6 +136,7 @@ BEGIN { &TransformHtmlToMarc &TransformHtmlToXml prepare_host_field + &RemoveItemsAndAuthidsFromRecord ); } @@ -2777,6 +2778,41 @@ sub get_koha_field_from_marc { return $kohafield; } +=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 + if ( $marcflavour eq "MARC21" ) { + 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 (@heading) { + foreach my $field ($record->field($_)) { + $field->delete_subfield(code => '9'); + unless($field->subfields()) { + $record->delete_field($field); + } + } + } + } +} + =head2 TransformMarcToKohaOneField $result = TransformMarcToKohaOneField( $kohatable, $kohafield, $record, $result, $frameworkcode ) diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 256175a..57e12b1 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -145,10 +145,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 5b06706..368323b 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -795,7 +795,8 @@ if (($biblionumber) && !($breedingid)){ $record = GetMarcBiblio($biblionumber); } if ($breedingid) { - ( $record, $encoding ) = MARCfindbreeding( $breedingid ) ; + ( $record, $encoding ) = MARCfindbreeding( $breedingid ); + RemoveItemsAndAuthidsFromRecord($record, $frameworkcode) if $record; } #populate hostfield if hostbiblionumber is available -- 1.9.1