C4::Biblio::AddBiblioAndItems - added duplicate barcode check
Signed-off-by: Chris Cormack <crc@liblime.com> Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
parent
7d47666f7e
commit
f60f4987a3
1 changed files with 19 additions and 1 deletions
20
C4/Biblio.pm
20
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
|
||||
|
|
Loading…
Reference in a new issue