Bugzilla – Attachment 159911 Details for
Bug 34611
Add a script for pseudonymizing existing data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34611: Add a script to pseudonymize statistics from before a given date
Bug-34611-Add-a-script-to-pseudonymize-statistics-.patch (text/plain), 5.17 KB, created by
Tomás Cohen Arazi (tcohen)
on 2023-12-15 20:31:32 UTC
(
hide
)
Description:
Bug 34611: Add a script to pseudonymize statistics from before a given date
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2023-12-15 20:31:32 UTC
Size:
5.17 KB
patch
obsolete
>From ea61b86dcbc946fae2456f886fe5db0039cd7142 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 25 Aug 2023 12:15:31 +0000 >Subject: [PATCH] Bug 34611: Add a script to pseudonymize statistics from > before a given date > >This script takes a date parameter in SQL format and pseudonymizes all statistics >found before this date. > >Only values that can be found will be added, i.e. no deleted patron or item info >will be present. > >Additionally - the values stored will be the current values from patrons and items, so >some info will be approximate, much as it is when joining from the statistics table for reporting. > >To test: > 1 - Perform some issues/returns/renewals/on-site checkouts > 2 - Make sure Pseudonymization is disabled > 3 - perl misc/maintenance/pseudonymize_statistics.pl > 4 - Script ends and reports that preference is not active > 5 - Enable the pref, and choose some borrower and item fields > NOTE: See bug 28911 if you need a bcrypt key for your koha-conf.xml > 6 - perl misc/maintenance/pseudonymize_statistics.pl > 7 - sudo koha-mysql kohadev > 8 - SELECT * FROM pseudonymized_transactions > 9 - Confirm data is correctly stored >10 - DELETE FROM pseudonymized_transactions; >11 - UPDATE statistics SET datetime = '2023-01-01 00:00:00'; >12 - perl misc/maintenance/pseudonymize_statistics.pl -b "2022-12-31 23:59:59"; >13 - SELECT * FROM pseudonymized_transactions; >14 - Confirm no entries were made >15 - Select different options in Pseudonmyization prefs, including borrower attributes > This wil require defining an attribute that can be kept for pseudonymization >16 - Confirm options are correctly pseudonymized > >Signed-off-by: AFHDubCoLib <andrewfh@dubcolib.org> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > misc/maintenance/pseudonymize_statistics.pl | 105 ++++++++++++++++++++ > 1 file changed, 105 insertions(+) > create mode 100755 misc/maintenance/pseudonymize_statistics.pl > >diff --git a/misc/maintenance/pseudonymize_statistics.pl b/misc/maintenance/pseudonymize_statistics.pl >new file mode 100755 >index 00000000000..6b08a841528 >--- /dev/null >+++ b/misc/maintenance/pseudonymize_statistics.pl >@@ -0,0 +1,105 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Getopt::Long qw( GetOptions ); >+use Pod::Usage qw( pod2usage ); >+ >+use Koha::DateUtils qw( dt_from_string format_sqldatetime ); >+use Koha::Script; >+use Koha::Statistics; >+ >+use C4::Context; >+ >+my ( $help, $verbose, $before ); >+my $result = GetOptions( >+ 'h|help' => \$help, >+ 'v|verbose' => \$verbose, >+ 'b|before:s' => \$before, >+) || pod2usage(1); >+ >+if ($help) { >+ pod2usage(0); >+} >+ >+unless ( C4::Context->preference('Pseudonymization') ) { >+ die "The system preference for Pseudonymization is not enabled, no action will be taken"; >+} >+ >+$before //= format_sqldatetime( dt_from_string(), 'sql', undef, 1 ); >+ >+my $statistics = Koha::Statistics->search( { datetime => { '<=' => $before } } ); >+ >+while ( my $statistic = $statistics->next ) { >+ $statistic->pseudonymize(); >+} >+ >+=head1 NAME >+ >+pseudonymize_statistics - This script pseudonymizes statistics before a given date, or now if no date passed. >+ >+NOTE: If patrons or items have been deleted their fields cannot be saved, additionally the fields will use current >+values as the ones from when the transaction occurred are not available. >+ >+=head1 SYNOPSIS >+ >+pseudonymize_statistics.pl [-h|--help] [-v|--verbose] [-b|--before=DATE] >+ >+=head1 OPTIONS >+ >+=over >+ >+=item B<-h|--help> >+ >+Print a brief help message >+ >+=item B<-v|--verbose> >+ >+Verbose mode. >+ >+=item B<-b|--before=DATE> >+ >+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. >+ >+=back >+ >+=head1 AUTHOR >+ >+Nick Clemens <nick@bywatersolutions.com> >+ >+=head1 COPYRIGHT >+ >+Copyright 2023 ByWater Solutions >+ >+=head1 LICENSE >+ >+This file is part of Koha. >+ >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+=cut >-- >2.43.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34611
:
154808
|
154809
|
157753
|
157754
|
157755
|
157763
|
157764
|
157765
|
157869
|
157870
|
157871
|
157872
|
157877
|
157878
|
157879
|
157880
|
159909
|
159910
|
159911
|
159912
|
163344
|
163345
|
163346
|
163347
|
163756
|
163757