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 {
_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
$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')) {
$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