Browse Source

Bug 30465: Make BatchUpdateBiblio update the index in one request

When using the batch record modification tool to modify several
bibliographic records, we don't want to send one index request per
biblio, we want to index them all on the fly after the records have been
modified.
Otherwise we will end up with one task per record, and records will be
indexed in background.

Test plan:
Use the batch mod tool to modify bibliographic records and confirm the
behaviour is correct.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
rmain2205
Jonathan Druart 10 months ago
committed by Fridolin Somers
parent
commit
734a02cf82
  1. 14
      C4/Biblio.pm
  2. 8
      Koha/BackgroundJob/BatchUpdateBiblio.pm
  3. 11
      Koha/Items.pm

14
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;
}

8
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;

11
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 );

Loading…
Cancel
Save