From 78ecdc84391ccfd7b8bdfba9464da5b46ff4f68a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 23 Mar 2022 12:30:42 +0100 Subject: [PATCH] Bug 29788: (follow-up) Make Koha::Item->safe_to_delete use Koha::Result::Boolean There were several wrong things in the previous patch! Signed-off-by: Fridolin Somers --- Koha/BackgroundJob/BatchDeleteBiblio.pm | 2 +- cataloguing/additem.pl | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Koha/BackgroundJob/BatchDeleteBiblio.pm b/Koha/BackgroundJob/BatchDeleteBiblio.pm index 15246feae0..0c95c6352c 100644 --- a/Koha/BackgroundJob/BatchDeleteBiblio.pm +++ b/Koha/BackgroundJob/BatchDeleteBiblio.pm @@ -108,7 +108,7 @@ sub process { my $items = Koha::Items->search({ biblionumber => $biblionumber }); while ( my $item = $items->next ) { my $deleted = $item->safe_delete; - if( $deleted ) { + unless ( $deleted ) { push @messages, { type => 'error', code => 'item_not_deleted', diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 4588b13fb5..1ad9edb503 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -377,11 +377,13 @@ if ($op eq "additem") { # check that there is no issue on this item before deletion. my $item = Koha::Items->find($itemnumber); my $deleted = $item->safe_delete; - if($deleted) { + unless ( $deleted ) { print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode&searchid=$searchid"); - } else { - push @errors, @{$deleted->messages}[0]->message; - $nextop="additem"; + exit; + } + else { + push @errors, @{ $deleted->messages }[0]->message; + $nextop = "additem"; } #------------------------------------------------------------------------------- } elsif ($op eq "delallitems") { @@ -389,7 +391,7 @@ if ($op eq "additem") { my $items = Koha::Items->search({ biblionumber => $biblionumber }); while ( my $item = $items->next ) { my $deleted = $item->safe_delete({ skip_record_index => 1 }); - push @errors, @{$deleted->messages}[0]->message; + push @errors, @{$deleted->messages}[0]->message unless $deleted; } my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" ); -- 2.39.5