Bug 13891: DataTables server-side processing - Serial recipients
[koha.git] / misc / cronjobs / batch_anonymise.pl
blob48a58c61ca848ba0c6b4978aff1344128a55b3dd
1 #!/usr/bin/perl
3 # Copyright 2011, ByWater Solutions.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
22 use Carp;
24 BEGIN {
26 # find Koha's Perl modules
27 # test carefully before changing this
28 use FindBin;
29 eval { require "$FindBin::Bin/../kohalib.pl" };
32 use C4::Context;
33 use C4::Circulation;
34 use C4::Dates;
35 use Date::Calc qw(
36 Today
37 Add_Delta_Days
39 use Getopt::Long;
41 sub usage {
42 print STDERR <<USAGE;
43 Usage: $0 --days DAYS [-h|--help]
44 --days DAYS (MANDATORY) anonymise patron history that is older than DAYS days.
45 -v --verbose gives a little more information
46 -h --help prints this help message, and exits, ignoring all
47 other options
48 USAGE
49 exit $_[0];
52 my ( $help, $days, $verbose );
54 GetOptions(
55 'h|help' => \$help,
56 'days:i' => \$days,
57 'v|verbose' => \$verbose,
58 ) || usage(1);
60 if ($help) {
61 usage(0);
64 if ( !$days ) {
65 print "The days parameter is mandatory.\n\n";
66 usage(1);
69 my ($year,$month,$day) = Today();
70 my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days);
71 my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday;
72 $verbose and print "Checkouts before $formatdate will be anonymised.\n";
74 my ($rows, $err_history_not_deleted) = AnonymiseIssueHistory($formatdate);
75 carp "Anonymisation of reading history failed." if ($err_history_not_deleted);
76 $verbose and print "$rows checkouts anonymised.\n";
78 exit(0);