Bug 35027: Add 'hold' to patron activity triggers

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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2023-10-12 12:40:17 +01:00 committed by Tomas Cohen Arazi
parent e1a4284258
commit 795c60e577
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
4 changed files with 39 additions and 7 deletions

View file

@ -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',

View file

@ -107,6 +107,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:

View file

@ -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();

View file

@ -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;
};