From 7399a8de944674dfdb1ffb9dd014427d7750dd14 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 26 Nov 2019 11:11:35 +0100 Subject: [PATCH] Bug 24114: Remove warn statements from Koha::Patrons The warn must be done in the cronjob. Signed-off-by: Marcel de Rooy Followed this test plan (with two follow-ups applied): [1] Prefs: UnsubscribeReflectionDelay=1, PatronAnonymizeDelay=2, PatronRemovalDelay=3, FailedLoginAttempts was undef [2] Pick borrower and set expiry to NOW-2, and lock him (login_attempts=-1) Could be achieved too by settings FailedLoginAttempts and trying wrong passwords. Run cleanup job: Locked 0 patrons Anonymized 1 patrons Deleted 0 patrons [3] Pick borrower, set expiry to NOW-3. Run cleanup job: Locked 0 patrons Anonymized 0 patrons Deleted 1 patrons Signed-off-by: Bouzid Fergani Signed-off-by: Martin Renvoize Signed-off-by: Joy Nelson (cherry picked from commit d7f922eb63c420375f42ab419d9db154650fbd4d) Signed-off-by: Lucas Gass --- Koha/Patrons.pm | 17 ++++------------- misc/cronjobs/cleanup_database.pl | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index c113c2c465..8971a081ec 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -212,7 +212,7 @@ sub anonymise_issue_history { =head3 delete - Koha::Patrons->search({ some filters here })->delete({ move => 1, verbose => 1 }); + Koha::Patrons->search({ some filters here })->delete({ move => 1 }); Delete passed set of patron objects. Wrapper for Koha::Patron->delete. (We do not want to bypass Koha::Patron @@ -235,7 +235,6 @@ sub delete { $patron->delete == 1 || Koha::Exceptions::Patron::FailedDelete->throw; $patrons_deleted++; } - warn "Deleted $count patrons\n" if $params->{verbose}; }, $self, $params ); return $patrons_deleted; } @@ -332,10 +331,9 @@ sub search_anonymized { =head3 lock - Koha::Patrons->search({ some filters })->lock({ expire => 1, remove => 1, verbose => 1 }) + Koha::Patrons->search({ some filters })->lock({ expire => 1, remove => 1 }) Lock the passed set of patron objects. Optionally expire and remove holds. - Optional verbose flag is used in cron job. Wrapper around Koha::Patron->lock. =cut @@ -346,30 +344,23 @@ sub lock { while( my $patron = $self->next ) { $patron->lock($params); } - if( $params->{verbose} ) { - warn "Locked $count patrons\n"; - } } =head3 anonymize - Koha::Patrons->search({ some filters })->anonymize({ verbose => 1 }); + Koha::Patrons->search({ some filters })->anonymize(); Anonymize passed set of patron objects. - Optional verbose flag is used in cron job. Wrapper around Koha::Patron->anonymize. =cut sub anonymize { - my ( $self, $params ) = @_; + my ( $self ) = @_; my $count = $self->count; while( my $patron = $self->next ) { $patron->anonymize; } - if( $params->{verbose} ) { - warn "Anonymized $count patrons\n"; - } } =head3 _type diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 975aaabd2a..964214122b 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -306,12 +306,24 @@ if($allDebarments) { } # Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference -Koha::Patrons->search_unsubscribed->lock({ expire => 1, remove => 1, verbose => $verbose }); +my $unsubscribed_patrons = Koha::Patrons->search_unsubscribed; +$unsubscribed_patrons->lock( { expire => 1, remove => 1 } ); +say sprintf "Locked %d patrons", $unsubscribed_patrons->count if $verbose; + # Anonymize patron data, depending on PatronAnonymizeDelay -Koha::Patrons->search_anonymize_candidates({ locked => 1 })->anonymize({ verbose => $verbose }); +my $anonymize_candidates = Koha::Patrons->search_anonymize_candidates( { locked => 1 } ); +$anonymize_candidates->anonymize; +say sprintf "Anonymized %s patrons", $anonymize_candidates->count if $verbose; + # Remove patron data, depending on PatronRemovalDelay (will raise an exception if problem encountered -eval { Koha::Patrons->search_anonymized->delete({ move => 1, verbose => $verbose }) }; -warn $@ if $@; +my $anonymized_patrons = Koha::Patrons->search_anonymized; +$anonymized_patrons->delete( { move => 1 } ); +if ($@) { + warn $@; +} +elsif ($verbose) { + say sprintf "Deleted %d patrons", $anonymized_patrons->count; +} if( $pExpSelfReg ) { DeleteExpiredSelfRegs(); -- 2.39.5