From e7dd88ff79e9b315ff02e8481504db92243303c8 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 19 Jan 2024 19:12:48 +0000 Subject: [PATCH] Bug 35165: Tidy Signed-off-by: Andrew Fuerste-Henry --- Koha/BackgroundJob/BatchDeleteItem.pm | 124 +++++++++++++------------- 1 file changed, 60 insertions(+), 64 deletions(-) diff --git a/Koha/BackgroundJob/BatchDeleteItem.pm b/Koha/BackgroundJob/BatchDeleteItem.pm index 6c15bbc158..169fd8545b 100644 --- a/Koha/BackgroundJob/BatchDeleteItem.pm +++ b/Koha/BackgroundJob/BatchDeleteItem.pm @@ -94,92 +94,88 @@ sub process { @deleted_biblionumbers ); try { - my (@biblionumbers); - for my $record_id ( sort { $a <=> $b } @record_ids ) { + my (@biblionumbers); + for my $record_id ( sort { $a <=> $b } @record_ids ) { - last if $self->get_from_storage->status eq 'cancelled'; + last if $self->get_from_storage->status eq 'cancelled'; - my $item = Koha::Items->find($record_id) || next; + my $item = Koha::Items->find($record_id) || next; - my $return = $item->safe_delete({ skip_record_index => 1, skip_holds_queue => 1 }); - unless ( $return ) { + my $return = $item->safe_delete( { skip_record_index => 1, skip_holds_queue => 1 } ); + unless ($return) { - push @not_deleted_itemnumbers, $item->itemnumber; - push @messages, - { - type => 'error', - code => 'item_not_deleted', - itemnumber => $item->itemnumber, - biblionumber => $item->biblionumber, - barcode => $item->barcode, - title => $item->biblio->title, - reason => @{$return->messages}[0]->message, - }; + push @not_deleted_itemnumbers, $item->itemnumber; + push @messages, + { + type => 'error', + code => 'item_not_deleted', + itemnumber => $item->itemnumber, + biblionumber => $item->biblionumber, + barcode => $item->barcode, + title => $item->biblio->title, + reason => @{ $return->messages }[0]->message, + }; - next; - } + next; + } - push @deleted_itemnumbers, $item->itemnumber; - push @biblionumbers, $item->biblionumber; + push @deleted_itemnumbers, $item->itemnumber; + push @biblionumbers, $item->biblionumber; - $report->{total_success}++; - $self->step; - } + $report->{total_success}++; + $self->step; + } - # If there are no items left, delete the biblio - my @updated_biblionumbers; - for my $biblionumber ( uniq @biblionumbers ) { - my $items_count = - Koha::Biblios->find($biblionumber)->items->count; - if ( $delete_biblios && $items_count == 0 ) { - my $error = C4::Biblio::DelBiblio( $biblionumber, - { skip_record_index => 1, skip_holds_queue => 1 } ); - unless ($error) { - push @deleted_biblionumbers, $biblionumber; - } - } else { - push @updated_biblionumbers, $biblionumber; - } + # If there are no items left, delete the biblio + my @updated_biblionumbers; + for my $biblionumber ( uniq @biblionumbers ) { + my $items_count = Koha::Biblios->find($biblionumber)->items->count; + if ( $delete_biblios && $items_count == 0 ) { + my $error = C4::Biblio::DelBiblio( + $biblionumber, + { skip_record_index => 1, skip_holds_queue => 1 } + ); + unless ($error) { + push @deleted_biblionumbers, $biblionumber; } + } else { + push @updated_biblionumbers, $biblionumber; + } + } - if (@deleted_biblionumbers) { - my $indexer = Koha::SearchEngine::Indexer->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + if (@deleted_biblionumbers) { + my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); - $indexer->index_records( \@deleted_biblionumbers, - 'recordDelete', "biblioserver", undef ); + $indexer->index_records( + \@deleted_biblionumbers, + 'recordDelete', "biblioserver", undef + ); - Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( - { - biblio_ids => \@deleted_biblionumbers - } - ) if C4::Context->preference('RealTimeHoldsQueue'); - } + Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@deleted_biblionumbers } ) + if C4::Context->preference('RealTimeHoldsQueue'); + } - if (@updated_biblionumbers) { - my $indexer = Koha::SearchEngine::Indexer->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + if (@updated_biblionumbers) { + my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); - $indexer->index_records( \@updated_biblionumbers, - 'specialUpdate', "biblioserver", undef ); + $indexer->index_records( + \@updated_biblionumbers, + 'specialUpdate', "biblioserver", undef + ); - Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( - { - biblio_ids => \@updated_biblionumbers - } - ) if C4::Context->preference('RealTimeHoldsQueue'); - } - } - catch { + Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@updated_biblionumbers } ) + if C4::Context->preference('RealTimeHoldsQueue'); + } + } catch { warn $_; push @messages, - { + { type => 'error', code => 'unknown', error => $_, - }; + }; }; -- 2.30.2