From 80798709119588651fc1673bef804da8a2873643 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. --- 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 6fa68a1..b1055c6 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -348,14 +348,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; @@ -433,25 +426,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_fiels, $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; } -- 1.7.10.4