From 9ed1f74bcf89d87065138538efb0019843c23aaa Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 10 Jul 2025 21:55:05 +0200 Subject: [PATCH] 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. --- Koha/Patron.pm | 2 ++ t/db_dependent/Koha/Patrons.t | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 14d5838e6be..ecfe7d40bb4 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -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); } diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index ed7ad7a3516..54595fecc67 100755 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -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' ); }; -- 2.34.1