From 04c0413352ad1be9b49919d73c288130eec4b06c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 6 Apr 2022 14:38:04 +0200 Subject: [PATCH] Bug 27344: Fix call to update_index with invalid ids Can't use an undefined value as an ARRAY reference at /kohadevbox/koha/Koha/SearchEngine/Elasticsearch/Indexer.pm line 121. Caught that when working on follow-up bug reports. Signed-off-by: Fridolin Somers --- Koha/SearchEngine/Elasticsearch/Indexer.pm | 2 +- .../Koha/SearchEngine/Elasticsearch/Indexer.t | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Indexer.pm b/Koha/SearchEngine/Elasticsearch/Indexer.pm index 1aa426a6a2..ca0d19a442 100644 --- a/Koha/SearchEngine/Elasticsearch/Indexer.pm +++ b/Koha/SearchEngine/Elasticsearch/Indexer.pm @@ -100,7 +100,7 @@ Arrayref of Cs. sub update_index { my ($self, $record_ids, $records) = @_; - my $index_record_ids; + my $index_record_ids = []; unless ( $records && @$records ) { for my $record_id ( sort { $a <=> $b } @$record_ids ) { diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t index 70e6ab073d..2b84a24f39 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Test::MockModule; use Test::Warn; use t::lib::Mocks; @@ -120,6 +120,22 @@ subtest 'index_records() tests' => sub { } "Update background " . $biblio->biblionumber, "When passing id only to index_records the marc record is fetched and passed through to update_index"; + +}; + +subtest 'update_index' => sub { + plan tests => 1; + + my $biblio = $builder->build_sample_biblio; + my $biblionumber = $biblio->biblionumber; + $biblio->delete; + + my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }); + warning_is { + $indexer->update_index([$biblionumber]); + + } "", "update_index called with deleted biblionumber should not crash"; + }; } -- 2.39.5