Bug 24114: Remove warn statements from Koha::Patrons
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 26 Nov 2019 10:11:35 +0000 (11:11 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 24 Feb 2020 13:17:39 +0000 (13:17 +0000)
The warn must be done in the cronjob.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
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 <bouzid.fergani@inlibro.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Patrons.pm
misc/cronjobs/cleanup_database.pl

index f4ca845..2257492 100644 (file)
@@ -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
index b0f60b2..7ca7b33 100755 (executable)
@@ -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();