From 4bf861136d13670d6c41a0e36afade5cba63f1a5 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 23 May 2022 12:26:42 +0000 Subject: [PATCH] Bug 30831: Store error in import_error column To test: 1 - Export a record with items from the catalog 2 - Stage the record for import 3 - Import the batch 4 - Silent failure? Batch stuck in 'importing 5 - Bonus points/QA team, otherwise skip: Stage again, go to manage batch, before clicking 'Import this batch' a - Right click and inspect the submit button b - Scroll to
element c - Right click and 'Edit as HTML' d - Add '?runinbackground=0' to form action e - Delete the hidden input for 'runinbackground' a few lines down f - Click 'Import' g - Error: [Mon May 23 10:47:43.583448 2022] [cgi:error] [pid 3114] [client 172.18.0.1:60936] AH01215: C4::ImportBatch::BatchCommitItems(): DBI Exception: DBD::mysql::st execute failed: Incorrect integer value: 'duplicate item barcode' for column `koha_kohadev`.`import_items`.`itemnumber` at row 1 at /kohadevbox/koha/C4/ImportBatch.pm line 652: /kohadevbox/koha/tools/manage-marc-import.pl, referer: http://localhost:8081/cgi-bin/koha/tools/manage-marc-import.pl?import_batch_id=2 6 - Apply patch 7 - Stage and import record again 8 - Import success! 9 - Note results report 'Number of items ignored because of duplicate barcode' equal to number of items on record --- C4/ImportBatch.pm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index e0dd051491..956c957ebf 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -770,13 +770,14 @@ sub BatchCommitItems { my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} }); my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); - my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); + my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); if ( $action eq "replace" && $duplicate_itemnumber ) { # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} ); $updsth->bind_param( 1, 'imported' ); $updsth->bind_param( 2, $item->{itemnumber} ); - $updsth->bind_param( 3, $row->{'import_items_id'} ); + $updsth->bind_param( 3, undef ); + $updsth->bind_param( 4, $row->{'import_items_id'} ); $updsth->execute(); $updsth->finish(); $num_items_replaced++; @@ -785,14 +786,16 @@ sub BatchCommitItems { ModItemFromMarc( $item_marc, $biblionumber, $itemnumber ); $updsth->bind_param( 1, 'imported' ); $updsth->bind_param( 2, $item->{itemnumber} ); - $updsth->bind_param( 3, $row->{'import_items_id'} ); + $updsth->bind_param( 3, undef ); + $updsth->bind_param( 4, $row->{'import_items_id'} ); $updsth->execute(); $updsth->finish(); $num_items_replaced++; } elsif ($duplicate_barcode) { $updsth->bind_param( 1, 'error' ); - $updsth->bind_param( 2, 'duplicate item barcode' ); - $updsth->bind_param( 3, $row->{'import_items_id'} ); + $updsth->bind_param( 2, undef ); + $updsth->bind_param( 3, 'duplicate item barcode' ); + $updsth->bind_param( 4, $row->{'import_items_id'} ); $updsth->execute(); $num_items_errored++; } else { @@ -804,7 +807,8 @@ sub BatchCommitItems { if( $itemnumber ) { $updsth->bind_param( 1, 'imported' ); $updsth->bind_param( 2, $itemnumber ); - $updsth->bind_param( 3, $row->{'import_items_id'} ); + $updsth->bind_param( 3, undef ); + $updsth->bind_param( 4, $row->{'import_items_id'} ); $updsth->execute(); $updsth->finish(); $num_items_added++; -- 2.30.2