Bug 29788: (follow-up) Make Koha::Item->safe_to_delete use Koha::Result::Boolean
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 23 Mar 2022 11:30:42 +0000 (12:30 +0100)
committerFridolin Somers <fridolin.somers@biblibre.com>
Wed, 23 Mar 2022 20:50:51 +0000 (10:50 -1000)
There were several wrong things in the previous patch!

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Koha/BackgroundJob/BatchDeleteBiblio.pm
cataloguing/additem.pl

index 15246fe..0c95c63 100644 (file)
@@ -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',
index 4588b13..1ad9edb 100755 (executable)
@@ -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" );