From dfe6f4d1e84c81220c218c59a0bddbd95026ca5a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Sat, 27 Feb 2021 17:24:56 +0000 Subject: [PATCH] Bug 27819: Spurious item deletion errors from delete_records_via_leader.pl The job reports errors when deleting items. The issue seems to be that Koha::Object->delete claims in the POD to return -1, 0, or 1 as a result, but it in fact returns the Object itself on a successful deletion The errors are reported as: ERROR DELETING ITEM 501740: Koha::Item=HASH(0x55ce407a1a78) To recreate: 1 - Find or create a record with some items 2 - Ensure those items can be deleted (not on loan, etc.) 3 - Edit the record leader and set position 5 to 'd' 4 - perl misc/cronjobs/delete_records_via_leader.pl -i -v --confirm 5 - Deletion succeeds, but reports failure on items 6 - Apply patch 7 - Find or create a new record as above, but this time add an additional item and check it out to a patron 8 - perl misc/cronjobs/delete_records_via_leader.pl -i -v 9 - Test mode should report 1 item to be deleted, one with error 10 - perl misc/cronjobs/delete_records_via_leader.pl -i -v --confirm 11 - One item should be deleted, one item not, record not deleted 12 - check the item in 13 - perl misc/cronjobs/delete_records_via_leader.pl -i -v --confirm 14 - Successful deletion with no error reported Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 02a404ef42683b3c19bb937cdd3bd7449c5fbd3a) Signed-off-by: Fridolin Somers (cherry picked from commit 92e69e25eefd6a603d6bb9f094a27a10c749154a) Signed-off-by: Andrew Fuerste-Henry --- misc/cronjobs/delete_records_via_leader.pl | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/misc/cronjobs/delete_records_via_leader.pl b/misc/cronjobs/delete_records_via_leader.pl index c49b68111a..0287e43f57 100755 --- a/misc/cronjobs/delete_records_via_leader.pl +++ b/misc/cronjobs/delete_records_via_leader.pl @@ -99,20 +99,24 @@ foreach my $m (@metadatas) { foreach my $item ( @items ) { my $itemnumber = $item->itemnumber; - my $error = $test ? "Test mode enabled" : $item->safe_delete; - $error = undef if $error eq '1'; - - if ($error) { - say "ERROR DELETING ITEM $itemnumber: $error"; - } - else { - say "DELETED ITEM $itemnumber" if $verbose; - $deleted_items_count++; + if( $test ){ + my $result = $item->safe_to_delete; + if ( $result eq "1") { + say "TEST MODE: Item $itemnumber would have been deleted"; + } else { + say "TEST MODE: ERROR DELETING ITEM $itemnumber: $result"; + } + } else { + my $result = $item->safe_delete; + if ( ref $result eq "Koha::Item" ){ + say "DELETED ITEM $itemnumber" if $verbose; + $deleted_items_count++; + } else { + say "ERROR DELETING ITEM $itemnumber: $result"; + } } - $total_items_count++; } - } my $error = $test ? q{Test mode enabled} : DelBiblio($biblionumber); -- 2.39.5