Line 0
Link Here
|
|
|
1 |
package Koha::Anonymized::Patron; |
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
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 |
8 |
# version. |
9 |
# |
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. |
13 |
# |
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. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Carp; |
21 |
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); |
22 |
|
23 |
use Koha::Database; |
24 |
|
25 |
use base qw(Koha::Object); |
26 |
|
27 |
=head1 NAME |
28 |
|
29 |
Koha::Anonymized::Patron - Koha Anonymized::Patron Object class |
30 |
|
31 |
=head1 API |
32 |
|
33 |
=head2 Class methods |
34 |
|
35 |
=head3 new |
36 |
|
37 |
=cut |
38 |
|
39 |
sub get_hash { |
40 |
my ( $class, $borrowernumber) = @_; |
41 |
return bcrypt($borrowernumber, C4::Context->config('key')); |
42 |
} |
43 |
|
44 |
|
45 |
sub new_from_patron { |
46 |
my ( $class, $patron ) = @_; |
47 |
|
48 |
my $self = $class->SUPER::new({ |
49 |
hashed_borrowernumber => $class->get_hash($patron->borrowernumber), |
50 |
}); |
51 |
|
52 |
$self->update_from_patron($patron); |
53 |
return $self; |
54 |
} |
55 |
|
56 |
sub update_from_patron { |
57 |
my ( $self, $patron ) = @_; |
58 |
|
59 |
my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || ''; |
60 |
my $values = |
61 |
{ map { $_ => $patron->$_ } @fields_to_copy }; |
62 |
|
63 |
$values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?) |
64 |
$values->{categorycode} = $patron->categorycode; |
65 |
|
66 |
$values->{has_cardnumber} = $patron->cardnumber ? 1 : 0; |
67 |
|
68 |
$self->set($values); |
69 |
return $self; |
70 |
} |
71 |
|
72 |
=head2 Internal methods |
73 |
|
74 |
=head3 _type |
75 |
|
76 |
=cut |
77 |
|
78 |
sub _type { |
79 |
return 'AnonymizedBorrower'; |
80 |
} |
81 |
|
82 |
1; |