diff --git a/C4/Biblio.pm b/C4/Biblio.pm index da10581ede..de4b48ab47 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -357,7 +357,9 @@ Returns 1 on success 0 on failure sub ModBiblio { my ( $record, $biblionumber, $frameworkcode, $options ) = @_; + $options //= {}; + my $skip_record_index = $options->{skip_record_index} || 0; if (!$record) { carp 'No record passed to ModBiblio'; @@ -421,7 +423,7 @@ sub ModBiblio { _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); # update the MARC record (that now contains biblio and items) with the new record data - ModBiblioMarc( $record, $biblionumber ); + ModBiblioMarc( $record, $biblionumber, { skip_record_index => $skip_record_index } ); # modify the other koha tables _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); @@ -2871,12 +2873,14 @@ Function exported, but should NOT be used, unless you really know what you're do sub ModBiblioMarc { # pass the MARC::Record to this function, and it will create the records in # the marcxml field - my ( $record, $biblionumber ) = @_; + my ( $record, $biblionumber, $params ) = @_; if ( !$record ) { carp 'ModBiblioMarc passed an undefined record'; return; } + my $skip_record_index = $params->{skip_record_index} || 0; + # Clone record as it gets modified $record = $record->clone(); my $dbh = C4::Context->dbh; @@ -2936,8 +2940,10 @@ sub ModBiblioMarc { $m_rs->metadata( $record->as_xml_record($encoding) ); $m_rs->store; - my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); - $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" ); + unless ( $skip_record_index ) { + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" ); + } return $biblionumber; } diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm index e8022c0d49..35152e4526 100644 --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -20,6 +20,8 @@ use JSON qw( decode_json encode_json ); use Koha::DateUtils qw( dt_from_string ); use Koha::Virtualshelves; +use Koha::SearchEngine; +use Koha::SearchEngine::Indexer; use C4::Context; use C4::Biblio; @@ -89,7 +91,8 @@ sub process { C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record ); my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblionumber ); C4::Biblio::ModBiblio( $record, $biblionumber, $frameworkcode, { - overlay_context => $args->{overlay_context}, + overlay_context => $args->{overlay_context}, + skip_record_index => 1, }); }; if ( $error and $error != 1 or $@ ) { # ModBiblio returns 1 if everything as gone well @@ -110,6 +113,9 @@ sub process { $self->progress( ++$job_progress )->store; } + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $indexer->index_records( \@record_ids, "specialUpdate", "biblioserver" ); + my $job_data = decode_json $self->data; $job_data->{messages} = \@messages; $job_data->{report} = $report; diff --git a/Koha/Items.pm b/Koha/Items.pm index d8bca20519..1900a40a0f 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -353,11 +353,12 @@ sub batch_update { Koha::Items->search( { itemnumber => \@modified_itemnumbers } ) ->get_column('biblionumber')); - my $indexer = Koha::SearchEngine::Indexer->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); - $indexer->index_records( \@biblionumbers, 'specialUpdate', - "biblioserver", undef ) - if @biblionumbers; + if ( @biblionumbers ) { + my $indexer = Koha::SearchEngine::Indexer->new( + { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + + $indexer->update_index( \@biblionumbers ); + } } return ( { modified_itemnumbers => \@modified_itemnumbers, modified_fields => $modified_fields }, $self );