From 5ce074b72bada9b9100753147b3f983bb5b66555 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 26 Nov 2019 20:21:21 +0100 Subject: [PATCH] Bug 24151: Move get_hash to Koha::Anonymized To avoid duplicated code. Sponsored-by: Association KohaLa - https://koha-fr.org/ --- 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 diff --git a/Koha/Anonymized.pm b/Koha/Anonymized.pm new file mode 100644 index 0000000000..fbf5ab2182 --- /dev/null +++ b/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; diff --git a/Koha/Anonymized/Patron.pm b/Koha/Anonymized/Patron.pm index 1cd5ba9c2c..0d2fc38c19 100644 --- a/Koha/Anonymized/Patron.pm +++ b/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); diff --git a/Koha/Anonymized/Transaction.pm b/Koha/Anonymized/Transaction.pm index e536674629..e57712c936 100644 --- a/Koha/Anonymized/Transaction.pm +++ b/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') || ''; -- 2.11.0