Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2011, ByWater Solutions. |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
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. |
11 |
# |
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. |
15 |
# |
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. |
19 |
|
20 |
use strict; |
21 |
use warnings; |
22 |
|
23 |
BEGIN { |
24 |
|
25 |
# find Koha's Perl modules |
26 |
# test carefully before changing this |
27 |
use FindBin; |
28 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
29 |
} |
30 |
|
31 |
use C4::Context; |
32 |
use C4::Circulation; |
33 |
use C4::Dates; |
34 |
use Date::Calc qw( |
35 |
Today |
36 |
Add_Delta_Days |
37 |
); |
38 |
use Getopt::Long; |
39 |
|
40 |
sub usage { |
41 |
print STDERR <<USAGE; |
42 |
Usage: $0 --days DAYS [-h|--help] |
43 |
--days DAYS (MANDATORY) anonymise patron history that is older than DAYS days. |
44 |
-v --verbose gives a little more information |
45 |
-h --help prints this help message, and exits, ignoring all |
46 |
other options |
47 |
USAGE |
48 |
exit $_[0]; |
49 |
} |
50 |
|
51 |
my ( $help, $days, $verbose ); |
52 |
|
53 |
GetOptions( |
54 |
'h|help' => \$help, |
55 |
'days:i' => \$days, |
56 |
'v|verbose' => \$verbose, |
57 |
) || usage(1); |
58 |
|
59 |
if ($help) { |
60 |
usage(0); |
61 |
} |
62 |
|
63 |
if ( !$days ) { |
64 |
print "The days parameter is mandatory.\n\n"; |
65 |
usage(1); |
66 |
} |
67 |
|
68 |
my ($year,$month,$day) = Today(); |
69 |
my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days); |
70 |
my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday; |
71 |
$verbose and print "Checkouts before $formatdate will be anonymised.\n"; |
72 |
|
73 |
my $rows = AnonymiseIssueHistory($formatdate); |
74 |
$verbose and print "$rows checkouts anonymised.\n"; |
75 |
|
76 |
exit(0); |