Bug 16809: Silence authority warnings C4::Biblio::TransformHtmlToMarc
authorMark Tompsett <mtompset@hotmail.com>
Fri, 24 Jun 2016 15:29:19 +0000 (11:29 -0400)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 2 Sep 2016 15:50:25 +0000 (15:50 +0000)
Most of the floodiness is caused by accessing the cgi parameters
in a context which is hard to determine. By purposefully saving
the value to a scalar variable and using the variable, the issue
disappears, and it will likely be a tiny tad faster as variable
access is faster than multiple function calls.

TEST PLAN
---------
 1) Back up your intranet error log
    -- for example:
       cp ~/koha-dev/var/log/koha-error-log ~/koha-error-log.backup
 2) Blank your intranet error log
    -- for example:
       echo > ~/koha-dev/var/log/koha-error-log
 3) Log into your staff client
 4) Click 'Authorities'
 5) Click 'New from Z39.50'
 5) Type 'Seuss' into 'Name (any):' and press enter
 6) Click 'Import' beside the first link
 7) Click 'Save'
 8) Check your koha-error-log
    -- floody!
 9) Apply patch
10) repeat steps 2-8
    -- blank!
11) restore your intranet error log
   -- for example:
      mv ~/koha-error-log.backup ~/koha-dev/var/log/koha-error-log
12) run koha qa test tools

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tested with addbiblio.pl. I would have preferred the scalar option in terms
of simpler code, but this works too.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

C4/Biblio.pm

index 2798325..3c99638 100644 (file)
@@ -2574,18 +2574,19 @@ sub TransformHtmlToMarc {
             if ( $tag < 10 ) {                              # no code for theses fields
                                                             # in MARC editor, 000 contains the leader.
                 next if $tag == $biblionumbertagfield;
+                my $fval= $cgi->param($params[$j+1]);
                 if ( $tag eq '000' ) {
                     # Force a fake leader even if not provided to avoid crashing
                     # during decoding MARC record containing UTF-8 characters
                     $record->leader(
-                        length( $cgi->param($params[$j+1]) ) == 24
-                        ? $cgi->param( $params[ $j + 1 ] )
+                        length( $fval ) == 24
+                        ? $fval
                         : '     nam a22        4500'
                        )
                     ;
                     # between 001 and 009 (included)
-                } elsif ( $cgi->param( $params[ $j + 1 ] ) ne '' ) {
-                    $newfield = MARC::Field->new( $tag, $cgi->param( $params[ $j + 1 ] ), );
+                } elsif ( $fval ne '' ) {
+                    $newfield = MARC::Field->new( $tag, $fval, );
                 }
 
                 # > 009, deal with subfields
@@ -2599,13 +2600,14 @@ sub TransformHtmlToMarc {
                     #if next param ne subfield, then it was probably empty
                     #try next param by incrementing j
                     if($params[$j+1]!~/_subfield_/) {$j++; next; }
+                    my $fkey= $cgi->param($params[$j]);
                     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);
+                        $newfield->add_subfields( $fkey => $fval);
                     }
                     elsif($fval ne '') {
-                        $newfield = MARC::Field->new( $tag, $ind1, $ind2, $cgi->param($params[$j]) => $fval );
+                        $newfield = MARC::Field->new( $tag, $ind1, $ind2, $fkey => $fval );
                     }
                     $j += 2;
                 } #end-of-while