From 06fbd1b345b59d79e4d62e3268f45b845000d0f0 Mon Sep 17 00:00:00 2001 From: Baptiste Date: Thu, 31 Oct 2024 12:28:14 +0100 Subject: [PATCH] Bug 34989: [23.11] Subscription cannot be added if a control field is set up in "Additional Fields" parameter Test plan for MARC21: 1 - Create a subscription 2 - Go to administration -> aditional fields add a field for any CONTROL field existing in your subscription for example 005 3 - Also create an additional field for 245$a (check non regression) 4 - On the subscription page: Edit -> Edit subscription -> Next -> Save subscription -> You get: "Internal server error" 5 - Apply patch 6 - Repeat 4, you have no error anymore. On the subscription page you can see both additional fields. --- Koha/Object/Mixin/AdditionalFields.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Koha/Object/Mixin/AdditionalFields.pm b/Koha/Object/Mixin/AdditionalFields.pm index bf6598d8c9b..9964a50113d 100644 --- a/Koha/Object/Mixin/AdditionalFields.pm +++ b/Koha/Object/Mixin/AdditionalFields.pm @@ -65,13 +65,21 @@ sub set_additional_fields { my ($tag, $subfield) = split /\$/, $field->marcfield; my $marc_field = $record->field($tag); if ($field->marcfield_mode eq 'get') { - $value = $marc_field ? $marc_field->subfield($subfield) : ''; - } elsif ($field->marcfield_mode eq 'set') { - if ($marc_field) { - $marc_field->update($subfield => $value); + if ($subfield) { + $value = $marc_field ? $marc_field->subfield($subfield) : ''; } else { + $value = $marc_field ? $marc_field->data() : ''; + } + } elsif ($field->marcfield_mode eq 'set') { + if ( $marc_field and $subfield ) { + $marc_field->update( $subfield => $value ); + } elsif ($marc_field) { + $marc_field->update($value); + } elsif ($subfield) { $marc_field = MARC::Field->new($tag, '', '', $subfield => $value); $record->append_fields($marc_field); + } else { + $marc_field = MARC::Field->new( $tag, '', '', $value ); } $record_updated = 1; } -- 2.30.2