From cc58bf3c81c4ad2e623d68edf94837b74b5b1d36 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Jan 2014 10:27:48 +0100 Subject: [PATCH] Bug 10855: Additional marc fields are not inserted In subscription-add.pl, the code for inserting additional_fields is not the same for updating and inserting. This patch refactores this code in code to do the same tests. Signed-off-by: Brendan Gallagher Signed-off-by: Tomas Cohen Arazi --- serials/subscription-add.pl | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index f9a0c4eb3e..fedb7dafd0 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -345,14 +345,7 @@ sub redirect_add_subscription { ); my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); - my @additional_field_values; - for my $field ( @$additional_fields ) { - my $af = Koha::AdditionalField->new({ id => $field->{id} }); - $af->{values} = { - $subscriptionid => $query->param('additional_field_' . $field->{id}) - } if defined $query->param('additional_field_' . $field->{id}); - $af->insert_values; - } + insert_additional_fields( $additional_fields, $biblionumber, $subscriptionid ); print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); return; @@ -430,25 +423,32 @@ sub redirect_mod_subscription { ); my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); + insert_additional_fields( $additional_fields, $biblionumber, $subscriptionid ); + + print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); + return; +} + +sub insert_additional_fields { + my ( $additional_fields, $biblionumber, $subscriptionid ) = @_; my @additional_field_values; + my $record = GetMarcBiblio( $biblionumber, 1 ); for my $field ( @$additional_fields ) { my $af = Koha::AdditionalField->new({ id => $field->{id} })->fetch; if ( $af->{marcfield} ) { - my $record = GetMarcBiblio( $biblionumber, 1 ); my ( $field, $subfield ) = split /\$/, $af->{marcfield}; - next unless $field and $subfield; - my $value = $record->subfield( $field, $subfield ); - $af->{values} = { - $subscriptionid => $value - }; + $af->{values} = undef; + if ( $field and $subfield ) { + my $value = $record->subfield( $field, $subfield ); + $af->{values} = { + $subscriptionid => $value + }; + } } else { $af->{values} = { $subscriptionid => $query->param('additional_field_' . $field->{id}) - }; + } if defined $query->param('additional_field_' . $field->{id}); } $af->insert_values; } - - print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); - return; } -- 2.39.5