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>.
19 use Crypt::Eksblowfish::Bcrypt qw( bcrypt );
22 use Koha::Exceptions::Config;
25 use base qw(Koha::Object);
29 Koha::PseudonymizedTransaction - Koha Koha::PseudonymizedTransaction Object class
35 =head3 new_from_statistic
37 Creates new object from a passed Koha::Statistic object
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);
104 Generates a hashed value for $s (e.g. borrowernumber) with Bcrypt.
105 Needs config entry 'bcrypt_settings' in koha-conf.
110 my ( $class, $s ) = @_;
111 my $bcrypt_settings = C4::Context->config('bcrypt_settings');
113 Koha::Exceptions::Config::MissingEntry->throw(
114 "Missing 'bcrypt_settings' entry in config file") unless $bcrypt_settings;
116 return bcrypt($s, $bcrypt_settings);
119 =head2 Internal methods
126 return 'PseudonymizedTransaction';