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

(-)a/C4/Auth.pm (-5 / +4 lines)
Lines 35-40 use Koha; 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::LibraryCategories;
36
use Koha::LibraryCategories;
37
use Koha::Libraries;
37
use Koha::Libraries;
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 1184-1194 sub checkauth { Link Here
1184
        }
1185
        }
1185
1186
1186
        if ( $userid ) {
1187
        if ( $userid ) {
1187
            $dbh->do(q|
1188
            # track_login also depends on pref TrackLastPatronActivity
1188
                UPDATE borrowers
1189
            my $patron = Koha::Patrons->search({ userid => $userid })->next;
1189
                SET lastseen = NOW()
1190
            $patron->track_login if $patron;
1190
                WHERE userid = ?
1191
            |, undef, $userid);
1192
        }
1191
        }
1193
1192
1194
        return ( $userid, $cookie, $sessionID, $flags );
1193
        return ( $userid, $cookie, $sessionID, $flags );
(-)a/Koha/Patron.pm (+19 lines)
Lines 208-213 sub update_password { Link Here
208
    return 1;
208
    return 1;
209
}
209
}
210
210
211
=head2 track_login
212
213
    $patron->track_login;
214
    $patron->track_login({ force => 1 });
215
216
    Tracks a (successful) login attempt.
217
    The preference TrackLastPatronActivity must be enabled. Or you
218
    should pass the force parameter.
219
220
=cut
221
222
sub track_login {
223
    my ( $self, $params ) = @_;
224
    return if
225
        !$params->{force} &&
226
        !C4::Context->preference('TrackLastPatronActivity');
227
    $self->lastseen( dt_from_string() )->store;
228
}
229
211
=head3 type
230
=head3 type
212
231
213
=cut
232
=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