From eac9d991782c8d4ee40b83bb5dfd487bfdf25569 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Sat, 9 May 2015 01:31:37 -0400 Subject: [PATCH] Bug 14145: Nicer counter-patch The problem with the odd number of hashes happens when not everything is selected. The grep returns undef, because it isn't found in @values. By turning the grep into a ternary-operator truth value, we can set a value (1 or 0) expressly. The next problem is when nothing is selected in these multiple lists, $value is undefined, so you can't split it. By splitting the definition of @values from the actual splitting, we can split only if $value is defined, thus eliminating the warning message. TEST PLAN --------- 1) back up your koha error log file 2) blank your koha error log file 3) log in to the staff client 4) Home -> Koha administration -> Global system preferences 5) Click on every tab, EXCEPT local use. 6) notice the koha error log file has warnings. 7) blank the koha error log file again 8) apply this patch 9) Click on every tab, EXCEPT local use, again. 10) notice the koha error log file has no warnings. 11) koha qa test tools. --- admin/preferences.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/admin/preferences.pl b/admin/preferences.pl index 1bd961e..d9683f1 100755 --- a/admin/preferences.pl +++ b/admin/preferences.pl @@ -106,7 +106,8 @@ sub _get_chunk { keys %{ $options{'choices'} } ]; } elsif ( $options{'multiple'} ) { - my @values = split /,/, $value; + my @values; + @values = split /,/, $value if defined($value); $chunk->{type} = 'multiple'; $chunk->{CHOICES} = [ sort { $a->{'text'} cmp $b->{'text'} } @@ -115,7 +116,7 @@ sub _get_chunk { { text => $options{multiple}->{$option_value}, value => $option_value, - selected => grep /^$option_value$/, @values, + selected => (grep /^$option_value$/, @values) ? 1 : 0, } } keys %{ $options{multiple} } -- 2.1.4