View | Details | Raw Unified | Return to bug 34611
Collapse All | Expand All

(-)a/misc/maintenance/pseudonymize_statistics.pl (-1 / +105 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
use Getopt::Long qw( GetOptions );
20
use Pod::Usage qw( pod2usage );
21
22
use Koha::DateUtils qw( dt_from_string format_sqldatetime );
23
use Koha::Script;
24
use Koha::Statistics;
25
26
use C4::Context;
27
28
my ( $help, $verbose, $before );
29
my $result = GetOptions(
30
    'h|help'          => \$help,
31
    'v|verbose'       => \$verbose,
32
    'b|before:s'       => \$before,
33
) || pod2usage(1);
34
35
if ($help) {
36
    pod2usage(0);
37
}
38
39
unless( C4::Context->preference('Pseudonymization') ){
40
    die "The system preference for Pseudonymization is not enabled, no action will be taken";
41
}
42
43
$before //= format_sqldatetime(dt_from_string(),'sql',undef,1 );
44
45
my $statistics = Koha::Statistics->search({ datetime => { '<=' => $before } });
46
47
while ( my $statistic = $statistics->next ){
48
    $statistic->pseudonymize();
49
}
50
51
=head1 NAME
52
53
pseudonymize_statistics - This script pseudonymizes statistics before a given date, or now if no date passed.
54
55
NOTE: If patrons or items have been deleted their fields cannot be saved, additionally the fields will use current
56
values as the ones from when the transaction occurred are not available.
57
58
=head1 SYNOPSIS
59
60
pseudonymize_statistics.pl [-h|--help] [-v|--verbose] [-b|--before=DATE]
61
62
=head1 OPTIONS
63
64
=over
65
66
=item B<-h|--help>
67
68
Print a brief help message
69
70
=item B<-v|--verbose>
71
72
Verbose mode.
73
74
=item B<-b|--before=DATE>
75
76
This option allows for specifiying a date to pseudonmyize before. Useful if you have enabled pseudonymization and want to pseudonymize transactions before that date. If not passed all statistics before current time will be pseudonymized.
77
78
=back
79
80
=head1 AUTHOR
81
82
Nick Clemens <nick@bywatersolutions.com>
83
84
=head1 COPYRIGHT
85
86
Copyright 2023 ByWater Solutions
87
88
=head1 LICENSE
89
90
This file is part of Koha.
91
92
# Koha is free software; you can redistribute it and/or modify it
93
# under the terms of the GNU General Public License as published by
94
# the Free Software Foundation; either version 3 of the License, or
95
# (at your option) any later version.
96
#
97
# Koha is distributed in the hope that it will be useful, but
98
# WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
100
# GNU General Public License for more details.
101
#
102
# You should have received a copy of the GNU General Public License
103
# along with Koha; if not, see <http://www.gnu.org/licenses>.
104
105
=cut

Return to bug 34611