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

(-)a/Koha/Patron.pm (-3 / +8 lines)
Lines 400-408 sub has_overdues { Link Here
400
400
401
sub track_login {
401
sub track_login {
402
    my ( $self, $params ) = @_;
402
    my ( $self, $params ) = @_;
403
    return if
403
404
        !$params->{force} &&
404
    warn "track_login()";
405
        !C4::Context->preference('TrackLastPatronActivity');
405
    return unless C4::Context->preference('TrackLastPatronActivity') || $params->{force};
406
    warn "Pref set OR forced";
407
    return if C4::Context->userenv->{'tracked_for_session'} && !$params->{force};
408
    warn "Untracked OR forced";
409
410
    C4::Context->userenv->{'tracked_for_session'} = 1;
406
    $self->lastseen( dt_from_string() )->store;
411
    $self->lastseen( dt_from_string() )->store;
407
}
412
}
408
413
(-)a/t/db_dependent/Members.t (-3 / +18 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 65;
20
use Test::More tests => 67;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Data::Dumper qw/Dumper/;
22
use Data::Dumper qw/Dumper/;
23
use C4::Context;
23
use C4::Context;
Lines 356-367 $patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' }); Link Here
356
is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' );
356
is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' );
357
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' });
357
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' });
358
is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' );
358
is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' );
359
360
361
# Test method last_seen / TrackLastPatronActivity
359
my $patron2 = $builder->build({ source => 'Borrower', value => { lastseen => undef } });
362
my $patron2 = $builder->build({ source => 'Borrower', value => { lastseen => undef } });
360
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' );
363
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' );
361
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login;
364
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login;
362
is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should not be changed' );
365
is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should not be changed' );
366
363
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 });
367
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 });
364
isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should be changed now' );
368
my $last_seen = Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen;
369
isnt( $last_seen, undef, 'Lastseen should be changed now' );
370
371
# Last seen shouldn't be updated a second time for this session
372
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' );
373
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login();
374
is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, $last_seen, 'Lastseen should not be changed' );
375
376
# If it's forced, it should still be updated
377
sleep(1); # We need to wait a tiny bit to make sure the timestamp will be different
378
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 });
379
isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, $last_seen, 'Lastseen should be changed if forced' );
380
365
381
366
# Regression tests for BZ13502
382
# Regression tests for BZ13502
367
## Remove all entries with userid='' (should be only 1 max)
383
## Remove all entries with userid='' (should be only 1 max)
368
- 

Return to bug 18821