Bugzilla – Attachment 179388 Details for
Bug 39334
Preserve order when saving patron attributes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39334: (follow-up) Preserve order when adding patron attributes
Bug-39334-follow-up-Preserve-order-when-adding-pat.patch (text/plain), 6.34 KB, created by
Jonathan Druart
on 2025-03-17 11:23:52 UTC
(
hide
)
Description:
Bug 39334: (follow-up) Preserve order when adding patron attributes
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-03-17 11:23:52 UTC
Size:
6.34 KB
patch
obsolete
>From a51a87be6aba06f77d241035fd1709ff4e9ddf7b Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >Date: Thu, 13 Mar 2025 19:36:03 +0100 >Subject: [PATCH] Bug 39334: (follow-up) Preserve order when adding patron > attributes > >To test: >1) Run tests in t/db_dependent/api/v1/patrons_extended_attributes.t, serveral should fail >2) Apply patch >3) Run the tests in 1) again, all should now pass > >Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/Patron.pm | 82 +++++++++++++++++++++++++++----------------------- > 1 file changed, 44 insertions(+), 38 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index ecdf96dc108..fd7cf85fc21 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -2305,11 +2305,9 @@ sub extended_attributes { > $attribute->validate_type(); > } > >- # Sort new attributes by code >- @new_attributes = sort { $a->attribute cmp $b->attribute } @new_attributes; >- > # Stash changes after >- for my $attribute ( values @new_attributes ) { >+ # Sort attributes to ensure order is the same as for current attributes retrieved above >+ for my $attribute ( sort { $a->attribute cmp $b->attribute } @new_attributes ) { > my $repeatable = $attribute->type->repeatable ? 1 : 0; > $attribute_changes{$repeatable}->{ $attribute->code }->{after} //= []; > push( >@@ -2327,12 +2325,15 @@ sub extended_attributes { > $schema->txn_do( > sub { > my $all_changes = {}; >+ my %changed_attributes_codes; > while ( my ( $repeatable, $changes ) = each %attribute_changes ) { > while ( my ( $code, $change ) = each %{$changes} ) { > $change->{before} //= []; > $change->{after} //= []; > > if ( $is_different->( $change->{before}, $change->{after} ) ) { >+ $changed_attributes_codes{$code} = 1; >+ > unless ($repeatable) { > $change->{before} = @{ $change->{before} } ? $change->{before}->[0] : ''; > $change->{after} = @{ $change->{after} } ? $change->{after}->[0] : ''; >@@ -2345,49 +2346,54 @@ sub extended_attributes { > } > )->delete; > >- # Add possible new attribute values >- for my $attribute (@new_attributes) { >- $attribute->store() if ( $attribute->code eq $code ); >- } > if ( C4::Context->preference("BorrowersLog") ) { > $all_changes->{"attribute.$code"} = $change; > } > } > } > } >- my $new_types = {}; >- for my $attribute ( @{$attributes} ) { >- $new_types->{ $attribute->{code} } = 1; >- } > >- # Check globally mandatory types >- my $interface = C4::Context->interface; >- my $params = { >- mandatory => 1, >- category_code => [ undef, $self->categorycode ], >- 'borrower_attribute_types_branches.b_branchcode' => undef, >- }; >+ if (%changed_attributes_codes) { > >- if ( $interface eq 'opac' ) { >- $params->{opac_editable} = 1; >- } >+ # Store changed attributes in the order they where passed in as some tests >+ # relies on ids being assigned in that order >+ my $new_types = {}; >+ for my $new_attribute (@new_attributes) { >+ $new_attribute->store() if $changed_attributes_codes{ $new_attribute->code }; >+ $new_types->{ $new_attribute->code } = 1; >+ } > >- my @required_attribute_types = Koha::Patron::Attribute::Types->search( >- $params, >- { join => 'borrower_attribute_types_branches' } >- )->get_column('code'); >- for my $type (@required_attribute_types) { >- Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute->throw( >- type => $type, >- ) if !$new_types->{$type}; >- } >- if ( %{$all_changes} ) { >- logaction( >- "MEMBERS", >- "MODIFY", >- $self->borrowernumber, >- to_json( $all_changes, { pretty => 1, canonical => 1 } ) >- ); >+ # Check globally mandatory types >+ my $interface = C4::Context->interface; >+ my $params = { >+ mandatory => 1, >+ category_code => [ undef, $self->categorycode ], >+ 'borrower_attribute_types_branches.b_branchcode' => undef, >+ }; >+ >+ if ( $interface eq 'opac' ) { >+ $params->{opac_editable} = 1; >+ } >+ >+ my @required_attribute_types = Koha::Patron::Attribute::Types->search( >+ $params, >+ { join => 'borrower_attribute_types_branches' } >+ )->get_column('code'); >+ >+ for my $type (@required_attribute_types) { >+ Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute->throw( >+ type => $type, >+ ) if !$new_types->{$type}; >+ } >+ >+ if ( %{$all_changes} ) { >+ logaction( >+ "MEMBERS", >+ "MODIFY", >+ $self->borrowernumber, >+ to_json( $all_changes, { pretty => 1, canonical => 1 } ) >+ ); >+ } > } > } > ); >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39334
:
179329
|
179377
| 179388