From a83c3bc16ede9829faf167da186d9aef8c787ff5 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 17 Apr 2024 09:29:29 -0400 Subject: [PATCH] Bug 35508: Move logic to Koha::Patron::Attribute::store() Signed-off-by: Kyle M Hall --- Koha/Patron/Attribute.pm | 5 ++++ members/memberentry.pl | 1 - t/db_dependent/Koha/Patron/Attribute.t | 41 +++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index aaaefbcbb80..5ae0ba29b0e 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -55,6 +55,11 @@ sub store { Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( attribute => $self ) unless $self->unique_ok(); + C4::Context->dbh->do( + "UPDATE borrowers SET updated_on = NOW() WHERE borrowernumber = ?", undef, + $self->borrowernumber + ); + return $self->SUPER::store(); } diff --git a/members/memberentry.pl b/members/memberentry.pl index d5f9a9da36f..702f2c68980 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -576,7 +576,6 @@ if ((!$nok) and $nodouble and ($op eq 'cud-insert' or $op eq 'cud-save')){ if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { $patron->extended_attributes->filter_by_branch_limitations->delete; $patron->extended_attributes($extended_patron_attributes); - $patron->set( { updated_on => "" } )->store; } if ( $destination eq 'circ' and not C4::Auth::haspermission( C4::Context->userenv->{id}, { circulate => 'circulate_remaining_permissions' } ) ) { diff --git a/t/db_dependent/Koha/Patron/Attribute.t b/t/db_dependent/Koha/Patron/Attribute.t index a24de0fb2d2..10913023c7a 100755 --- a/t/db_dependent/Koha/Patron/Attribute.t +++ b/t/db_dependent/Koha/Patron/Attribute.t @@ -33,7 +33,46 @@ my $builder = t::lib::TestBuilder->new; subtest 'store() tests' => sub { - plan tests => 4; + plan tests => 5; + + subtest 'Update an attribute should update the patron "updated_on" field' => sub { + + plan tests => 1; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $updated_on = $patron->updated_on; + + sleep 1; # Timestamps are in one second increments, so we need to wait one second + + my $type = $builder->build_object( + { + class => 'Koha::Patron::Attribute::Types', + value => { + mandatory => 0, + repeatable => 0, + unique_id => 0, + category_code => undef + } + } + ); + + my $attr = $patron->add_extended_attribute( + { + code => $type->code, + attribute => 'TEST' + } + ); + + $attr->set( { attribute => 'TEST' } )->store(); + + $patron->discard_changes; + + isnt( $updated_on, $patron->updated_on, "Updated on was updated by attribute storage" ); + + $schema->storage->txn_rollback; + }; subtest 'repeatable attributes tests' => sub { -- 2.30.2