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
15 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
23 use Koha::Exceptions::Config;
26 use base qw(Koha::Object);
30 Koha::PseudonymizedTransaction - Koha Koha::PseudonymizedTransaction Object class
40 sub new_from_statistic {
41 my ( $class, $statistic ) = @_;
44 hashed_borrowernumber => $class->get_hash($statistic->borrowernumber),
47 my @t_fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || '';
49 if ( grep { $_ eq 'transaction_branchcode' } @t_fields_to_copy ) {
50 $values->{transaction_branchcode} = $statistic->branch;
52 if ( grep { $_ eq 'holdingbranch' } @t_fields_to_copy ) {
53 $values->{holdingbranch} = $statistic->item->holdingbranch;
55 if ( grep { $_ eq 'homebranch' } @t_fields_to_copy ) {
56 $values->{homebranch} = $statistic->item->homebranch;
58 if ( grep { $_ eq 'transaction_type' } @t_fields_to_copy ) {
59 $values->{transaction_type} = $statistic->type;
61 if ( grep { $_ eq 'itemcallnumber' } @t_fields_to_copy ) {
62 $values->{itemcallnumber} = $statistic->item->itemcallnumber;
66 @t_fields_to_copy = grep {
67 $_ ne 'transaction_branchcode'
68 && $_ ne 'holdingbranch'
70 && $_ ne 'transaction_type'
71 && $_ ne 'itemcallnumber'
74 $values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy };
76 my $patron = Koha::Patrons->find($statistic->borrowernumber);
77 my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || '';
78 $values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy };
80 $values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?)
81 $values->{categorycode} = $patron->categorycode;
83 $values->{has_cardnumber} = $patron->cardnumber ? 1 : 0;
85 my $self = $class->SUPER::new($values);
87 my $extended_attributes = $patron->extended_attributes->unblessed;
88 for my $attribute (@$extended_attributes) {
89 next unless Koha::Patron::Attribute::Types->find(
90 $attribute->{code} )->keep_for_pseudonymization;
92 delete $attribute->{id};
93 delete $attribute->{borrowernumber};
95 $self->_result->create_related('pseudonymized_borrower_attributes', $attribute);
102 my ( $class, $s ) = @_;
103 my $key = C4::Context->config('key');
105 Koha::Exceptions::Config::MissingEntry->throw(
106 "Missing 'key' entry in config file") unless $key;
108 return bcrypt($s, $key);
111 =head2 Internal methods
118 return 'PseudonymizedTransaction';