From 2330a155f6d13c37a81632c3088030c89a877401 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 10 Oct 2018 15:34:22 +0200 Subject: [PATCH] Bug 21535: Anonymize function in Patron should not scramble email addresses Scrambled email addresses will only generate warnings etc. Clear them although they might be in BorrowerMandatoryField. Test plan: Run t/db_dependent/Koha/Patrons.t Signed-off-by: Marcel de Rooy Signed-off-by: Owen Leonard t/db_depepended/Koha/Patrons.t runs with no warnings. Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/Patron.pm | 4 +++- t/db_dependent/Koha/Patrons.t | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 6a25d717c1..04b54a3ed6 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1358,7 +1358,9 @@ sub anonymize { warn "Exiting anonymize: patron ".$self->borrowernumber." still has issues"; return; } - my $mandatory = { map { (lc $_, 1); } + # Mandatory fields come from the corresponding pref, but email fields + # are removed since scrambled email addresses only generate errors + my $mandatory = { map { (lc $_, 1); } grep { !/email/ } split /\s*\|\s*/, C4::Context->preference('BorrowerMandatoryField') }; $mandatory->{userid} = 1; # needed since sub store does not clear field my @columns = $self->_result->result_source->columns; diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 7e4a535f9e..c9dd9c9306 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1761,7 +1761,7 @@ subtest 'lock' => sub { }; subtest 'anonymize' => sub { - plan tests => 9; + plan tests => 10; my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } ); my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -1782,6 +1782,7 @@ subtest 'anonymize' => sub { isnt( $patron1->surname, $surname, 'Surname changed' ); ok( $patron1->surname =~ /^\w{10}$/, 'Mandatory surname randomized' ); is( $patron1->branchcode, $branchcode, 'Branch code skipped' ); + is( $patron1->email, undef, 'Email was mandatory, must be cleared' ); # Test wrapper in Koha::Patrons $patron1->surname($surname)->store; # restore -- 2.39.5