Bugzilla – Attachment 119457 Details for
Bug 21549
Lock expired patron accounts after x days
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21549: Lock expired patron accounts
Bug-21549-Lock-expired-patron-accounts.patch (text/plain), 3.76 KB, created by
Jonathan Druart
on 2021-04-12 14:23:28 UTC
(
hide
)
Description:
Bug 21549: Lock expired patron accounts
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-04-12 14:23:28 UTC
Size:
3.76 KB
patch
obsolete
>From 8de30deb81803868f8ab4d9870b7e417fb11879c Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 11 Oct 2018 15:34:48 +0200 >Subject: [PATCH] Bug 21549: Lock expired patron accounts > >Adding a search on locked patrons to the search_expired in cron script. >This prevents relocking. > >Test plan: >Prove Koha/Patrons.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Michal Denar <black23@gmail.com> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/Patrons.pm | 18 ++++++++++++++++++ > misc/cronjobs/cleanup_database.pl | 13 +++++++++++++ > t/db_dependent/Koha/Patrons.t | 14 +++++++++++++- > 3 files changed, 44 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm >index 3b3b4b1cb61..9a3977704fa 100644 >--- a/Koha/Patrons.pm >+++ b/Koha/Patrons.pm >@@ -233,6 +233,24 @@ sub delete { > return $patrons_deleted; > } > >+=head3 search_expired >+ >+ Koha::Patrons->search_expired{{ days => $x }); >+ >+ Returns set of Koha patron objects expired $x days. >+ >+=cut >+ >+sub search_expired { >+ my ( $class, $params ) = @_; >+ my $days = $params->{days} || 0; >+ my $parser = Koha::Database->new->schema->storage->datetime_parser; >+ my $dt = dt_from_string()->subtract( days => $days ); >+ return $class->search({ >+ dateexpiry => { '<=' => $parser->format_datetime($dt) }, >+ }); >+} >+ > =head3 search_unsubscribed > > Koha::Patrons->search_unsubscribed; >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index 062efe60414..07bd2622f9f 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -400,7 +400,20 @@ if($allDebarments) { > } > } > >+# Lock expired patrons? >+my $days = C4::Context->preference('LockExpiredDelay'); >+if( defined $days && $days ne q{} ) { >+ say "Start locking expired patrons" if $verbose; >+ my $expired_patrons = Koha::Patrons->search_expired({ days => $days })->search({ login_attempts => { '!=' => -1 } }); >+ my $count = $expired_patrons->count; >+ $expired_patrons->lock({ remove => 1 }) if $confirm; >+ if( $verbose ) { >+ say $confirm ? sprintf("Locked %d patrons", $count) : sprintf("Found %d patrons", $count); >+ } >+} >+ > # Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference >+say "Start lock unsubscribed, anonymize and delete" if $verbose; > my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed; > my $count = $unsubscribed_patrons->count; > $unsubscribed_patrons->lock( { expire => 1, remove => 1 } ) if $confirm; >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 8d77adbc646..a8edcd6d941 100755 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 40; >+use Test::More tests => 41; > use Test::Warn; > use Test::Exception; > use Test::MockModule; >@@ -1798,6 +1798,18 @@ subtest '->set_password' => sub { > }; > > $schema->storage->txn_begin; >+subtest 'search_expired' => sub { >+ plan tests => 3; >+ my $count1 = Koha::Patrons->search_expired({ days => 28 })->count; >+ my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); >+ $patron1->dateexpiry( dt_from_string->subtract(days => 27) )->store; >+ is( Koha::Patrons->search_expired({ days => 28 })->count, $count1, 'No more expired' ); >+ $patron1->dateexpiry( dt_from_string->subtract(days => 28) )->store; >+ is( Koha::Patrons->search_expired({ days => 28 })->count, $count1 + 1, 'One more expired' ); >+ $patron1->dateexpiry( dt_from_string->subtract(days => 29) )->store; >+ is( Koha::Patrons->search_expired({ days => 28 })->count, $count1 + 1, 'Same number again' ); >+}; >+ > subtest 'search_unsubscribed' => sub { > plan tests => 4; > >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21549
:
108000
|
108001
|
111480
|
111481
|
113914
|
113915
|
118493
|
118494
|
118495
|
118496
|
118517
|
118518
|
118519
|
118520
|
118521
| 119457 |
119458
|
119459
|
119460
|
119461
|
119462
|
119463
|
119464
|
119525
|
119526
|
119527