From 7e1db56dd8a0f70792fc9c1f8eb66423a9611944 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 --- 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 f4ca8456a6..22574923d6 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -202,7 +202,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 @@ -229,7 +229,6 @@ sub delete { $patrons_deleted++; } - warn "Deleted $count patrons\n" if $params->{verbose}; }, $self, $params ); return $patrons_deleted; } @@ -326,10 +325,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 @@ -340,30 +338,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 search_patrons_to_update_category diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index b0f60b2cc3..7ca7b33177 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -331,12 +331,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