Bug 6840 warning in logs
authorPaul Poulain <paul.poulain@biblibre.com>
Fri, 2 Sep 2011 16:39:53 +0000 (18:39 +0200)
committerChris Cormack <chrisc@catalyst.net.nz>
Thu, 13 Oct 2011 03:17:33 +0000 (16:17 +1300)
In staff interface, in search (catalogue/search.pl), there is a warning saying:
[Fri Sep  2 18:20:24 2011] search.pl: Use of uninitialized value $key in hash
element at /home/paul/koha.dev/koha-community/C4/Templates.pm line 227.

The problem happens when searching from the quick search toolbar, not when you
search from advanced search.
Investigating, it seems it's because the sort_by is not defined in this case.

This patch
* fixes the problem in Search.pl by setting the parameter only if there is a sort_by field
* modify te Template->param sub to get a better error message. Instead of having just "use of uninitia..." get the value you try to set to an empty key. Much easier to understand which line causes the problem

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Ian Walls <ian.walls@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Templates.pm
catalogue/search.pl

index c3a9850..c2a5911 100644 (file)
@@ -179,7 +179,11 @@ sub param {
         my $val = shift;
         if    ( ref($val) eq 'ARRAY' && !scalar @$val ) { $val = undef; }
         elsif ( ref($val) eq 'HASH'  && !scalar %$val ) { $val = undef; }
-        $self->{VARS}->{$key} = $val;
+        if ( $key ) {
+            $self->{VARS}->{$key} = $val;
+        } else {
+            warn "Problem = a value of $val has been passed to param without key";
+        }
     }
 }
 
index 97fa3d7..907efdb 100755 (executable)
@@ -369,7 +369,7 @@ if (   C4::Context->preference('defaultSortField')
 @sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'};
 $sort_by[0] = $default_sort_by unless $sort_by[0];
 foreach my $sort (@sort_by) {
-    $template->param($sort => 1);
+    $template->param($sort => 1) if $sort;
 }
 $template->param('sort_by' => $sort_by[0]);