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

(-)a/Koha/Patrons.pm (+18 lines)
Lines 233-238 sub delete { Link Here
233
    return $patrons_deleted;
233
    return $patrons_deleted;
234
}
234
}
235
235
236
=head3 search_expired
237
238
    Koha::Patrons->search_expired{{ days => $x });
239
240
    Returns set of Koha patron objects expired $x days.
241
242
=cut
243
244
sub search_expired {
245
    my ( $class, $params ) = @_;
246
    my $days = $params->{days} || 0;
247
    my $parser = Koha::Database->new->schema->storage->datetime_parser;
248
    my $dt = dt_from_string()->subtract( days => $days );
249
    return $class->search({
250
        dateexpiry => { '<=' => $parser->format_datetime($dt) },
251
    });
252
}
253
236
=head3 search_unsubscribed
254
=head3 search_unsubscribed
237
255
238
    Koha::Patrons->search_unsubscribed;
256
    Koha::Patrons->search_unsubscribed;
(-)a/misc/cronjobs/cleanup_database.pl (+13 lines)
Lines 400-406 if($allDebarments) { Link Here
400
    }
400
    }
401
}
401
}
402
402
403
# Lock expired patrons?
404
my $days = C4::Context->preference('LockExpiredDelay');
405
if( defined $days && $days ne q{} ) {
406
    say "Start locking expired patrons" if $verbose;
407
    my $expired_patrons = Koha::Patrons->search_expired({ days => $days })->search({ login_attempts => { '!=' => -1 } });
408
    my $count = $expired_patrons->count;
409
    $expired_patrons->lock({ remove => 1 }) if $confirm;
410
    if( $verbose ) {
411
        say $confirm ? sprintf("Locked %d patrons", $count) : sprintf("Found %d patrons", $count);
412
    }
413
}
414
403
# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference
415
# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference
416
say "Start lock unsubscribed, anonymize and delete" if $verbose;
404
my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed;
417
my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed;
405
my $count = $unsubscribed_patrons->count;
418
my $count = $unsubscribed_patrons->count;
406
$unsubscribed_patrons->lock( { expire => 1, remove => 1 } ) if $confirm;
419
$unsubscribed_patrons->lock( { expire => 1, remove => 1 } ) if $confirm;
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +13 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 41;
22
use Test::More tests => 42;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 1798-1803 subtest '->set_password' => sub { Link Here
1798
};
1798
};
1799
1799
1800
$schema->storage->txn_begin;
1800
$schema->storage->txn_begin;
1801
subtest 'search_expired' => sub {
1802
    plan tests => 3;
1803
    my $count1 = Koha::Patrons->search_expired({ days => 28 })->count;
1804
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
1805
    $patron1->dateexpiry( dt_from_string->subtract(days => 27) )->store;
1806
    is( Koha::Patrons->search_expired({ days => 28 })->count, $count1, 'No more expired' );
1807
    $patron1->dateexpiry( dt_from_string->subtract(days => 28) )->store;
1808
    is( Koha::Patrons->search_expired({ days => 28 })->count, $count1 + 1, 'One more expired' );
1809
    $patron1->dateexpiry( dt_from_string->subtract(days => 29) )->store;
1810
    is( Koha::Patrons->search_expired({ days => 28 })->count, $count1 + 1, 'Same number again' );
1811
};
1812
1801
subtest 'search_unsubscribed' => sub {
1813
subtest 'search_unsubscribed' => sub {
1802
    plan tests => 4;
1814
    plan tests => 4;
1803
1815
1804
- 

Return to bug 21549