@@ -, +, @@ --- C4/Items.pm | 27 +++++++++++++++++++-------- 1 files changed, 19 insertions(+), 8 deletions(-) --- a/C4/Items.pm +++ a/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"); } --