From 25f8581c0d98706047d282e46122821be738d969 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 15 May 2023 12:07:09 -0300 Subject: [PATCH] Bug 33739: Only trigger indexing on last item modification at ModItemTransfer This patch makes ModItemTransfer trigger record indexing only on the last call (in $transfer->transit). And extra parameter is added to ->transit to effectively honour the ModItemTransfer parameter. I wanted to mention that bug 31212 highlighted an existing issue, not catched by the current tests before its inclussion, because of the DT truncation taking place. To test: 1. Run: $ ktd --shell k$ prove t/db_dependent/Koha/SearchEngine/Indexer.t => FAIL: Indexing is requested twice, should only be once 2. Apply this patch 3. Repeat 1 => SUCCESS: Tests pass! Indexing is requested only once! 4. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart --- C4/Items.pm | 4 ++-- Koha/Item/Transfer.pm | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index ea008f09e2..813d01a045 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -380,10 +380,10 @@ sub ModItemTransfer { $item->holdingbranch($frombranch)->store( { log_action => 0, - skip_record_index => $params->{skip_record_index} + skip_record_index => 1, # avoid indexing duplication, let ->transit handle it } ); - $transfer->transit; + $transfer->transit({ skip_record_index => $params->{skip_record_index} }); } return; diff --git a/Koha/Item/Transfer.pm b/Koha/Item/Transfer.pm index 286e0fd276..74ec297ec9 100644 --- a/Koha/Item/Transfer.pm +++ b/Koha/Item/Transfer.pm @@ -80,14 +80,19 @@ sub to_library { =head3 transit -Set the transfer as in transit by updating the datesent time. + $transfer->transit({ [ skip_record_index => 0|1 ] }); + +Set the transfer as in transit by updating the I time. Also, update date last seen and ensure item holdingbranch is correctly set. +An optional I parameter can be passed to avoid triggering +reindex. + =cut sub transit { - my ($self) = @_; + my ($self, $params) = @_; # Throw exception if item is still checked out Koha::Exceptions::Item::Transfer::OnLoan->throw() if ( $self->item->checkout ); @@ -107,7 +112,7 @@ sub transit { } )->store; - ModDateLastSeen( $self->item->itemnumber ); + ModDateLastSeen( $self->item->itemnumber, undef, { skip_record_index => $params->{skip_record_index} } ); return $self; }