Bug 24324: Resolve error with delete_records_via_leader.pl
authorLiz Rea <wizzyrea@gmail.com>
Fri, 3 Jan 2020 21:18:27 +0000 (21:18 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 24 Mar 2020 08:03:30 +0000 (08:03 +0000)
To test:

Have a record with the 000 position 5 set to "deleted" (record status)
Use koha-shell to run the job with the -i flag: perl misc/cronjobs/delete_records_via_leader.pl -c -i -v
* items and the record should be deleted
Mark another record with the 000 position 5 set to deleted (record status)
Use koha-shell to run the job without the -i flag: perl misc/cronjobs/delete_records_via_leader.pl -c -v
* if the record had items, it will not be deleted
* if the record did not have items, it will be deleted.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

misc/cronjobs/delete_records_via_leader.pl

index 4e5315c..c49b681 100755 (executable)
@@ -39,6 +39,7 @@ use C4::Items;
 use Koha::Database;
 use Koha::Biblios;
 use Koha::Biblio::Metadatas;
+use Koha::Items;
 
 my $delete_items;
 my $confirm;
@@ -86,7 +87,6 @@ my $total_records_count   = @metadatas;
 my $deleted_records_count = 0;
 my $total_items_count     = 0;
 my $deleted_items_count   = 0;
-
 foreach my $m (@metadatas) {
     my $biblionumber = $m->get_column('biblionumber');
 
@@ -95,9 +95,9 @@ foreach my $m (@metadatas) {
     if ($delete_items) {
         my $deleted_count = 0;
         my $biblio = Koha::Biblios->find( $biblionumber );
-        my @items = $biblio ? $biblio->items : ();
+        my @items = Koha::Items->search( { biblionumber => $biblionumber } );
         foreach my $item ( @items ) {
-            my $itemnumber = $item->itemnumber();
+            my $itemnumber = $item->itemnumber;
 
             my $error = $test ? "Test mode enabled" : $item->safe_delete;
             $error = undef if $error eq '1';