From 5854e5de7f0082b94c85006c267a72cade2c5687 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 17 Apr 2019 15:03:25 -0300 Subject: [PATCH] Bug 22729: Adapt Koha::Patron(s) and tests This patch adapts the Koha::Patron(s) code to the column change. To test: - Apply this patches - Run: $ kshell k$ prove t/db_dependent/Koha/Patrons.t => SUCCESS: Tests pass! - Sign off :-D Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/Patron.pm | 4 ++-- Koha/Patrons.pm | 4 ++-- t/db_dependent/Koha/Patrons.t | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index c3326285b9..6a25d717c1 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1362,12 +1362,12 @@ sub anonymize { 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; - @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|flgAnonymized/ } @columns; + @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|anonymized/ } @columns; push @columns, 'dateofbirth'; # add this date back in foreach my $col (@columns) { $self->_anonymize_column($col, $mandatory->{lc $col} ); } - $self->flgAnonymized(1)->store; + $self->anonymized(1)->store; } sub _anonymize_column { diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index b35e6cc4a8..7510093185 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -293,7 +293,7 @@ sub search_anonymize_candidates { my $dt = dt_from_string()->subtract( days => $delay ); my $str = $parser->format_datetime($dt); $cond->{dateexpiry} = { '<=' => $str }; - $cond->{flgAnonymized} = [ undef, 0 ]; # not yet done + $cond->{anonymized} = 0; # not yet done if( $params->{locked} ) { my $fails = C4::Context->preference('FailedLoginAttempts'); $cond->{login_attempts} = [ -and => { '!=' => undef }, { -not_in => [0, 1..$fails-1 ] } ]; # -not_in does not like undef @@ -324,7 +324,7 @@ sub search_anonymized { my $dt = dt_from_string()->subtract( days => $delay ); my $str = $parser->format_datetime($dt); $cond->{dateexpiry} = { '<=' => $str }; - $cond->{flgAnonymized} = 1; + $cond->{anonymized} = 1; return $class->search( $cond ); } diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index b248729de0..7e4a535f9e 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1663,9 +1663,9 @@ subtest 'search_anonymize_candidates' => sub { plan tests => 5; my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); - $patron1->flgAnonymized(0); + $patron1->anonymized(0); $patron1->dateexpiry( dt_from_string->add(days => 1) )->store; - $patron2->flgAnonymized(undef); + $patron2->anonymized(0); $patron2->dateexpiry( dt_from_string->add(days => 1) )->store; t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', q{} ); @@ -1713,9 +1713,9 @@ subtest 'search_anonymized' => sub { t::lib::Mocks::mock_preference( 'PatronRemovalDelay', 1 ); $patron1->dateexpiry( dt_from_string ); - $patron1->flgAnonymized(0)->store; + $patron1->anonymized(0)->store; my $cnt = Koha::Patrons->search_anonymized->count; - $patron1->flgAnonymized(1)->store; + $patron1->anonymized(1)->store; is( Koha::Patrons->search_anonymized->count, $cnt, 'Number unchanged' ); $patron1->dateexpiry( dt_from_string->subtract(days => 1) )->store; is( Koha::Patrons->search_anonymized->count, $cnt+1, 'Found patron1' ); @@ -1775,7 +1775,7 @@ subtest 'anonymize' => sub { my $surname = $patron1->surname; # expect change, no clear my $branchcode = $patron1->branchcode; # expect skip $patron1->anonymize; - is($patron1->flgAnonymized, 1, 'Check flag' ); + is($patron1->anonymized, 1, 'Check flag' ); is( $patron1->dateofbirth, undef, 'Birth date cleared' ); is( $patron1->firstname, undef, 'First name cleared' ); -- 2.39.5