Browse Source

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 <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>
19.05.x
Tomás Cohen Arazi 4 years ago
committed by Nick Clemens
parent
commit
5854e5de7f
  1. 4
      Koha/Patron.pm
  2. 4
      Koha/Patrons.pm
  3. 10
      t/db_dependent/Koha/Patrons.t

4
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 {

4
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 );
}

10
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' );

Loading…
Cancel
Save