Bug 23486: Add creation to TrackLasPatronActivity triggers

Some libraries would like to update the last seen when a patron is created to avoid NULL
values and ensure new users are marked as 'active'

To test:
1 - Apply patch
2 - Create a new patron, confirm their lastseen date is null
    SELECT lastseen FROM borrowers WHERE cardnumber={their cardnumber}
3 - Update preference 'TrackLastPatronActivity' to include 'Patron creation'
4 - Create a second patron, confirm their lastseen is set
5 - Update preference 'TrackLastPatronActivity' to include 'Checking out an item'
6 - Checkout an item to the second patron
7 - Confirm their lastseen is not updated (We only update once per day)

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Nick Clemens 2024-09-20 12:38:42 +00:00 committed by Katrin Fischer
parent 75a79d2e5c
commit ad610c8211
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 34 additions and 8 deletions

View File

@ -335,6 +335,9 @@ sub store {
$self->add_enrolment_fee_if_needed(0);
$self->discard_changes;
$self->update_lastseen('creation');
logaction( "MEMBERS", "CREATE", $self->borrowernumber, "" )
if C4::Context->preference("BorrowersLog");
} else { #ModMember

View File

@ -102,6 +102,7 @@ Patrons:
- Select which patron activities should be tracked to signify patron activity. Each time that one of these activities occurs, borrowers.lastseen will update with the current date and time.
- pref: TrackLastPatronActivityTriggers
multiple:
creation: "Patron creation"
login: "Logging in"
connection: "Connecting to Koha via SIP or ILSDI"
check_out: "Checking out an item"

View File

@ -2129,27 +2129,49 @@ subtest 'test patron_consent' => sub {
subtest 'update_lastseen tests' => sub {
plan tests => 24;
plan tests => 26;
$schema->storage->txn_begin;
my $cache = Koha::Caches->get_instance();
t::lib::Mocks::mock_preference(
'TrackLastPatronActivityTriggers',
'creation,login,connection,check_in,check_out,renewal,hold,article'
);
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $userid = $patron->userid;
$patron->lastseen(undef);
$patron->store();
my $patron_info = $patron->unblessed;
delete $patron_info->{borrowernumber};
$patron->delete();
$patron = Koha::Patron->new($patron_info)->store();
my $cache = Koha::Caches->get_instance();
my $cache_key = "track_activity_" . $patron->borrowernumber;
$cache->clear_from_cache($cache_key);
my $now = dt_from_string();
my $today = $now->ymd();
is(
dt_from_string( $patron->lastseen )->ymd(), $today,
'Patron should have last seen when newly created if requested'
);
my $cache_key = "track_activity_" . $patron->borrowernumber;
my $cache_value = $cache->get_from_cache($cache_key);
is( $cache_value, $today, "Cache was updated as expected" );
$patron->delete();
t::lib::Mocks::mock_preference(
'TrackLastPatronActivityTriggers',
'login,connection,check_in,check_out,renewal,hold,article'
);
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' );
$patron = Koha::Patron->new($patron_info)->store();
$cache_key = "track_activity_" . $patron->borrowernumber;
my $now = dt_from_string();
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created if trigger not set' );
$now = dt_from_string();
Time::Fake->offset( $now->epoch );
$patron->update_lastseen('login');