View | Details | Raw Unified | Return to bug 22729
Collapse All | Expand All

(-)a/Koha/Patron.pm (-2 / +2 lines)
Lines 1362-1373 sub anonymize { Link Here
1362
        split /\s*\|\s*/, C4::Context->preference('BorrowerMandatoryField') };
1362
        split /\s*\|\s*/, C4::Context->preference('BorrowerMandatoryField') };
1363
    $mandatory->{userid} = 1; # needed since sub store does not clear field
1363
    $mandatory->{userid} = 1; # needed since sub store does not clear field
1364
    my @columns = $self->_result->result_source->columns;
1364
    my @columns = $self->_result->result_source->columns;
1365
    @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|flgAnonymized/ } @columns;
1365
    @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|anonymized/ } @columns;
1366
    push @columns, 'dateofbirth'; # add this date back in
1366
    push @columns, 'dateofbirth'; # add this date back in
1367
    foreach my $col (@columns) {
1367
    foreach my $col (@columns) {
1368
        $self->_anonymize_column($col, $mandatory->{lc $col} );
1368
        $self->_anonymize_column($col, $mandatory->{lc $col} );
1369
    }
1369
    }
1370
    $self->flgAnonymized(1)->store;
1370
    $self->anonymized(1)->store;
1371
}
1371
}
1372
1372
1373
sub _anonymize_column {
1373
sub _anonymize_column {
(-)a/Koha/Patrons.pm (-2 / +2 lines)
Lines 293-299 sub search_anonymize_candidates { Link Here
293
    my $dt = dt_from_string()->subtract( days => $delay );
293
    my $dt = dt_from_string()->subtract( days => $delay );
294
    my $str = $parser->format_datetime($dt);
294
    my $str = $parser->format_datetime($dt);
295
    $cond->{dateexpiry} = { '<=' => $str };
295
    $cond->{dateexpiry} = { '<=' => $str };
296
    $cond->{flgAnonymized} = [ undef, 0 ]; # not yet done
296
    $cond->{anonymized} = 0; # not yet done
297
    if( $params->{locked} ) {
297
    if( $params->{locked} ) {
298
        my $fails = C4::Context->preference('FailedLoginAttempts');
298
        my $fails = C4::Context->preference('FailedLoginAttempts');
299
        $cond->{login_attempts} = [ -and => { '!=' => undef }, { -not_in => [0, 1..$fails-1 ] } ]; # -not_in does not like undef
299
        $cond->{login_attempts} = [ -and => { '!=' => undef }, { -not_in => [0, 1..$fails-1 ] } ]; # -not_in does not like undef
Lines 324-330 sub search_anonymized { Link Here
324
    my $dt = dt_from_string()->subtract( days => $delay );
324
    my $dt = dt_from_string()->subtract( days => $delay );
325
    my $str = $parser->format_datetime($dt);
325
    my $str = $parser->format_datetime($dt);
326
    $cond->{dateexpiry} = { '<=' => $str };
326
    $cond->{dateexpiry} = { '<=' => $str };
327
    $cond->{flgAnonymized} = 1;
327
    $cond->{anonymized} = 1;
328
    return $class->search( $cond );
328
    return $class->search( $cond );
329
}
329
}
330
330
(-)a/t/db_dependent/Koha/Patrons.t (-6 / +5 lines)
Lines 1663-1671 subtest 'search_anonymize_candidates' => sub { Link Here
1663
    plan tests => 5;
1663
    plan tests => 5;
1664
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
1664
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
1665
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
1665
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
1666
    $patron1->flgAnonymized(0);
1666
    $patron1->anonymized(0);
1667
    $patron1->dateexpiry( dt_from_string->add(days => 1) )->store;
1667
    $patron1->dateexpiry( dt_from_string->add(days => 1) )->store;
1668
    $patron2->flgAnonymized(undef);
1668
    $patron2->anonymized(0);
1669
    $patron2->dateexpiry( dt_from_string->add(days => 1) )->store;
1669
    $patron2->dateexpiry( dt_from_string->add(days => 1) )->store;
1670
1670
1671
    t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', q{} );
1671
    t::lib::Mocks::mock_preference( 'PatronAnonymizeDelay', q{} );
Lines 1713-1721 subtest 'search_anonymized' => sub { Link Here
1713
1713
1714
    t::lib::Mocks::mock_preference( 'PatronRemovalDelay', 1 );
1714
    t::lib::Mocks::mock_preference( 'PatronRemovalDelay', 1 );
1715
    $patron1->dateexpiry( dt_from_string );
1715
    $patron1->dateexpiry( dt_from_string );
1716
    $patron1->flgAnonymized(0)->store;
1716
    $patron1->anonymized(0)->store;
1717
    my $cnt = Koha::Patrons->search_anonymized->count;
1717
    my $cnt = Koha::Patrons->search_anonymized->count;
1718
    $patron1->flgAnonymized(1)->store;
1718
    $patron1->anonymized(1)->store;
1719
    is( Koha::Patrons->search_anonymized->count, $cnt, 'Number unchanged' );
1719
    is( Koha::Patrons->search_anonymized->count, $cnt, 'Number unchanged' );
1720
    $patron1->dateexpiry( dt_from_string->subtract(days => 1) )->store;
1720
    $patron1->dateexpiry( dt_from_string->subtract(days => 1) )->store;
1721
    is( Koha::Patrons->search_anonymized->count, $cnt+1, 'Found patron1' );
1721
    is( Koha::Patrons->search_anonymized->count, $cnt+1, 'Found patron1' );
Lines 1775-1781 subtest 'anonymize' => sub { Link Here
1775
    my $surname = $patron1->surname; # expect change, no clear
1775
    my $surname = $patron1->surname; # expect change, no clear
1776
    my $branchcode = $patron1->branchcode; # expect skip
1776
    my $branchcode = $patron1->branchcode; # expect skip
1777
    $patron1->anonymize;
1777
    $patron1->anonymize;
1778
    is($patron1->flgAnonymized, 1, 'Check flag' );
1778
    is($patron1->anonymized, 1, 'Check flag' );
1779
1779
1780
    is( $patron1->dateofbirth, undef, 'Birth date cleared' );
1780
    is( $patron1->dateofbirth, undef, 'Birth date cleared' );
1781
    is( $patron1->firstname, undef, 'First name cleared' );
1781
    is( $patron1->firstname, undef, 'First name cleared' );
1782
- 

Return to bug 22729