Bug 30710: Build holds queue once per biblio when batch deleting items
authorNick Clemens <nick@bywatersolutions.com>
Fri, 6 May 2022 14:45:13 +0000 (14:45 +0000)
committerFridolin Somers <fridolin.somers@biblibre.com>
Wed, 11 May 2022 09:09:09 +0000 (23:09 -1000)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
C4/Biblio.pm
Koha/BackgroundJob/BatchDeleteItem.pm
Koha/Item.pm

index f10f7b4..aac46f0 100644 (file)
@@ -538,7 +538,7 @@ sub DelBiblio {
         {
             biblio_ids => [ $biblionumber ]
         }
-    );
+    ) unless $params->{skip_holds_queue};
 
     return;
 }
index 578a095..63e8814 100644 (file)
@@ -108,7 +108,7 @@ sub process {
 
                     my $item = Koha::Items->find($record_id) || next;
 
-                    my $return = $item->safe_delete({ skip_record_index => 1 });
+                    my $return = $item->safe_delete({ skip_record_index => 1, skip_holds_queue => 1 });
                     unless ( $return ) {
 
                         # FIXME Do we need to rollback the whole transaction if a deletion failed?
@@ -141,7 +141,7 @@ sub process {
                       Koha::Biblios->find($biblionumber)->items->count;
                     if ( $delete_biblios && $items_count == 0 ) {
                         my $error = C4::Biblio::DelBiblio( $biblionumber,
-                            { skip_record_index => 1 } );
+                            { skip_record_index => 1, skip_holds_queue => 1 } );
                         unless ($error) {
                             push @deleted_biblionumbers, $biblionumber;
                         }
@@ -156,6 +156,12 @@ sub process {
 
                     $indexer->index_records( \@deleted_biblionumbers,
                         'recordDelete', "biblioserver", undef );
+
+                    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
+                        {
+                            biblio_ids => \@deleted_biblionumbers
+                        }
+                    );
                 }
 
                 if (@updated_biblionumbers) {
@@ -164,6 +170,12 @@ sub process {
 
                     $indexer->index_records( \@updated_biblionumbers,
                         'specialUpdate', "biblioserver", undef );
+
+                    Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
+                        {
+                            biblio_ids => \@updated_biblionumbers
+                        }
+                    );
                 }
             }
         );
index 312b2b4..a6e3c1f 100644 (file)
@@ -248,7 +248,7 @@ sub delete {
         {
             biblio_ids => [ $self->biblionumber ]
         }
-    );
+    ) unless $params->{skip_holds_queue};
 
     return $result;
 }