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

(-)a/Koha/Patron.pm (-12 / +14 lines)
Lines 1193-1218 sub anonymize { Link Here
1193
    @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|flgAnonymized/ } @columns;
1193
    @columns = grep { !/borrowernumber|branchcode|categorycode|^date|password|flags|updated_on|lastseen|lang|login_attempts|flgAnonymized/ } @columns;
1194
    push @columns, 'dateofbirth'; # add this date back in
1194
    push @columns, 'dateofbirth'; # add this date back in
1195
    foreach my $col (@columns) {
1195
    foreach my $col (@columns) {
1196
        if( $mandatory->{lc $col} ) {
1196
        $self->_anonymize_column($col, $mandatory->{lc $col} );
1197
            my $str = $self->_anonymize_column($col);
1198
            $self->$col($str);
1199
        } else {
1200
            $self->$col(undef);
1201
        }
1202
    }
1197
    }
1203
    $self->flgAnonymized(1)->store;
1198
    $self->flgAnonymized(1)->store;
1204
}
1199
}
1205
1200
1206
sub _anonymize_column {
1201
sub _anonymize_column {
1207
    my ( $self, $col ) = @_;
1202
    my ( $self, $col, $mandatory ) = @_;
1208
    my $type = $self->_result->result_source->column_info($col)->{data_type};
1203
    my $col_info = $self->_result->result_source->column_info($col);
1204
    my $type = $col_info->{data_type};
1205
    my $nullable = $col_info->{is_nullable};
1206
    my $val;
1209
    if( $type =~ /char|text/ ) {
1207
    if( $type =~ /char|text/ ) {
1210
        return Koha::Token->new->generate({ pattern => '\w{10}' });
1208
        $val = $mandatory
1209
            ? Koha::Token->new->generate({ pattern => '\w{10}' })
1210
            : $nullable
1211
            ? undef
1212
            : q{};
1211
    } elsif( $type =~ /integer|int$|float|dec|double/ ) {
1213
    } elsif( $type =~ /integer|int$|float|dec|double/ ) {
1212
        return 0;
1214
        $val = $nullable ? undef : 0;
1213
    } elsif( $type =~ /date|time/ ) {
1215
    } elsif( $type =~ /date|time/ ) {
1214
        return dt_from_string;
1216
        $val = $nullable ? undef : dt_from_string;
1215
    }
1217
    }
1218
    $self->$col($val);
1216
}
1219
}
1217
1220
1218
=head3 can_see_patron_infos
1221
=head3 can_see_patron_infos
1219
- 

Return to bug 21336