From eae9042d1f77b273fb354fd8bc7891a434a6f5a4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 6 Apr 2022 13:52:40 +0200 Subject: [PATCH] Bug 30459: Make BatchDeleteAuthority update the index in one request Same as bug 30460 for authorities --- C4/AuthoritiesMarc.pm | 10 ++++++++-- Koha/BackgroundJob/BatchDeleteAuthority.pm | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 06da1b726d8..899ed680204 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -663,12 +663,16 @@ Deletes $authid and calls merge to cleanup linked biblio records. Parameter skip_merge is used in authorities/merge.pl. You should normally not use it. +skip_record_index will skip the indexation step. + =cut sub DelAuthority { my ( $params ) = @_; my $authid = $params->{authid} || return; my $skip_merge = $params->{skip_merge}; + my $skip_record_index = $params->{skip_record_index} || 0; + my $dbh = C4::Context->dbh; # Remove older pending merge requests for $authid to itself. (See bug 22437) @@ -678,8 +682,10 @@ sub DelAuthority { merge({ mergefrom => $authid }) if !$skip_merge; $dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid ); logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); - my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); - $indexer->index_records( $authid, "recordDelete", "authorityserver", undef ); + unless ( $skip_record_index ) { + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); + $indexer->index_records( $authid, "recordDelete", "authorityserver", undef ); + } _after_authority_action_hooks({ action => 'delete', authority_id => $authid }); } diff --git a/Koha/BackgroundJob/BatchDeleteAuthority.pm b/Koha/BackgroundJob/BatchDeleteAuthority.pm index 3983ffd1e4a..64d10f43ab6 100644 --- a/Koha/BackgroundJob/BatchDeleteAuthority.pm +++ b/Koha/BackgroundJob/BatchDeleteAuthority.pm @@ -3,9 +3,12 @@ package Koha::BackgroundJob::BatchDeleteAuthority; use Modern::Perl; use JSON qw( encode_json decode_json ); -use Koha::DateUtils qw( dt_from_string ); use C4::AuthoritiesMarc; +use Koha::DateUtils qw( dt_from_string ); +use Koha::SearchEngine; +use Koha::SearchEngine::Indexer; + use base 'Koha::BackgroundJob'; sub job_type { @@ -46,7 +49,10 @@ sub process { $schema->storage->txn_begin; my $authid = $record_id; - eval { C4::AuthoritiesMarc::DelAuthority({ authid => $authid }) }; + eval { + C4::AuthoritiesMarc::DelAuthority( + { authid => $authid, skip_record_index => 1 } ); + }; if ( $@ ) { push @messages, { type => 'error', @@ -69,6 +75,15 @@ sub process { $self->progress( ++$job_progress )->store; } + my @deleted_authids = + map { $_->{code} eq 'authority_deleted' ? $_->{authid} : () } + @messages; + + if ( @deleted_authids ) { + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); + $indexer->index_records( \@deleted_authids, "recordDelete", "authorityserver" ); + } + my $job_data = decode_json $self->data; $job_data->{messages} = \@messages; $job_data->{report} = $report; -- 2.25.1