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 379-385 if($allDebarments) { Link Here
379
    }
379
    }
380
}
380
}
381
381
382
# Lock expired patrons?
383
my $days = C4::Context->preference('LockExpiredDelay');
384
if( defined $days && $days ne q{} ) {
385
    say "Start locking expired patrons" if $verbose;
386
    my $expired_patrons = Koha::Patrons->search_expired({ days => $days })->search({ login_attempts => { '!=' => -1 } });
387
    my $count = $expired_patrons->count;
388
    $expired_patrons->lock({ remove => 1 }) if $confirm;
389
    if( $verbose ) {
390
        say $confirm ? sprintf("Locked %d patrons", $count) : sprintf("Found %d patrons", $count);
391
    }
392
}
393
382
# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference
394
# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference
395
say "Start lock unsubscribed, anonymize and delete" if $verbose;
383
my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed;
396
my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed;
384
my $count = $unsubscribed_patrons->count;
397
my $count = $unsubscribed_patrons->count;
385
$unsubscribed_patrons->lock( { expire => 1, remove => 1 } ) if $confirm;
398
$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 1861-1866 subtest '->set_password' => sub { Link Here
1861
};
1861
};
1862
1862
1863
$schema->storage->txn_begin;
1863
$schema->storage->txn_begin;
1864
subtest 'search_expired' => sub {
1865
    plan tests => 3;
1866
    my $count1 = Koha::Patrons->search_expired({ days => 28 })->count;
1867
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
1868
    $patron1->dateexpiry( dt_from_string->subtract(days => 27) )->store;
1869
    is( Koha::Patrons->search_expired({ days => 28 })->count, $count1, 'No more expired' );
1870
    $patron1->dateexpiry( dt_from_string->subtract(days => 28) )->store;
1871
    is( Koha::Patrons->search_expired({ days => 28 })->count, $count1 + 1, 'One more expired' );
1872
    $patron1->dateexpiry( dt_from_string->subtract(days => 29) )->store;
1873
    is( Koha::Patrons->search_expired({ days => 28 })->count, $count1 + 1, 'Same number again' );
1874
};
1875
1864
subtest 'search_unsubscribed' => sub {
1876
subtest 'search_unsubscribed' => sub {
1865
    plan tests => 4;
1877
    plan tests => 4;
1866
1878
1867
- 

Return to bug 21549