1 package Koha::PseudonymizedTransaction;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
24 use Koha::Exceptions::Config;
27 use base qw(Koha::Object);
31 Koha::PseudonymizedTransaction - Koha Koha::PseudonymizedTransaction Object class
41 sub new_from_statistic {
42 my ( $class, $statistic ) = @_;
45 hashed_borrowernumber => $class->get_hash($statistic->borrowernumber),
48 my @t_fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || '';
50 if ( grep { $_ eq 'transaction_branchcode' } @t_fields_to_copy ) {
51 $values->{transaction_branchcode} = $statistic->branch;
53 if ( grep { $_ eq 'holdingbranch' } @t_fields_to_copy ) {
54 $values->{holdingbranch} = $statistic->item->holdingbranch;
56 if ( grep { $_ eq 'homebranch' } @t_fields_to_copy ) {
57 $values->{homebranch} = $statistic->item->homebranch;
59 if ( grep { $_ eq 'transaction_type' } @t_fields_to_copy ) {
60 $values->{transaction_type} = $statistic->type;
62 if ( grep { $_ eq 'itemcallnumber' } @t_fields_to_copy ) {
63 $values->{itemcallnumber} = $statistic->item->itemcallnumber;
67 @t_fields_to_copy = grep {
68 $_ ne 'transaction_branchcode'
69 && $_ ne 'holdingbranch'
71 && $_ ne 'transaction_type'
72 && $_ ne 'itemcallnumber'
75 $values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy };
77 my $patron = Koha::Patrons->find($statistic->borrowernumber);
78 my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || '';
79 $values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy };
81 $values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?)
82 $values->{categorycode} = $patron->categorycode;
84 $values->{has_cardnumber} = $patron->cardnumber ? 1 : 0;
86 my $self = $class->SUPER::new($values);
88 my $extended_attributes = $patron->extended_attributes->unblessed;
89 for my $attribute (@$extended_attributes) {
90 next unless Koha::Patron::Attribute::Types->find(
91 $attribute->{code} )->keep_for_pseudonymization;
93 delete $attribute->{id};
94 delete $attribute->{borrowernumber};
96 $self->_result->create_related('pseudonymized_borrower_attributes', $attribute);
103 my ( $class, $s ) = @_;
104 my $key = C4::Context->config('key');
106 Koha::Exceptions::Config::MissingEntry->throw(
107 "Missing 'key' entry in config file") unless $key;
109 return bcrypt($s, $key);
112 =head2 Internal methods
119 return 'PseudonymizedTransaction';