From 4e42f1182d14dd0658c984930c11ea3c952b8051 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 5 Dec 2023 16:27:44 +0000 Subject: [PATCH] Bug 35491: Add logging to RevertWaitingStatus This patch simply adds a logaction line to RevertWaitingStatus To test: 1 - Enable HoldsLog 2 - Place a hold 3 - Fill the hold 4 - Revert the waiting status 5 - Note there is no action log added 6 - Apply patch 7 - Repeat 2-4 8 - Confirm you now have a MODIFY action logged for the reversion Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Katrin Fischer --- C4/Reserves.pm | 3 +++ t/db_dependent/Reserves.t | 27 +++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 872abfa13b..c95a3d7ad4 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2169,6 +2169,9 @@ sub RevertWaitingStatus { } )->store(); + logaction( 'HOLDS', 'MODIFY', $hold->id, $hold ) + if C4::Context->preference('HoldsLog'); + _FixPriority( { biblionumber => $hold->biblionumber } ); Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 0076dc2e15..83b84bbc2d 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -989,7 +989,7 @@ subtest 'reserves.item_level_hold' => sub { ); subtest 'item level hold' => sub { - plan tests => 3; + plan tests => 5; my $reserve_id = AddReserve( { branchcode => $item->homebranch, @@ -1017,24 +1017,39 @@ subtest 'reserves.item_level_hold' => sub { } ); t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); + t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); # Revert the waiting status - C4::Reserves::RevertWaitingStatus( - { itemnumber => $item->itemnumber } ); + C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); $hold = Koha::Holds->find($reserve_id); - is( $hold->itemnumber, $item->itemnumber, 'Itemnumber should not be removed when the waiting status is revert' ); + is( + $hold->itemnumber, $item->itemnumber, + 'Itemnumber should not be removed when the waiting status is revert' + ); + + my $log = + Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->next; + my $expected = sprintf q{'timestamp' => '%s'}, $hold->timestamp; + like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); + my $log_count = + Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count; t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); + t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); $hold->set_waiting; # Revert the waiting status, RealTimeHoldsQueue => shouldn't add a test - C4::Reserves::RevertWaitingStatus( - { itemnumber => $item->itemnumber } ); + C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); $hold->delete; # cleanup + + my $log_count_after = + Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count; + is( $log_count, $log_count_after, "No logging is added for RevertWaitingStatus when HoldsLog is disabled" ); + }; subtest 'biblio level hold' => sub { -- 2.39.5