From 945d6820f9a65fab046337e5bd9a0ab009441176 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 3 Jan 2022 15:08:27 -0300 Subject: [PATCH] Bug 29525: Make batch_anonymise.pl deal with holds This patch makes the batch_anonymise.pl script handle holds too. It does so by leveraging on the newly introduced method 'filter_by_anonymizable' and also 'anonymize'. To test: 1. Have a patron with two past holds. 2. Make sure they are a few days back: $ koha-mysql kohadev > UPDATE old_reserves SET timestamp=ADDDATE(NOW(), INTERVAL -4 DAY); 3. Run: $ kshell k$ perl misc/cronjobs/batch_anonymise.pl --days 2 -v => SUCCESS: You see something like: Checkouts and holds before 2022-01-01 will be anonymised. 0 checkouts anonymised. 2 holds anonymised. 4. Repeat 3 => SUCCESS: They are already anonymized. You see Checkouts and holds before 2022-01-01 will be anonymised. 0 checkouts anonymised. 0 holds anonymised. 5. Sign off :-D --- misc/cronjobs/batch_anonymise.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/batch_anonymise.pl b/misc/cronjobs/batch_anonymise.pl index edea4fa7ed..78a4e1ad0c 100755 --- a/misc/cronjobs/batch_anonymise.pl +++ b/misc/cronjobs/batch_anonymise.pl @@ -22,6 +22,7 @@ use warnings; use Koha::Script -cron; use C4::Context; +use Koha::DateUtils qw(dt_from_string); use Koha::Patrons; use Date::Calc qw( Add_Delta_Days Today ); use Getopt::Long qw( GetOptions ); @@ -61,9 +62,12 @@ cronlogaction(); my ($year,$month,$day) = Today(); my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days); my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday; -$verbose and print "Checkouts before $formatdate will be anonymised.\n"; +$verbose and print "Checkouts and holds before $formatdate will be anonymised.\n"; my $rows = Koha::Patrons->search_patrons_to_anonymise( { before => $formatdate } )->anonymise_issue_history( { before => $formatdate } ); $verbose and print int($rows) . " checkouts anonymised.\n"; +$rows = Koha::Old::Holds->filter_by_anonymizable({ before => dt_from_string()->subtract( days => $days ) })->anonymize; +$verbose and print int($rows) . " holds anonymised.\n"; + exit(0); -- 2.32.0