View | Details | Raw Unified | Return to bug 15504
Collapse All | Expand All

(-)a/C4/Auth.pm (-30 / +2 lines)
Lines 1318-1324 sub checkauth { Link Here
1318
            ));
1318
            ));
1319
        }
1319
        }
1320
1320
1321
        track_login_daily( $userid, 'login' );
1321
        my $patron = Koha::Patrons->find({ userid => $userid });
1322
        $patron->update_lastseen('login');
1322
1323
1323
        # In case, that this request was a login attempt, we want to prevent that users can repost the opac login
1324
        # In case, that this request was a login attempt, we want to prevent that users can repost the opac login
1324
        # request. We therefore redirect the user to the requested page again without the login parameters.
1325
        # request. We therefore redirect the user to the requested page again without the login parameters.
Lines 2344-2378 sub getborrowernumber { Link Here
2344
    return 0;
2345
    return 0;
2345
}
2346
}
2346
2347
2347
=head2 track_login_daily
2348
2349
    track_login_daily( $userid );
2350
2351
Wraps the call to $patron->track_login, the method used to update borrowers.lastseen. We only call track_login once a day.
2352
2353
=cut
2354
2355
sub track_login_daily {
2356
    my $userid = shift;
2357
    my $activity = shift;
2358
    return if !$userid || !$activity || !C4::Context->preference('TrackLastPatronActivity');
2359
2360
    my $cache     = Koha::Caches->get_instance();
2361
    my $cache_key = "track_login_" . $userid;
2362
    my $cached    = $cache->get_from_cache($cache_key);
2363
    my $today = dt_from_string()->ymd;
2364
    return if $cached && $cached eq $today;
2365
2366
    my $patron = Koha::Patrons->find({ userid => $userid });
2367
    return unless $patron;
2368
2369
    my $tracked_activities = { map { (lc $_, 1); } split /\s*\,\s*/, C4::Context->preference('TrackLastPatronActivityTriggers') };
2370
    return unless $tracked_activities->{$activity};
2371
2372
    $patron->track_login;
2373
    $cache->set_in_cache( $cache_key, $today );
2374
}
2375
2376
END { }    # module clean-up code here (global destructor)
2348
END { }    # module clean-up code here (global destructor)
2377
1;
2349
1;
2378
__END__
2350
__END__
(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 1682-1688 sub AddIssue { Link Here
1682
                )->store;
1682
                )->store;
1683
            }
1683
            }
1684
            $issue->discard_changes;
1684
            $issue->discard_changes;
1685
            C4::Auth::track_login_daily( $borrower->{userid}, 'check_out' );
1685
            $patron->update_lastseen('check_out');
1686
            if ( $item_object->location && $item_object->location eq 'CART'
1686
            if ( $item_object->location && $item_object->location eq 'CART'
1687
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1687
                && ( !$item_object->permanent_location || $item_object->permanent_location ne 'CART' ) ) {
1688
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
1688
            ## Item was moved to cart via UpdateItemLocationOnCheckin, anything issued should be taken off the cart.
Lines 2477-2483 sub AddReturn { Link Here
2477
            if C4::Context->preference("ReturnLog");
2477
            if C4::Context->preference("ReturnLog");
2478
2478
2479
        #Update borrowers.lastseen
2479
        #Update borrowers.lastseen
2480
        C4::Auth::track_login_daily( $patron->userid, 'check_in' );
2480
        $patron->update_lastseen('check_in');
2481
    }
2481
    }
2482
2482
2483
    # Check if this item belongs to a biblio record that is attached to an
2483
    # Check if this item belongs to a biblio record that is attached to an
Lines 3327-3333 sub AddRenewal { Link Here
3327
            }
3327
            }
3328
        );
3328
        );
3329
        #Update borrowers.lastseen
3329
        #Update borrowers.lastseen
3330
        C4::Auth::track_login_daily( $patron_unblessed->{userid}, 'renewal' );
3330
        $patron->update_lastseen('renewal');
3331
3331
3332
        #Log the renewal
3332
        #Log the renewal
