From 91468333ccbb9e3637b1fe5a633045aa6bd00cd4 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 Content-Type: text/plain; charset=utf-8 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 --- Koha/Patrons.pm | 16 +++++++++++++--- misc/cronjobs/cleanup_database.pl | 13 +++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index ba5e246..eb43176 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -332,34 +332,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 3e6c504..a7bc28a 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -304,6 +304,19 @@ 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 +{ + my $rs = Koha::Patrons->search_anonymized; + my $count = $rs->count; + my $rv = $rs->delete; + print "Removed $count anonymized patrons\n" if $verbose && $rv==1; + warn "Problem with removing anonymized patrons\n" if $rv<1 && $count; +} + if( $pExpSelfReg ) { DeleteExpiredSelfRegs(); } -- 2.1.4