From 735ee5d756d7d17ebfa2e11b04e9e592084d432f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 12 Oct 2023 12:40:17 +0100 Subject: [PATCH] Bug 35027: Add 'hold' to patron activity triggers Content-Type: text/plain; charset=utf-8 This patch adds 'hold' to the list of triggers available for tracking patron activity. Test plan 1) Select 'Placing a hold on an item' in the TrackPatronLastActivityTriggers system preference 2) As a staff member, place a hold on any item for a test user 3) Confirm that the borrowers.lastseen field is updated for that test borrower Signed-off-by: Marcel de Rooy --- C4/Reserves.pm | 5 +++- .../en/modules/admin/preferences/patrons.pref | 1 + t/db_dependent/Koha/Patron.t | 29 +++++++++++++++++-- t/db_dependent/Reserves.t | 11 +++++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 3625737885..e2dc17df69 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -258,6 +258,9 @@ sub AddReserve { )->store(); $hold->set_waiting() if $found && $found eq 'W'; + # record patron activity + $hold->patron->update_lastseen('hold'); + logaction( 'HOLDS', 'CREATE', $hold->id, $hold ) if C4::Context->preference('HoldsLog'); @@ -273,7 +276,7 @@ sub AddReserve { # Send e-mail to librarian if syspref is active if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){ - my $patron = Koha::Patrons->find( $borrowernumber ); + my $patron = $hold->patron; my $library = $patron->library; if ( my $letter = C4::Letters::GetPreparedLetter ( module => 'reserves', diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 9e80c86265..2f416cb2e9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -101,6 +101,7 @@ Patrons: check_out: "Checking out an item" renewal: "Renewing an item" check_in: "Returning an item" + hold: "Placing a hold on an item" - - pref: AutoApprovePatronProfileSettings choices: diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 02a06df75f..ba4e30179b 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -1954,7 +1954,7 @@ subtest 'alert_subscriptions tests' => sub { subtest 'update_lastseen tests' => sub { - plan tests => 18; + plan tests => 21; $schema->storage->txn_begin; my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -1967,7 +1967,10 @@ subtest 'update_lastseen tests' => sub { my $cache_key = "track_activity_" . $patron->borrowernumber; $cache->clear_from_cache($cache_key); - t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); + t::lib::Mocks::mock_preference( + 'TrackLastPatronActivityTriggers', + 'login,connection,check_in,check_out,renewal,hold' + ); is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); @@ -1997,6 +2000,9 @@ subtest 'update_lastseen tests' => sub { $patron->update_lastseen('renewal'); $patron->_result()->discard_changes(); is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a renewal' ); + $patron->update_lastseen('hold'); + $patron->_result()->discard_changes(); + is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a hold' ); # Check that tracking is disabled when the activity isn't listed t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); @@ -2036,9 +2042,18 @@ subtest 'update_lastseen tests' => sub { $patron->lastseen, $last_seen, 'Patron last seen should be unchanged after a renewal if renewal is not selected as an option and the cache has been cleared' ); + $patron->update_lastseen('hold'); + $patron->_result()->discard_changes(); + is( + $patron->lastseen, $last_seen, + 'Patron last seen should be unchanged after a hold if hold is not selected as an option and the cache has been cleared' + ); # Check tracking for each activity - t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); + t::lib::Mocks::mock_preference( + 'TrackLastPatronActivityTriggers', + 'login,connection,check_in,check_out,renewal,hold' + ); $cache->clear_from_cache($cache_key); $patron->update_lastseen('login'); @@ -2069,6 +2084,14 @@ subtest 'update_lastseen tests' => sub { 'Patron last seen should be changed after a check_in if we cleared the cache' ); + $cache->clear_from_cache($cache_key); + $patron->update_lastseen('hold'); + $patron->_result()->discard_changes(); + isnt( + $patron->lastseen, $last_seen, + 'Patron last seen should be changed after a hold if we cleared the cache' + ); + $cache->clear_from_cache($cache_key); $patron->update_lastseen('renewal'); $patron->_result()->discard_changes(); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index c329222a54..9dd6a0b04b 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -1488,12 +1488,14 @@ subtest 'IsAvailableForItemLevelRequest() tests' => sub { subtest 'AddReserve() tests' => sub { - plan tests => 1; + plan tests => 2; $schema->storage->txn_begin; - my $library = $builder->build_object({ class => 'Koha::Libraries' }); - my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'hold' ); + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { lastseen => undef } } ); my $biblio = $builder->build_sample_biblio; my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); @@ -1526,6 +1528,9 @@ subtest 'AddReserve() tests' => sub { } ); + $patron->discard_changes; + isnt( $patron->lastseen, undef, "Patron activity tracked when hold is a valid trigger" ); + $schema->storage->txn_rollback; }; -- 2.30.2