From 993931eb9e63805b0737bc3411b7628fb871742f 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 (cherry picked from commit 4e42f1182d14dd0658c984930c11ea3c952b8051) Signed-off-by: Fridolin Somers (cherry picked from commit 5ca5900f911ab483cb7bd6bda352399977148481) Signed-off-by: Lucas Gass --- 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 0295bd3c66..e8df114877 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -2120,6 +2120,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 8ae67ed4b6..0057faac77 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -1004,7 +1004,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, @@ -1032,24 +1032,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