From 060c742b3dcdcb4eafe4fa59c72ec4a9de3601dd Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 8 Sep 2016 12:06:05 +0200 Subject: [PATCH] Bug 6852: Staged import reports wrong success for items Content-Type: text/plain; charset=utf-8 If we import items that have a wrong branch code, the items will not be imported but manage-marc-import reports them as imported. (A wrong branch code probably occurs most, but other causes are possible too.) The underlying cause is that AddItem does not look at the error returned from _koha_new_item in Items.pm. This patch deals with that omission in the most economical way. It adjusts AddItem so that it returns undef if no item was added. In ImportBatch.pm I check if an item was added and adjust the totals accordingly instead of just always counting them. Note: Several scripts like additem.pl use AddItemFromMarc to call AddItem. They do not report an error, but fail silently. With this patch, these scripts get undef and will still fail silently. (No change.) Adding error checks around calls of AddItemFromMarc is outside the scope of this report. Here we are taking care of correct imported item numbers. Test plan: [1] Verify that additem.pl still works by adding a new item. [2] Run t/db_dependent/Items.t [3] Add a new branchcode, say XXX. [4] Pick a biblio record with a few items (n) and set one item to branch XXX. [5] Export this biblio with items to a MARC file. [6] Change the XXX item to the original branch and remove branch XXX. [7] Import the MARC file. Verify that one item was not imported and that the number of imported items reflects that (equals n-1). --- C4/ImportBatch.pm | 14 ++++++++------ C4/Items.pm | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 046b859..2ecd96b 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -792,12 +792,14 @@ sub BatchCommitItems { $num_items_errored++; } else { my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber ); - $updsth->bind_param( 1, 'imported' ); - $updsth->bind_param( 2, $itemnumber ); - $updsth->bind_param( 3, $row->{'import_items_id'} ); - $updsth->execute(); - $updsth->finish(); - $num_items_added++; + if( $itemnumber ) { + $updsth->bind_param( 1, 'imported' ); + $updsth->bind_param( 2, $itemnumber ); + $updsth->bind_param( 3, $row->{'import_items_id'} ); + $updsth->execute(); + $updsth->finish(); + $num_items_added++; + } } } diff --git a/C4/Items.pm b/C4/Items.pm index 2f31897..d379989 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -309,6 +309,9 @@ sub AddItem { } my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} ); + if( $error ) { + return; + } $item->{'itemnumber'} = $itemnumber; ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver" ); -- 1.7.10.4