Bug 22729: Adapt Koha::Patron(s) and tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 17 Apr 2019 18:03:25 +0000 (15:03 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 25 Apr 2019 10:06:44 +0000 (10:06 +0000)
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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Patron.pm
Koha/Patrons.pm
t/db_dependent/Koha/Patrons.t

index c332628..6a25d71 100644 (file)
@@ -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 {
index b35e6cc..7510093 100644 (file)
@@ -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 );
 }
 
index b248729..7e4a535 100644 (file)
@@ -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' );