From eed4b0940dd3beaa26f63d3e8d936f1efff9a9e9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 28 May 2024 13:26:03 -0400 Subject: [PATCH] Bug 35508: Don't update patron attributes if new list of attributes matches list of existing attributes Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer --- Koha/Patron/Attribute.pm | 1 + members/memberentry.pl | 44 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index 863d55850b..93b25ece02 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -58,6 +58,7 @@ 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 diff --git a/members/memberentry.pl b/members/memberentry.pl index d8cf801361..c5114c664c 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -592,9 +592,47 @@ if ((!$nok) and $nodouble and ($op eq 'cud-insert' or $op eq 'cud-save')){ if ( $success ) { 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); - } + my $existing_attributes = $patron->extended_attributes->filter_by_branch_limitations->unblessed; + + my $needs_update = 1; + + # If there are an unqueunal number of new and old patron attributes they definietely need updated + if ( scalar @{$existing_attributes} == scalar @{$extended_patron_attributes} ) { + my $seen = 0; + for ( my $i = 0 ; $i <= scalar @{$extended_patron_attributes} ; $i++ ) { + my $new_attr = $extended_patron_attributes->[$i]; + next unless $new_attr; + for ( my $j = 0 ; $j <= scalar @{$existing_attributes} ; $j++ ) { + my $existing_attr = $existing_attributes->[$j]; + next unless $existing_attr; + + if ( $new_attr->{attribute} eq $existing_attr->{attribute} + && $new_attr->{borrowernumber} eq $existing_attr->{borrowernumber} + && $new_attr->{code} eq $existing_attr->{code} ) + { + $seen++; + + # Remove the match from the "old" attribute + splice( @{$existing_attributes}, $j, 1 ); + + # Move on to look at the next "new" attribute + last; + } + } + } + + # If we found a match for each existing attribute and the number of see attributes matches the number seen + # we don't need to update the attributes + if ( scalar @{$existing_attributes} == 0 && $seen == @{$extended_patron_attributes} ) { + $needs_update = 0; + } + } + + if ($needs_update) { + $patron->extended_attributes->filter_by_branch_limitations->delete; + $patron->extended_attributes($extended_patron_attributes); + } + } if ( $destination eq 'circ' and not C4::Auth::haspermission( C4::Context->userenv->{id}, { circulate => 'circulate_remaining_permissions' } ) ) { # If we want to redirect to circulation.pl and need to check if the logged in user has the necessary permission -- 2.39.5