From 795dc61f7526c3810173139004c741dc8c810382 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 19 Jan 2012 09:50:03 +0100 Subject: [PATCH] Bug 3264 UnCloneField() / minus button in MARC editor can clear all subfields (authorities AND biblio) All subfields following the removed subfield were not saved. Problem is in C4/Biblio routine TransformHtmlToMarc. If the field is emptied, the param list contains a code param but no subfield param. The while loop handling the subfields could not handle that. Also added a FIXME because the whole routine depends on an assumption about the order of cgi parameters that is not strictly guaranteed. Signed-off-by: Jared Camins-Esakov I was unable to replicate the problem, but can confirm that the patch does not break anything under any of the following platforms/browsers: Mac OS X 10.6.8: Chrome 16.0.912.77 Firefox 9.0.1 Windows 7: Firefox 3.6.3 Firefox 9.0.1 IE 8.0.7600.16385 Ubuntu 11.10 Firefox 8.0 Chromium 15.0.874.106 (Developer Build 107270 Linux) Signed-off-by: Paul Poulain --- C4/Biblio.pm | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 83fef13f1c..8d2dd9d46b 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2142,6 +2142,7 @@ sub TransformHtmlToMarc { my $record = MARC::Record->new(); my $i = 0; my @fields; +#FIXME This code assumes that the CGI params will be in the same order as the fields in the template; this is no absolute guarantee! while ( $params[$i] ) { # browse all CGI params my $param = $params[$i]; my $newfield = 0; @@ -2181,19 +2182,23 @@ sub TransformHtmlToMarc { # > 009, deal with subfields } else { - while ( defined $params[$j] && $params[$j] =~ /_code_/ ) { # browse all it's subfield - my $inner_param = $params[$j]; - if ($newfield) { - if ( $cgi->param( $params[ $j + 1 ] ) ne '' ) { # only if there is a value (code => value) - $newfield->add_subfields( $cgi->param($inner_param) => $cgi->param( $params[ $j + 1 ] ) ); - } - } else { - if ( $cgi->param( $params[ $j + 1 ] ) ne '' ) { # creating only if there is a value (code => value) - $newfield = MARC::Field->new( $tag, $ind1, $ind2, $cgi->param($inner_param) => $cgi->param( $params[ $j + 1 ] ), ); - } + # browse subfields for this tag (reason for _code_ match) + while(defined $params[$j] && $params[$j] =~ /_code_/) { + last unless defined $params[$j+1]; + #if next param ne subfield, then it was probably empty + #try next param by incrementing j + if($params[$j+1]!~/_subfield_/) {$j++; next; } + my $fval= $cgi->param($params[$j+1]); + #check if subfield value not empty and field exists + if($fval ne '' && $newfield) { + $newfield->add_subfields( $cgi->param($params[$j]) => $fval); + } + elsif($fval ne '') { + $newfield = MARC::Field->new( $tag, $ind1, $ind2, $cgi->param($params[$j]) => $fval ); } $j += 2; - } + } #end-of-while + $i= $j-1; #update i for outer loop accordingly } push @fields, $newfield if ($newfield); } -- 2.39.5