From c04782e1cc9c2083d67c9cbcfe47a74e4a9b57af Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 6 Apr 2022 13:45:21 +0200 Subject: [PATCH] Bug 30464: Make BatchUpdateAuthority update the index in one request Same as bug 30465 for authorities Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- C4/AuthoritiesMarc.pm | 19 +++++++++++++++---- Koha/BackgroundJob/BatchUpdateAuthority.pm | 7 ++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 179b843866..d6f2e381b3 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -545,7 +545,10 @@ returns authid of the newly created authority sub AddAuthority { # pass the MARC::Record to this function, and it will create the records in the authority table - my ($record,$authid,$authtypecode) = @_; + my ( $record, $authid, $authtypecode, $params ) = @_; + + my $skip_record_index = $params->{skip_record_index} || 0; + my $dbh=C4::Context->dbh; my $leader=' nz a22 o 4500';#Leader for incomplete MARC21 record @@ -654,8 +657,11 @@ sub AddAuthority { $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) ); # Update $dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr; - my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); - $indexer->index_records( $authid, "specialUpdate", "authorityserver", $record ); + + unless ( $skip_record_index ) { + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); + $indexer->index_records( $authid, "specialUpdate", "authorityserver", $record ); + } _after_authority_action_hooks({ action => $action, authority_id => $authid }); return ( $authid ); @@ -703,13 +709,18 @@ sub DelAuthority { Modifies authority record, optionally updates attached biblios. The parameter skip_merge is optional and should be used with care. +skip_record_index will skip the indexation step. + =cut sub ModAuthority { my ( $authid, $record, $authtypecode, $params ) = @_; + + my $skip_record_index = $params->{skip_record_index} || 0; + my $oldrecord = GetAuthority($authid); #Now rewrite the $record to table with an add - $authid = AddAuthority($record, $authid, $authtypecode); + $authid = AddAuthority($record, $authid, $authtypecode, { skip_record_index => $skip_record_index }); merge({ mergefrom => $authid, MARCfrom => $oldrecord, mergeto => $authid, MARCto => $record }) if !$params->{skip_merge}; logaction( "AUTHORITIES", "MODIFY", $authid, "authority BEFORE=>" . $oldrecord->as_formatted ) if C4::Context->preference("AuthoritiesLog"); return $authid; diff --git a/Koha/BackgroundJob/BatchUpdateAuthority.pm b/Koha/BackgroundJob/BatchUpdateAuthority.pm index 9b5f89b7d7..ca23f7cf86 100644 --- a/Koha/BackgroundJob/BatchUpdateAuthority.pm +++ b/Koha/BackgroundJob/BatchUpdateAuthority.pm @@ -23,6 +23,8 @@ use C4::AuthoritiesMarc qw( ModAuthority ); use Koha::BackgroundJobs; use Koha::DateUtils qw( dt_from_string ); use Koha::MetadataRecord::Authority; +use Koha::SearchEngine; +use Koha::SearchEngine::Indexer; use base 'Koha::BackgroundJob'; @@ -81,7 +83,7 @@ sub process { my $authority = Koha::MetadataRecord::Authority->get_from_authid( $authid ); my $record = $authority->record; ModifyRecordWithTemplate( $mmtid, $record ); - ModAuthority( $authid, $record, $authority->authtypecode ); + ModAuthority( $authid, $record, $authority->authtypecode, { skip_record_index => 1 } ); }; if ( $error and $error != $authid or $@ ) { push @messages, { @@ -101,6 +103,9 @@ sub process { $self->progress( ++$job_progress )->store; } + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); + $indexer->index_records( \@record_ids, "specialUpdate", "authorityserver" ); + my $job_data = decode_json $self->data; $job_data->{messages} = \@messages; $job_data->{report} = $report; -- 2.39.5