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

(-)a/Koha/Patron.pm (-12 / +14 lines)
Lines 1364-1389 sub anonymize { Link Here
1364
    @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|flgAnonymized/ } @columns;
1364
    @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|flgAnonymized/ } @columns;
1365
    push @columns, 'dateofbirth'; # add this date back in
1365
    push @columns, 'dateofbirth'; # add this date back in
1366
    foreach my $col (@columns) {
1366
    foreach my $col (@columns) {
1367
        if( $mandatory->{lc $col} ) {
1367
        $self->_anonymize_column($col, $mandatory->{lc $col} );
1368
            my $str = $self->_anonymize_column($col);
1369
            $self->$col($str);
1370
        } else {
1371
            $self->$col(undef);
1372
        }
1373
    }
1368
    }
1374
    $self->flgAnonymized(1)->store;
1369
    $self->flgAnonymized(1)->store;
1375
}
1370
}
1376
1371
1377
sub _anonymize_column {
1372
sub _anonymize_column {
1378
    my ( $self, $col ) = @_;
1373
    my ( $self, $col, $mandatory ) = @_;
1379
    my $type = $self->_result->result_source->column_info($col)->{data_type};
1374
    my $col_info = $self->_result->result_source->column_info($col);
1375
    my $type = $col_info->{data_type};
1376
    my $nullable = $col_info->{is_nullable};
1377
    my $val;
1380
    if( $type =~ /char|text/ ) {
1378
    if( $type =~ /char|text/ ) {
1381
        return Koha::Token->new->generate({ pattern => '\w{10}' });
1379
        $val = $mandatory
1380
            ? Koha::Token->new->generate({ pattern => '\w{10}' })
1381
            : $nullable
1382
            ? undef
1383
            : q{};
1382
    } elsif( $type =~ /integer|int$|float|dec|double/ ) {
1384
    } elsif( $type =~ /integer|int$|float|dec|double/ ) {
1383
        return 0;
1385
        $val = $nullable ? undef : 0;
1384
    } elsif( $type =~ /date|time/ ) {
1386
    } elsif( $type =~ /date|time/ ) {
1385
        return dt_from_string;
1387
        $val = $nullable ? undef : dt_from_string;
1386
    }
1388
    }
1389
    $self->$col($val);
1387
}
1390
}
1388
1391
1389
=head2 Internal methods
1392
=head2 Internal methods
1390
- 

Return to bug 21336