Bugzilla – Attachment 179284 Details for
Bug 26744
Log changes to extended patron attributes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26744i: (follow up) Preserve order when adding patron attributes
Bug-26744i-follow-up-Preserve-order-when-adding-pa.patch (text/plain), 6.09 KB, created by
David Gustafsson
on 2025-03-13 19:02:44 UTC
(
hide
)
Description:
Bug 26744i: (follow up) Preserve order when adding patron attributes
Filename:
MIME Type:
Creator:
David Gustafsson
Created:
2025-03-13 19:02:44 UTC
Size:
6.09 KB
patch
obsolete
>From 102649c57c3d3912daa055e7f120143eb658f8f4 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 26744i: (follow up) Preserve order when adding patron > attributes > >--- > Koha/Patron.pm | 84 +++++++++++++++++++++++++++----------------------- > 1 file changed, 46 insertions(+), 38 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index bd3572d92c4..47e5706faf9 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,6 +2325,7 @@ 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} //= []; >@@ -2338,6 +2337,8 @@ sub extended_attributes { > $change->{after} = @{ $change->{after} } ? $change->{after}->[0] : ''; > } > >+ push @changed_attributes_codes, $code; >+ > # Remove existing > $self->extended_attributes->filter_by_branch_limitations->search( > { >@@ -2345,49 +2346,56 @@ 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) { >+ if ( grep { $_ eq $new_attribute->code } @changed_attributes_codes ) { >+ $new_attribute->store(); >+ } >+ $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 26744
:
163957
|
163958
|
163959
|
164034
|
164035
|
164098
|
165212
|
165213
|
165301
|
165302
|
165303
|
165304
|
165305
|
177605
|
177652
|
178728
|
178771
|
178787
|
178788
|
178789
|
178801
|
178802
|
178803
|
178817
|
178839
|
178840
|
178841
|
178842
|
179284
|
179285
|
179286