@@ -, +, @@ --- Koha/Anonymized.pm | 35 +++++++++++++++++++++++++++++++++++ Koha/Anonymized/Patron.pm | 10 ++-------- Koha/Anonymized/Transaction.pm | 9 +-------- 3 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 Koha/Anonymized.pm --- a/Koha/Anonymized.pm +++ a/Koha/Anonymized.pm @@ -0,0 +1,35 @@ +package Koha::Anonymized; + +# 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); + +use Koha::Exceptions::Config; + +sub get_hash { + my ( $class, $s ) = @_; + my $key = C4::Context->config('key'); + + Koha::Exceptions::Config::MissingEntry->throw( + "Missing 'key' entry in config file") unless $key; + + return bcrypt($s, $key); +} + +1; --- a/Koha/Anonymized/Patron.pm +++ a/Koha/Anonymized/Patron.pm @@ -18,9 +18,9 @@ package Koha::Anonymized::Patron; use Modern::Perl; use Carp; -use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); use Koha::Database; +use Koha::Anonymized; use base qw(Koha::Object); @@ -36,17 +36,11 @@ Koha::Anonymized::Patron - Koha Anonymized::Patron Object class =cut -sub get_hash { - my ( $class, $borrowernumber) = @_; - return bcrypt($borrowernumber, C4::Context->config('key')); -} - - sub new_from_patron { my ( $class, $patron ) = @_; my $self = $class->SUPER::new({ - hashed_borrowernumber => $class->get_hash($patron->borrowernumber), + hashed_borrowernumber => Koha::Anonymized->get_hash($patron->borrowernumber), }); $self->update_from_patron($patron); --- a/Koha/Anonymized/Transaction.pm +++ a/Koha/Anonymized/Transaction.pm @@ -18,7 +18,6 @@ package Koha::Anonymized::Transaction; use Modern::Perl; use Carp; -use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); use Koha::Database; @@ -36,17 +35,11 @@ Koha::Anonymized::Transaction - Koha Anonymized::Transaction Object class =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), + hashed_borrowernumber => Koha::Anonymized->get_hash($statistic->borrowernumber), }; my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || ''; --