From 2ca69b49af54a01a7a46b8f791539145d1f2c6ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Tue, 25 May 2021 18:34:33 +0300 Subject: [PATCH] Bug 22690: (QA follow-up) Index also source biblio when calling move_to_biblio() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We need to update the search index record for the old biblio where the item was moved from to keep the item info in search index up-to-date. To test: 1) $ prove t/db_dependent/Koha/SearchEngine/Indexer.t Signed-off-by: Joonas Kylmälä Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Item.pm | 22 ++++++++++++++-------- t/db_dependent/Koha/SearchEngine/Indexer.t | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 1e39116b91..0b346217e9 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -1214,27 +1214,33 @@ sub move_to_biblio { return unless $self->biblionumber != $to_biblio->biblionumber; - my $biblionumber = $to_biblio->biblionumber; + my $from_biblionumber = $self->biblionumber; + my $to_biblionumber = $to_biblio->biblionumber; # Own biblionumber and biblioitemnumber $self->set({ - biblionumber => $biblionumber, + biblionumber => $to_biblionumber, biblioitemnumber => $to_biblio->biblioitem->biblioitemnumber })->store({ skip_record_index => $params->{skip_record_index} }); + unless ($params->{skip_record_index}) { + my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); + $indexer->index_records( $from_biblionumber, "specialUpdate", "biblioserver" ); + } + # Acquisition orders my $orders = $self->item_orders; if ($orders) { - $orders->update({ biblionumber => $biblionumber }, { no_triggers => 1 }); + $orders->update({ biblionumber => $to_biblionumber }, { no_triggers => 1 }); } # Holds - $self->holds->update({ biblionumber => $biblionumber }); + $self->holds->update({ biblionumber => $to_biblionumber }); # hold_fill_target (there's no Koha object available) my $hold_fill_target = $self->_result->hold_fill_target; if ($hold_fill_target) { - $hold_fill_target->update({ biblionumber => $biblionumber }); + $hold_fill_target->update({ biblionumber => $to_biblionumber }); } # tmp_holdsqueues - Can't update with DBIx since the table is missing a primary key @@ -1244,16 +1250,16 @@ sub move_to_biblio { sub { my ($storage, $dbh, @cols) = @_; - $dbh->do("UPDATE tmp_holdsqueue SET biblionumber=? WHERE itemnumber=?", undef, $biblionumber, $self->itemnumber); + $dbh->do("UPDATE tmp_holdsqueue SET biblionumber=? WHERE itemnumber=?", undef, $to_biblionumber, $self->itemnumber); } ); # linktrackers my $schema = Koha::Database->new()->schema(); my $linktrackers = $schema->resultset('Linktracker')->search({ itemnumber => $self->itemnumber }); - $linktrackers->update_all({ biblionumber => $biblionumber }); + $linktrackers->update_all({ biblionumber => $to_biblionumber }); - return $biblionumber; + return $to_biblionumber; } =head2 Internal methods diff --git a/t/db_dependent/Koha/SearchEngine/Indexer.t b/t/db_dependent/Koha/SearchEngine/Indexer.t index 663f0bafdf..9ee997c263 100755 --- a/t/db_dependent/Koha/SearchEngine/Indexer.t +++ b/t/db_dependent/Koha/SearchEngine/Indexer.t @@ -178,7 +178,7 @@ subtest 'Test indexer calls' => sub { warnings_are{ $item3->move_to_biblio($biblio2); - } [$engine,"Koha::Item"], "index_records is called for $engine when moving an item to another biblio (Item->move_to_biblio)"; + } [$engine,"Koha::Item",$engine,"Koha::Item"], "index_records is called twice for $engine when moving an item to another biblio (Item->move_to_biblio)"; warnings_are{ $item4->move_to_biblio($biblio2, { skip_record_index => 1 }); } undef, "index_records is not called for $engine when moving an item to another biblio (Item->move_to_biblio) if skip_record_index passed"; -- 2.39.5