Bug 30459: Make BatchDeleteAuthority update the index in one request
Same as bug 30460 for authorities Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
c1d036e8f9
commit
9dc00051c7
|
|
@ -669,12 +669,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)
|
||||
|
|
@ -684,8 +688,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 });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue