From 00e94f63dcf34f0e3eaa1f1bcfc1481db9f5e8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Mon, 22 Sep 2025 15:18:44 -0300 Subject: [PATCH] Bug 40850: (follow-up) Use add_or_update_attributes in Standard backend This patch updates the Standard ILL backend to use the new add_or_update_attributes() method instead of the problematic extended_attributes() method that only supports adding new attributes. Changes: - Request creation: Use add_or_update_attributes() for setting metadata - Request migration: Use add_or_update_attributes() for copying attributes Benefits: - Eliminates duplicate key errors when updating existing requests - Cleaner code - removes array-to-hash conversion boilerplate - More efficient - only updates attributes when values change - Consistent with new Koha::ILL::Request API patterns Locations updated: - add_request(): Request creation with metadata (line ~1017) - migrate(): Request migration copying attributes (line ~731) Test plan: 1. Apply patch 2. Test ILL request creation in Standard backend: - Create new ILL request with metadata => SUCCESS: Request created with attributes 3. Test ILL request migration: - Migrate existing request to new request => SUCCESS: Attributes copied correctly 4. Test updating existing request metadata: - Edit request and update metadata fields => SUCCESS: No duplicate key errors 5. Sign off :-D Signed-off-by: Martin Renvoize --- Koha/ILL/Backend/Standard.pm | 39 +++++++----------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/Koha/ILL/Backend/Standard.pm b/Koha/ILL/Backend/Standard.pm index acc7bda9c56..57529f049f6 100644 --- a/Koha/ILL/Backend/Standard.pm +++ b/Koha/ILL/Backend/Standard.pm @@ -716,19 +716,11 @@ sub migrate { my $original_attributes = $original_request->extended_attributes->search( { type => { '-in' => \@default_attributes } } ); - my @request_details_array = map { - { - 'type' => $_->type, - 'value' => $_->value, - } - } $original_attributes->as_list; - - push @request_details_array, { - 'type' => 'migrated_from', - 'value' => $original_request->illrequest_id, - }; + # Build attributes hash directly + my %attributes = map { $_->type => $_->value } $original_attributes->as_list; + $attributes{migrated_from} = $original_request->illrequest_id; - $new_request->extended_attributes( \@request_details_array ); + $new_request->add_or_update_attributes( \%attributes ); return { error => 0, @@ -809,19 +801,8 @@ sub _set_requested_partners { # the time we get to this stage, any previous request # from partners would have had to be cancelled my ($args) = @_; - my $where = { - illrequest_id => $args->{request}->id, - type => 'requested_partners' - }; - Koha::ILL::Request::Attributes->search($where)->delete(); - Koha::ILL::Request::Attribute->new( - { - illrequest_id => $args->{request}->id, - column_exists( 'illrequestattributes', 'backend' ) ? ( backend => "Standard" ) : (), - type => 'requested_partners', - value => $args->{to} - } - )->store; + + $args->{request}->add_or_update_attributes( { requested_partners => $args->{to} } ); } =head3 _validate_borrower @@ -1008,13 +989,7 @@ sub add_request { if column_exists( 'illrequests', 'batch_id' ); $request->store; - my @request_details_array = map { - { - 'type' => $_, - 'value' => $request_details->{$_}, - } - } keys %{$request_details}; - $request->extended_attributes( \@request_details_array ); + $request->add_or_update_attributes($request_details); $request->add_unauthenticated_data( $params->{other} ) if $unauthenticated_request; $request->after_created; -- 2.51.0