From f60f4987a3a102ec85351ce97db2e6ace638892d Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 25 Dec 2007 01:25:55 -0600 Subject: [PATCH] C4::Biblio::AddBiblioAndItems - added duplicate barcode check Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Biblio.pm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index f873a665e5..17da43ebff 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -242,6 +242,10 @@ The goal of this API is to have a similar effect to using AddBiblio and AddItems in succession, but without inefficient repeated parsing of the MARC XML bib record. +One functional difference is that the duplicate item barcode +check is implemented in this API, instead of relying on +the caller to do it, like AddItem does. + =cut sub AddBiblioAndItems { @@ -261,8 +265,9 @@ sub AddBiblioAndItems { _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber); # now we loop through the item tags and start creating items + my @bad_item_fields = (); my ($itemtag, $itemsubfield) = &GetMarcFromKohaField("items.itemnumber",''); - foreach my $item_field ($record->field($itemtag)) { + ITEMFIELD: foreach my $item_field ($record->field($itemtag)) { # we take the item field and stick it into a new # MARC record -- this is required so far because (FIXME) # TransformMarcToKoha requires a MARC::Record, not a MARC::Field @@ -275,6 +280,14 @@ sub AddBiblioAndItems { $item->{'biblionumber'} = $biblionumber; $item->{'biblioitemnumber'} = $biblioitemnumber; + # check for duplicate barcode + my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'}); + if ($duplicate_barcode) { + warn "ERROR: cannot add item $item->{'barcode'} for biblio $biblionumber: duplicate barcode\n"; + push @bad_item_fields, $item_field; + next ITEMFIELD; + } + # figure out what item type to use -- biblioitem-level or item-level my $itemtype; if (C4::Context->preference('item-level_itypes')) { @@ -321,6 +334,11 @@ sub AddBiblioAndItems { $item_field->replace_with($temp_item_marc->field($itemtag)); } + # remove any MARC item fields for rejected items + foreach my $item_field (@bad_item_fields) { + $record->delete_field($item_field); + } + # now add the record # FIXME - this paragraph copied from AddBiblio -- however, moved since # since we need to create the items row and plug in the itemnumbers in the -- 2.39.5