From 37773c64df09a16633dfd000ba1b725d226a3083 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 30 Nov 2023 11:47:53 +0000 Subject: [PATCH] Bug 35451: Record table in set_additional_fields --- Koha/Object/Mixin/AdditionalFields.pm | 39 +++++++++++++++------------ 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Koha/Object/Mixin/AdditionalFields.pm b/Koha/Object/Mixin/AdditionalFields.pm index bf6598d8c9b..d4bf0dd36e9 100644 --- a/Koha/Object/Mixin/AdditionalFields.pm +++ b/Koha/Object/Mixin/AdditionalFields.pm @@ -43,51 +43,56 @@ Koha::Object::Mixin::AdditionalFields =cut sub set_additional_fields { - my ($self, $additional_fields) = @_; + my ( $self, $additional_fields ) = @_; $self->additional_field_values->delete; + my $table = $self->_result->table; + my $biblionumber; my $record; my $record_updated; - if ($self->_result->has_column('biblionumber')) { + if ( $self->_result->has_column('biblionumber') ) { $biblionumber = $self->biblionumber; } foreach my $additional_field (@$additional_fields) { - my $field = Koha::AdditionalFields->find($additional_field->{id}); + my $field = Koha::AdditionalFields->find( $additional_field->{id} ); my $value = $additional_field->{value}; - if ($biblionumber and $field->marcfield) { + if ( $biblionumber and $field->marcfield ) { require Koha::Biblios; $record //= Koha::Biblios->find($biblionumber)->metadata->record; - my ($tag, $subfield) = split /\$/, $field->marcfield; + my ( $tag, $subfield ) = split /\$/, $field->marcfield; my $marc_field = $record->field($tag); - if ($field->marcfield_mode eq 'get') { + if ( $field->marcfield_mode eq 'get' ) { $value = $marc_field ? $marc_field->subfield($subfield) : ''; - } elsif ($field->marcfield_mode eq 'set') { + } elsif ( $field->marcfield_mode eq 'set' ) { if ($marc_field) { - $marc_field->update($subfield => $value); + $marc_field->update( $subfield => $value ); } else { - $marc_field = MARC::Field->new($tag, '', '', $subfield => $value); + $marc_field = MARC::Field->new( $tag, '', '', $subfield => $value ); $record->append_fields($marc_field); } $record_updated = 1; } } - if (defined $value) { - my $field_value = Koha::AdditionalFieldValue->new({ - field_id => $additional_field->{id}, - record_id => $self->id, - value => $value, - })->store; + if ( defined $value ) { + my $field_value = Koha::AdditionalFieldValue->new( + { + field_id => $additional_field->{id}, + record_table => $table, + record_id => $self->id, + value => $value, + } + )->store; } } if ($record_updated) { - C4::Biblio::ModBiblio($record, $biblionumber); + C4::Biblio::ModBiblio( $record, $biblionumber ); } } @@ -103,7 +108,7 @@ sub additional_field_values { my ($self) = @_; my $afv_rs = $self->_result->additional_field_values; - return Koha::AdditionalFieldValues->_new_from_dbic( $afv_rs ); + return Koha::AdditionalFieldValues->_new_from_dbic($afv_rs); } =head1 AUTHOR -- 2.43.0