Bugzilla – Attachment 95963 Details for
Bug 24151
Add a pseudonymization process for patrons and transactions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24151: Pseudonymize transactions on the fly
Bug-24151-Pseudonymize-transactions-on-the-fly.patch (text/plain), 6.57 KB, created by
Jonathan Druart
on 2019-12-03 18:11:20 UTC
(
hide
)
Description:
Bug 24151: Pseudonymize transactions on the fly
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-12-03 18:11:20 UTC
Size:
6.57 KB
patch
obsolete
>From 9d18ebf1dded145da46b26a40813b1f24ab3372c Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 26 Nov 2019 19:45:13 +0100 >Subject: [PATCH] Bug 24151: Pseudonymize transactions on the fly > >Sponsored-by: Association KohaLa - https://koha-fr.org/ >--- > C4/Stats.pm | 39 ++++++++++------- > Koha/Anonymized/Transaction.pm | 92 +++++++++++++++++++++++++++++++++++++++++ > Koha/Anonymized/Transactions.pm | 53 ++++++++++++++++++++++++ > 3 files changed, 168 insertions(+), 16 deletions(-) > create mode 100644 Koha/Anonymized/Transaction.pm > create mode 100644 Koha/Anonymized/Transactions.pm > >diff --git a/C4/Stats.pm b/C4/Stats.pm >index 8a8835c346..c7552d6553 100644 >--- a/C4/Stats.pm >+++ b/C4/Stats.pm >@@ -18,12 +18,15 @@ package C4::Stats; > # You should have received a copy of the GNU General Public License > # along with Koha; if not, see <http://www.gnu.org/licenses>. > >-use strict; >-use warnings; >+use Modern::Perl; > require Exporter; > use Carp; > use C4::Context; > use C4::Debug; >+ >+use Koha::DateUtils qw( dt_from_string ); >+use Koha::Statistics; >+use Koha::Anonymized::Transactions; > use vars qw(@ISA @EXPORT); > > our $debug; >@@ -124,20 +127,24 @@ sub UpdateStats { > my $location = exists $params->{location} ? $params->{location} : undef; > my $ccode = exists $params->{ccode} ? $params->{ccode} : ''; > >- my $dbh = C4::Context->dbh; >- my $sth = $dbh->prepare( >- "INSERT INTO statistics >- (datetime, >- branch, type, value, >- other, itemnumber, itemtype, location, >- borrowernumber, ccode) >- VALUES (now(),?,?,?,?,?,?,?,?,?)" >- ); >- $sth->execute( >- $branch, $type, $amount, $other, >- $itemnumber, $itemtype, $location, $borrowernumber, >- $ccode >- ); >+ my $statistic = Koha::Statistic->new( >+ { >+ datetime => dt_from_string, >+ branch => $branch, >+ type => $type, >+ value => $amount, >+ other => $other, >+ itemnumber => $itemnumber, >+ itemtype => $itemtype, >+ location => $location, >+ borrowernumber => $borrowernumber, >+ ccode => $ccode, >+ } >+ )->store; >+ >+ Koha::Anonymized::Transaction->new_from_statistic($statistic)->store >+ if C4::Context->preference('Pseudonymization') >+ && grep { $_ eq $params->{type} } qw(renew issue return onsite_checkout); > } > > 1; >diff --git a/Koha/Anonymized/Transaction.pm b/Koha/Anonymized/Transaction.pm >new file mode 100644 >index 0000000000..e536674629 >--- /dev/null >+++ b/Koha/Anonymized/Transaction.pm >@@ -0,0 +1,92 @@ >+package Koha::Anonymized::Transaction; >+ >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Carp; >+use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); >+ >+use Koha::Database; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::Anonymized::Transaction - Koha Anonymized::Transaction Object class >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 new >+ >+=cut >+ >+sub get_hash { >+ my ( $class, $borrowernumber) = @_; >+ return bcrypt($borrowernumber, C4::Context->config('key')); >+} >+ >+ >+sub new_from_statistic { >+ my ( $class, $statistic ) = @_; >+ >+ my $values = { >+ hashed_borrowernumber => $class->get_hash($statistic->borrowernumber), >+ }; >+ >+ my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || ''; >+ >+ if ( grep { $_ eq 'branchcode' } @fields_to_copy ) { >+ $values->{branchcode} = $statistic->branch; >+ } >+ if ( grep { $_ eq 'holdingbranch' } @fields_to_copy ) { >+ $values->{holdingbranch} = $statistic->item->holdingbranch; >+ } >+ if ( grep { $_ eq 'transaction_type' } @fields_to_copy ) { >+ $values->{transaction_type} = $statistic->type; >+ } >+ if ( grep { $_ eq 'itemcallnumber' } @fields_to_copy ) { >+ $values->{itemcallnumber} = $statistic->item->itemcallnumber; >+ } >+ >+ >+ @fields_to_copy = grep { >+ $_ ne 'branchcode' >+ && $_ ne 'holdingbranch' >+ && $_ ne 'transaction_type' >+ && $_ ne 'itemcallnumber' >+ } @fields_to_copy; >+ >+ $values = { >+ %$values, >+ map { $_ => $statistic->$_ } @fields_to_copy}; >+ >+ return $class->SUPER::new($values); >+} >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'AnonymizedTransaction'; >+} >+ >+1; >diff --git a/Koha/Anonymized/Transactions.pm b/Koha/Anonymized/Transactions.pm >new file mode 100644 >index 0000000000..27cd4fb5fc >--- /dev/null >+++ b/Koha/Anonymized/Transactions.pm >@@ -0,0 +1,53 @@ >+package Koha::Anonymized::Transactions; >+ >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Carp; >+use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); >+ >+use Koha::Database; >+ >+use Koha::Anonymized::Transaction; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::Anonymized::Transactions - Koha Anonymized Transaction Object set class >+ >+=head1 API >+ >+=cut >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'AnonymizedTransaction'; >+} >+ >+sub object_class { >+ return 'Koha::Anonymized::Transaction'; >+} >+ >+1; >-- >2.11.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 24151
:
95959
|
95960
|
95961
|
95962
|
95963
|
95964
|
95965
|
95966
|
95967
|
95968
|
95969
|
95970
|
95971
|
95972
|
95973
|
95974
|
95975
|
95976
|
97240
|
97241
|
97242
|
97243
|
97244
|
97245
|
97246
|
97247
|
97248
|
97249
|
97250
|
97251
|
97252
|
101034
|
101035
|
101036
|
101037
|
101038
|
101039
|
101040
|
101041
|
101042
|
101043
|
101044
|
101045
|
101046
|
101047
|
101048
|
101049
|
105801
|
105802
|
105803
|
105804
|
105805
|
105806
|
105807
|
105808
|
105809
|
105810
|
105811
|
105812
|
105813
|
105814
|
105815
|
105816
|
106032
|
106033
|
106034
|
106035
|
106036
|
106037
|
106038
|
106039
|
106040
|
106041
|
106042
|
106043
|
106044
|
106045
|
106046
|
106047
|
106048
|
106049
|
106195
|
106255
|
107127
|
107225