From e914ad2e7679836ca6cb4f40bc878fb6cbfb872c Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 12 Sep 2018 14:25:26 +0200 Subject: [PATCH] Bug 21336: Adjust cleanup_database.pl Add the new Patron routines to this cron job. Actions are performed only if preferences are set. Note: No specific command line flags for these actions are added here (and probably not needed too). So no crontab changes too. Test plan: Add a new patron. Enable GDPR_Policy and refuse consent on OPAC for this patron. Set only the first delay to zero (0) for immediate action. Run cleanup_database.pl --logs (or any other flag) for the first time. Check lock and expiration. Set the second delay to zero (0) for immediate action. Run cleanup_database.pl --logs for the second time. Check anonymization. Set the third delay to zero (0) for immediate action. Run cleanup_database.pl --logs for the third time. Check removal. Signed-off-by: Marcel de Rooy Amended: Added the warn $@ line in cleanup_database.pl Signed-off-by: Josef Moravec --- Koha/Patrons.pm | 20 ++++++++++++++++---- misc/cronjobs/cleanup_database.pl | 8 ++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 7da0655fb2..b35e6cc4a8 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -210,7 +210,7 @@ sub anonymise_issue_history { =head3 delete - Koha::Patrons->search({ some filters here })->delete({ move => 1 }); + Koha::Patrons->search({ some filters here })->delete({ move => 1, verbose => 1 }); Delete passed set of patron objects. Wrapper for Koha::Patron->delete. (We do not want to bypass Koha::Patron @@ -227,11 +227,13 @@ sub delete { my $patrons_deleted; $self->_resultset->result_source->schema->txn_do( sub { my ( $set, $params ) = @_; + my $count = $set->count; while( my $patron = $set->next ) { $patron->move_to_deleted if $params->{move}; $patron->delete == 1 || Koha::Exceptions::Patron::FailedDelete->throw; $patrons_deleted++; } + warn "Deleted $count patrons\n" if $params->{verbose}; }, $self, $params ); return $patrons_deleted; } @@ -328,34 +330,44 @@ sub search_anonymized { =head3 lock - Koha::Patrons->search({ some filters })->lock({ expire => 1, remove => 1 }) + Koha::Patrons->search({ some filters })->lock({ expire => 1, remove => 1, verbose => 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 sub lock { my ( $self, $params ) = @_; + my $count = $self->count; while( my $patron = $self->next ) { $patron->lock($params); } + if( $params->{verbose} ) { + warn "Locked $count patrons\n"; + } } =head3 anonymize - Koha::Patrons->search({ some filters })->anonymize; + Koha::Patrons->search({ some filters })->anonymize({ verbose => 1 }); Anonymize passed set of patron objects. + Optional verbose flag is used in cron job. Wrapper around Koha::Patron->anonymize. =cut sub anonymize { - my ( $self ) = @_; + my ( $self, $params ) = @_; + 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 3e6c504532..50fe525101 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -304,6 +304,14 @@ if($allDebarments) { print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose; } +# Handle unsubscribe requests from GDPR consent form, depends on UnsubscribeReflectionDelay preference +Koha::Patrons->search_unsubscribed->lock({ expire => 1, remove => 1, verbose => $verbose }); +# Anonymize patron data, depending on PatronAnonymizeDelay +Koha::Patrons->search_anonymize_candidates({ locked => 1 })->anonymize({ verbose => $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 $@; + if( $pExpSelfReg ) { DeleteExpiredSelfRegs(); } -- 2.11.0