From fceb2b70f1f227b066bc6279a31f6da33202c9a2 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 2 Jul 2013 11:17:57 -0400 Subject: [PATCH] Bug 9231 - Batch revert staged MARC records fails if one or more records in a batch have been deleted. If a record in an imported batch is deleted, any attempt to revert the batch will result in the progress bar never reaching 100%. The background job dies when it hits the already deleted record, with the error occurring in C4::Items::DelItem for the line: $copy2deleted->execute( $record->as_usmarc(), $itemnumber ); which fails because $record is undefined. To keep the failure from causing the script to die, we just need to check the record to see if it loaded before working on it. Test Plan: 1) Stage a batch of marc records 2) Import those records 3) Delete one of those records 4) Attempt to revert the batch, it will hang. 5) Apply this patch 6) Repeat steps 1-4, the revert should succeed. --- C4/Items.pm | 27 +++++++++++++++++++-------- 1 files changed, 19 insertions(+), 8 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 212a9d3..d71118d 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -608,21 +608,32 @@ Exported function (core API) for deleting an item record in Koha. sub DelItem { my ( $dbh, $biblionumber, $itemnumber ) = @_; - - # FIXME check the item has no current issues + + # FIXME: Why pass $dbh in? We can get it from C4::Context + # FIXME: Why pass $biblionumber in? It would be safer to get it via the itemnumber + + return unless ( DelItemCheck( $dbh, $biblionumber, $itemnumber ) eq '1' ); _koha_delete_item( $dbh, $itemnumber ); # get the MARC record my $record = GetMarcBiblio($biblionumber); - ModZebra( $biblionumber, "specialUpdate", "biblioserver" ); - # backup the record - my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?"); - $copy2deleted->execute( $record->as_usmarc(), $itemnumber ); - # This last update statement makes that the timestamp column in deleteditems is updated too. If you remove these lines, please add a line to update the timestamp separately. See Bugzilla report 7146 and Biblio.pm (DelBiblio). + if ($record) { + + ModZebra( $biblionumber, "specialUpdate", "biblioserver" ); + + # backup the record + my $copy2deleted = + $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?"); + $copy2deleted->execute( $record->as_usmarc(), $itemnumber ); + # This last update statement makes that the timestamp column in deleteditems is updated too. + # If you remove these lines, please add a line to update the timestamp separately. + # See Bugzilla report 7146 and Biblio.pm (DelBiblio). + } else { + warn "Something's wrong! Cannot backup item because record doesn't exist! Biblionumber: $biblionumber, Itemnumber: $itemnumber"; + } - #search item field code logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog"); } -- 1.7.2.5