Bug 40337: Handle enum in Koha::Patron->anonymize

We need to reset to the default value. We might have a problem (later)
if it's NOT NULL and no default is set, which is not handled by this
patch. But the situation does not seem to exist yet anyway.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit b4a561c133)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-07-10 21:55:05 +02:00 committed by Paul Derscheid
parent c34f53df6c
commit b78ca44451
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 11 additions and 8 deletions

View File

@ -2677,6 +2677,8 @@ sub _anonymize_column {
$val = $nullable ? undef : 0;
} elsif ( $type =~ /date|time/ ) {
$val = $nullable ? undef : dt_from_string;
} elsif ( $type eq 'enum' ) {
$val = $nullable ? undef : $col_info->{default_value};
}
$self->$col($val);
}

View File

@ -2675,10 +2675,10 @@ subtest 'lock' => sub {
};
subtest 'anonymize' => sub {
plan tests => 10;
plan tests => 11;
my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } );
my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } );
my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } )->store;
my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } )->store;
# First try patron with issues
my $issue = $builder->build_object(
@ -2696,16 +2696,17 @@ subtest 'anonymize' => sub {
is( $patron1->firstname, undef, 'First name cleared' );
isnt( $patron1->surname, $surname, 'Surname changed' );
ok( $patron1->surname =~ /^\w{10}$/, 'Mandatory surname randomized' );
is( $patron1->branchcode, $branchcode, 'Branch code skipped' );
is( $patron1->email, undef, 'Email was mandatory, must be cleared' );
is( $patron1->branchcode, $branchcode, 'Branch code skipped' );
is( $patron1->email, undef, 'Email was mandatory, must be cleared' );
is( $patron1->checkprevcheckout, 'inherit', 'Enum checkprevcheckout is reset to the default value' );
# Test wrapper in Koha::Patrons
$patron1->surname($surname)->store; # restore
$patron1->surname($surname)->store; # restore
my $rs = Koha::Patrons->search( { borrowernumber => [ $patron1->borrowernumber, $patron2->borrowernumber ] } )
->anonymize;
$patron1->discard_changes; # refresh
$patron1->discard_changes; # refresh
isnt( $patron1->surname, $surname, 'Surname patron1 changed again' );
$patron2->discard_changes; # refresh
$patron2->discard_changes; # refresh
is( $patron2->firstname, undef, 'First name patron2 cleared' );
};