Test major Koha Wiki changes or bug fixes here without fear of breaking the production wiki.
For the current Koha Wiki, visit https://wiki.koha-community.org .Updating borrowers.lastseen
Note: The descriptions below are based on the code in the master branch as of 2018-05-07.
Database field and syspref
In the "borrowers" table, there is a field called "lastseen". The comment for this field reads:
last time a patron has been seen (connected at the OPAC or staff interface)
In order to use this field, the syspref "TrackLastPatronActivity" must be switched on. The description for this is:
[Do|Don't] track last patron activity. Everytime a patron will connect, the borrowers.lastseen will be updated with the current time.
The database field and syspref were introduced in "Bug 16276 - When automatically deleting expired borrowers, make sure they didn't log in recently". It looks like the original intent was only to track logins, not circulation events.
Koha::Patron::track_login()
This is the subroutine that does the actual update:
474 =head3 track_login 475 476 $patron->track_login; 477 $patron->track_login({ force => 1 }); 478 479 Tracks a (successful) login attempt. 480 The preference TrackLastPatronActivity must be enabled. Or you 481 should pass the force parameter. 482 483 =cut 484 485 sub track_login { 486 my ( $self, $params ) = @_; 487 return if 488 !$params->{force} && 489 !C4::Context->preference('TrackLastPatronActivity'); 490 $self->lastseen( dt_from_string() )->store; 491 }
Login
C4::Auth::checkauth() calls Koha::Patron::track_login().
This gets called on every page load.
SIP2
Patron info
In C4::SIP::Sip::MsgType::handle_patron_info() there is a call to C4::SIP::ILS::Patron::update_lastseen(), which again calls Koha::Patron::track_login().
This was added in 18.05: Bug 18625 - Update borrower last seen from SIP
REST API
Can external services use the REST API for authenticating patrons now? If so, this should also update borrowers.lastseen.
ILS-DI
ILS-DI can be used by third parties to authenticate patrons who want to use external services. This should also update borrowers.lastseen.
Extend borrowers.lastseen to circ events?
Libraries wanting to be compliant with GDPR will want to delete patrons who have not been "active" in the last X months, or similar. Being active might mean at least two things:
- Checking out books etc
- Using the library facilities in other ways, like logging into services the library subscribes to
The last part is covered by borrowers.lastseen, both for logging into the OPAC and for logging in to services via SIP2. But if borrowing history is anonymized (which it will surely be for a GDPR-compliant library), a patron could borrow lots of books and not leave a trace of it after anonymization.
The question then is, would it make sense to extend the use of borrowers.lastseen to also track circ events? If so, we would need to catch events from:
- Circulation in the staff client
- Processing .koc files
- Self Checkout
- Circ actions via SIP2
Relevant bugs
- Bug 18821 - TrackLastPatronActivity is a performance killer