From d19572ea765dbf6c13ba1343433ed07729413248 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 25 Sep 2020 07:42:44 +0000 Subject: [PATCH] Bug 25265: (QA follow-up) Check server type in Elasticsearch::index_records Doing the same change as previously (renaming biblionumber), but fixing at the same the record fetch. If (theoretically) an authority is passed without a record, it would have fetched a biblio record. Test plan: You need Elasticsearch here. Replaced this line in AddAuthority: $indexer->index_records( $authid, "specialUpdate", "authorityserver", $record ); by $indexer->index_records( $authid, "specialUpdate", "authorityserver", undef ); And updated an authority record. Check if you can search for the change. Signed-off-by: Marcel de Rooy JD amended patch: remove trailing whitespace Signed-off-by: Jonathan Druart --- Koha/SearchEngine/Elasticsearch/Indexer.pm | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Indexer.pm b/Koha/SearchEngine/Elasticsearch/Indexer.pm index 87902a34e0..39e129f7df 100644 --- a/Koha/SearchEngine/Elasticsearch/Indexer.pm +++ b/Koha/SearchEngine/Elasticsearch/Indexer.pm @@ -284,7 +284,7 @@ sub update_index_background { =head2 index_records -This function takes an array of biblionumbers and fetches the records to send to update_index +This function takes an array of record numbers and fetches the records to send to update_index for actual indexing. If $records parameter is provided the records will be used as-is, this is only utilized for authorities @@ -296,29 +296,34 @@ to Zebra as well. =cut sub index_records { - my ( $self, $biblionumbers, $op, $server, $records ) = @_; - $biblionumbers = [$biblionumbers] if ref $biblionumbers ne 'ARRAY' && defined $biblionumbers; + my ( $self, $record_numbers, $op, $server, $records ) = @_; + $record_numbers = [$record_numbers] if ref $record_numbers ne 'ARRAY' && defined $record_numbers; $records = [$records] if ref $records ne 'ARRAY' && defined $records; if ( $op eq 'specialUpdate' ) { - my $index_biblionumbers; + my $index_record_numbers; unless ($records) { - foreach my $biblionumber ( @$biblionumbers ){ - my $record = C4::Biblio::GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); + foreach my $record_number ( @$record_numbers ){ + my $record = _get_record( $record_number, $server ); if( $record ){ push @$records, $record; - push @$index_biblionumbers, $biblionumber; + push @$index_record_numbers, $record_number; } } } - $self->update_index_background( $index_biblionumbers, $records ) if $index_biblionumbers && $records; + $self->update_index_background( $index_record_numbers, $records ) if $index_record_numbers && $records; } elsif ( $op eq 'recordDelete' ) { - $self->delete_index_background( $biblionumbers ); + $self->delete_index_background( $record_numbers ); } #FIXME Current behaviour is to index Zebra when using ES, at some point we should stop - Koha::SearchEngine::Zebra::Indexer::index_records( $self, $biblionumbers, $op, $server, undef ); + Koha::SearchEngine::Zebra::Indexer::index_records( $self, $record_numbers, $op, $server, undef ); +} + +sub _get_record { + my ( $id, $server ) = @_; + return $server eq 'biblioserver' + ? C4::Biblio::GetMarcBiblio({ biblionumber => $id, embed_items => 1 }) + : C4::AuthoritiesMarc::GetAuthority($id); } =head2 delete_index($biblionums) -- 2.39.5