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

(-)a/C4/Auth.pm (-5 / +4 lines)
Lines 35-40 use Koha::Caches; Link Here
35
use Koha::AuthUtils qw(get_script_name hash_password);
35
use Koha::AuthUtils qw(get_script_name hash_password);
36
use Koha::Libraries;
36
use Koha::Libraries;
37
use Koha::LibraryCategories;
37
use Koha::LibraryCategories;
38
use Koha::Patrons;
38
use POSIX qw/strftime/;
39
use POSIX qw/strftime/;
39
use List::MoreUtils qw/ any /;
40
use List::MoreUtils qw/ any /;
40
use Encode qw( encode is_utf8);
41
use Encode qw( encode is_utf8);
Lines 1183-1193 sub checkauth { Link Here
1183
        }
1184
        }
1184
1185
1185
        if ( $userid ) {
1186
        if ( $userid ) {
1186
            $dbh->do(q|
1187
            # track_login also depends on pref TrackLastPatronActivity
1187
                UPDATE borrowers
1188
            my $patron = Koha::Patrons->search({ userid => $userid })->next;
1188
                SET lastseen = NOW()
1189
            $patron->track_login if $patron;
1189
                WHERE userid = ?
1190
            |, undef, $userid);
1191
        }
1190
        }
1192
1191
1193
        return ( $userid, $cookie, $sessionID, $flags );
1192
        return ( $userid, $cookie, $sessionID, $flags );
(-)a/Koha/Patron.pm (+19 lines)
Lines 248-253 sub has_overdues { Link Here
248
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
248
    return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
249
}
249
}
250
250
251
=head2 track_login
252
253
    $patron->track_login;
254
    $patron->track_login({ force => 1 });
255
256
    Tracks a (successful) login attempt.
257
    The preference TrackLastPatronActivity must be enabled. Or you
258
    should pass the force parameter.
259
260
=cut
261
262
sub track_login {
263
    my ( $self, $params ) = @_;
264
    return if
265
        !$params->{force} &&
266
        !C4::Context->preference('TrackLastPatronActivity');
267
    $self->lastseen( dt_from_string() )->store;
268
}
269
251
=head3 type
270
=head3 type
252
271
253
=cut
272
=cut
(-)a/t/db_dependent/Members.t (-3 / +8 lines)
Lines 17-30 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 82;
20
use Test::More tests => 84;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Data::Dumper;
22
use Data::Dumper;
23
use C4::Context;
23
use C4::Context;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Holds;
25
use Koha::Holds;
26
use Koha::List::Patron;
26
use Koha::List::Patron;
27
27
use Koha::Patrons;
28
28
29
use t::lib::Mocks;
29
use t::lib::Mocks;
30
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
Lines 387-392 $patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' }); Link Here
387
is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' );
387
is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' );
388
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' });
388
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' });
389
is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' );
389
is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' );
390
my $patron2 = $builder->build({ source => 'Borrower', value => { lastseen => undef } });
391
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' );
392
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login;
393
is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should not be changed' );
394
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 });
395
isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should be changed now' );
390
396
391
# Regression tests for BZ13502
397
# Regression tests for BZ13502
392
## Remove all entries with userid='' (should be only 1 max)
398
## Remove all entries with userid='' (should be only 1 max)
393
- 

Return to bug 16276