3 # This file is part of Koha.
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.
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.
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>.
19 use Getopt::Long qw( GetOptions );
20 use Pod::Usage qw( pod2usage );
22 use Koha::DateUtils qw( dt_from_string format_sqldatetime );
25 use Koha::PseudonymizedTransactions;
29 my ( $help, $verbose, $before );
30 my $result = GetOptions(
32 'v|verbose' => \$verbose,
33 'b|before:s' => \$before,
40 unless ( C4::Context->preference('Pseudonymization') ) {
41 die "The system preference for Pseudonymization is not enabled, no action will be taken";
44 $before //= format_sqldatetime( dt_from_string(), 'sql', undef, 1 );
45 print "Searching for statistics before $before\n" if $verbose;
47 my $statistics = Koha::Statistics->search( { datetime => { '<=' => $before } } );
48 print $statistics->count() . " statistics found\n" if $verbose;
51 my $existing_pseudo_stats = Koha::PseudonymizedTransactions->search( { datetime => { '<=' => $before } } )->count;
53 if ( $statistics->count && $existing_pseudo_stats ) {
55 . $statistics->count()
56 . " statistics found, and $existing_pseudo_stats already in the database for the date provided.\n";
57 print "You may have already run this script for the time period given.\n";
58 print "Please enter 'Y' if you would like to continue:";
59 chomp( my $continue = <> );
60 exit unless uc($continue) eq 'Y';
64 while ( my $statistic = $statistics->next ) {
65 $statistic->pseudonymize();
68 print $statistics->count() . " statistics pseudonymized\n" if $verbose;
72 pseudonymize_statistics - This script pseudonymizes statistics before a given date, or now if no date passed.
74 NOTE: If patrons or items have been deleted their fields cannot be saved, additionally the fields will use current
75 values as the ones from when the transaction occurred are not available.
79 pseudonymize_statistics.pl [-h|--help] [-v|--verbose] [-b|--before=DATE]
87 Print a brief help message
93 =item B<-b|--before=DATE>
95 This option allows for specifying 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.
101 Nick Clemens <nick@bywatersolutions.com>
105 Copyright 2023 ByWater Solutions
109 This file is part of Koha.
111 # Koha is free software; you can redistribute it and/or modify it
112 # under the terms of the GNU General Public License as published by
113 # the Free Software Foundation; either version 3 of the License, or
114 # (at your option) any later version.
116 # Koha is distributed in the hope that it will be useful, but
117 # WITHOUT ANY WARRANTY; without even the implied warranty of
118 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
119 # GNU General Public License for more details.
121 # You should have received a copy of the GNU General Public License
122 # along with Koha; if not, see <http://www.gnu.org/licenses>.