From 80eb5555d6e2a944669046fd1abb7ac91db4ccb9 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 5 Aug 2021 13:17:19 +0000 Subject: [PATCH] Bug 28799: Log when item was lost and now found In the subroutine ModDateLastSeen we unset an item's lost status when checked in. This routine passes a noi log parameter to the store request, this is to avoid spamming the cataloguing log on every checkin. When marking an item unlost we should record this change. To test: 1 - Enable cataloguing log 2 - Mark an item lost 3 - View the log and confirm this chagne was recorded 4 - Check the item in 5 - The message indicates item is now found, but logs have no new entry 6 - Apply patch, restart all 7 - Mark the item lost and verify it is logged 8 - Check the item in, reported found and log entry recorded Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- C4/Items.pm | 3 ++- t/db_dependent/Items.t | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 817e86e940..a34527d51d 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -401,8 +401,9 @@ sub ModDateLastSeen { my $item = Koha::Items->find($itemnumber); $item->datelastseen(dt_from_string); + my $log = $item->itemlost && !$leave_item_lost ? 1 : 0; # If item was lost, record the change to the item $item->itemlost(0) unless $leave_item_lost; - $item->store({ log_action => 0, skip_record_index => $params->{skip_record_index}, skip_holds_queue => $params->{skip_holds_queue} }); + $item->store({ log_action => $log, skip_record_index => $params->{skip_record_index}, skip_holds_queue => $params->{skip_holds_queue} }); } =head2 CheckItemPreSave diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 10b9bab3b7..be071e729b 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -19,7 +19,7 @@ use Modern::Perl; use Data::Dumper; use MARC::Record; -use C4::Items qw( ModItemTransfer SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ); +use C4::Items qw( ModItemTransfer SearchItems AddItemFromMarc ModItemFromMarc get_hostitemnumbers_of Item2Marc ModDateLastSeen ); use C4::Biblio qw( GetMarcFromKohaField AddBiblio ); use C4::Circulation qw( AddIssue ); use Koha::Items; @@ -34,7 +34,7 @@ use Koha::AuthorisedValues; use t::lib::Mocks; use t::lib::TestBuilder; -use Test::More tests => 11; +use Test::More tests => 12; use Test::Warn; @@ -931,4 +931,28 @@ subtest 'ModItemFromMarc' => sub { $schema->storage->txn_rollback; Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); -} +}; + +subtest 'ModDateLastSeen' => sub { + plan tests => 5; + $schema->storage->txn_begin; + + my $builder = t::lib::TestBuilder->new; + my $item = $builder->build_sample_item; + t::lib::Mocks::mock_preference('CataloguingLog', '1'); + my $logs_before = Koha::ActionLogs->search({ module => 'CATALOGUING', action => 'MODIFY', object => $item->itemnumber })->count; + ModDateLastSeen($item->itemnumber); + my $logs_after = Koha::ActionLogs->search({ module => 'CATALOGUING', action => 'MODIFY', object => $item->itemnumber })->count; + is( $logs_after, $logs_before, "ModDateLastSeen doesn't log if item not lost"); + $item->itemlost(1)->store({ log_action => 0 }); + ModDateLastSeen($item->itemnumber, 1); + $item->discard_changes; + $logs_after = Koha::ActionLogs->search({ module => 'CATALOGUING', action => 'MODIFY', object => $item->itemnumber })->count; + is( $item->itemlost, 1, "Item left lost when parameter is passed"); + is( $logs_after, $logs_before, "ModDateLastSeen doesn't log if item not lost"); + ModDateLastSeen($item->itemnumber); + $item->discard_changes; + $logs_after = Koha::ActionLogs->search({ module => 'CATALOGUING', action => 'MODIFY', object => $item->itemnumber })->count; + is( $item->itemlost, 0, "Item no longer lost when no parameter is passed"); + is( $logs_after, $logs_before + 1, "ModDateLastSeen logs if item was lost and now found"); +}; -- 2.39.5