3333
        logaction("CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber) if C4::Context->preference("RenewalLog");
3333
        logaction("CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber) if C4::Context->preference("RenewalLog");
(-)a/C4/ILSDI/Services.pm (-2 / +2 lines)
Lines 396-405 sub AuthenticatePatron { Link Here
396
    my $password = $cgi->param('password');
396
    my $password = $cgi->param('password');
397
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( $username, $password );
397
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( $username, $password );
398
    if ( $status == 1 ) {
398
    if ( $status == 1 ) {
399
        # Track the login
400
        C4::Auth::track_login_daily( $userid, 'connection' );
401
        # Get the borrower
399
        # Get the borrower
402
        my $patron = Koha::Patrons->find( { userid => $userid } );
400
        my $patron = Koha::Patrons->find( { userid => $userid } );
401
        # Track the login
402
        $patron->update_lastseen('connection');
403
        return { id => $patron->borrowernumber };
403
        return { id => $patron->borrowernumber };
404
    }
404
    }
405
    elsif ( $status == -2 ){
405
    elsif ( $status == -2 ){
(-)a/C4/SIP/Sip/MsgType.pm (-1 / +5 lines)
Lines 16-21 use C4::SIP::Sip::Checksum qw(verify_cksum); Link Here
16
16
17
use Data::Dumper;
17
use Data::Dumper;
18
use CGI qw ( -utf8 );
18
use CGI qw ( -utf8 );
19
use C4::Context;
19
use C4::Auth qw(&check_api_auth);
20
use C4::Auth qw(&check_api_auth);
20
use C4::Items qw(ModDateLastSeen);
21
use C4::Items qw(ModDateLastSeen);
21
22
Lines 995-1001 sub handle_patron_info { Link Here
995
996
996
    $resp = (PATRON_INFO_RESP);
997
    $resp = (PATRON_INFO_RESP);
997
    if ($patron) {
998
    if ($patron) {
998
        C4::Auth::track_login_daily( $patron->userid, 'connection' );
999
        if ( C4::Context->preference('TrackLastPatronActivity') ) {
1000
            my $koha_patron = Koha::Patrons->find($patron->userid);
1001
            $koha_patron->update_lastseen('connection');
1002
        }
999
        $resp .= patron_status_string( $patron, $server );
1003
        $resp .= patron_status_string( $patron, $server );
1000
        $resp .= ( defined($lang) and length($lang) == 3 ) ? $lang : $patron->language;
1004
        $resp .= ( defined($lang) and length($lang) == 3 ) ? $lang : $patron->language;
1001
        $resp .= timestamp();
1005
        $resp .= timestamp();
(-)a/Koha/Patron.pm (-13 / +24 lines)
Lines 32-37 use Koha::Account; Link Here
32
use Koha::ArticleRequests;
32
use Koha::ArticleRequests;
33
use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
33
use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
34
use Koha::AuthUtils;
34
use Koha::AuthUtils;
35
use Koha::Caches;
35
use Koha::Checkouts;
36
use Koha::Checkouts;
36
use Koha::CirculationRules;
37
use Koha::CirculationRules;
37
use Koha::Club::Enrollments;
38
use Koha::Club::Enrollments;
Lines 998-1020 sub has_overdues { Link Here
998
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
999
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
999
}
1000
}
1000
1001
1001
=head3 track_login
1002
=head3 update_lastseen
1002
1003
1003
    $patron->track_login;
1004
  $patron->update_lastseen('activity');
1004
    $patron->track_login({ force => 1 });
1005
1005
1006
    Tracks a (successful) login attempt.
1006
Tracks a (successful) login attempt when the TrackLastPatronActivity preference is enabled
1007
    The preference TrackLastPatronActivity must be enabled. Or you
1007
and the activity passed is in the TrackLastPatronActivityTriggers list.
1008
    should pass the force parameter.
1009
1008
1010
=cut
1009
=cut
1011
1010
1012
sub track_login {
1011
sub update_lastseen {
1013
    my ( $self, $params ) = @_;
1012
    my ( $self, $activity ) = @_;
1014
    return if
1013
    return $self if !C4::Context->preference('TrackLastPatronActivity');
1015
        !$params->{force} &&
1014
1016
        !C4::Context->preference('TrackLastPatronActivity');
1015
    my $tracked_activities = {
1017
    $self->lastseen( dt_from_string() )->store;
1016
        map { ( lc $_, 1 ); } split /\s*\,\s*/,
1017
        C4::Context->preference('TrackLastPatronActivityTriggers')
1018
    };
1019
    return $self unless $tracked_activities->{$activity};
1020
1021
    my $cache     = Koha::Caches->get_instance();
1022
    my $cache_key = "track_login_" . $self->userid;
1023
    my $cached    = $cache->get_from_cache($cache_key);
1024
    my $now       = dt_from_string();
1025
    return if $cached && $cached eq $now->ymd;
1026
1027
    $self->lastseen($now)->store;
1028
    $cache->set_in_cache( $cache_key, $now->ymd );
1029
    return $self;
1018
}
1030
}
1019
1031
1020
=head3 move_to_deleted
1032
=head3 move_to_deleted
1021
- 

Return to bug 15504