From 4624425bf800cba280a0afc69c2c9e97a7dbda62 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 Signed-off-by: Katrin Fischer --- Koha/Patron/Attribute.pm | 4 +++ members/memberentry.pl | 1 - t/db_dependent/Koha/Patron/Attribute.t | 41 +++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index 5fc1b9111d..863d55850b 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -58,6 +58,10 @@ sub store { Koha::Exceptions::Patron::Attribute::InvalidAttributeValue->throw( attribute => $self ) unless $self->value_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 f2a675b9b9..d8cf801361 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -594,7 +594,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 f68692e57b..e9e9f9c7fb 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 => 5; + plan tests => 6; + + 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.39.5