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 <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2025-09-22 15:18:44 -03:00 committed by Lucas Gass
parent ea3065aeef
commit f1f0963f62
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 7 additions and 32 deletions

View File

@ -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;
# Build attributes hash directly
my %attributes = map { $_->type => $_->value } $original_attributes->as_list;
$attributes{migrated_from} = $original_request->illrequest_id;
push @request_details_array, {
'type' => 'migrated_from',
'value' => $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;