Bugzilla – Attachment 8775 Details for
Bug 7874
Templates::get_language generates lots of not defined warnings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch
0001-Bug-7874-Stop-unnecessary-warnings-in-get_language.patch (text/plain), 2.36 KB, created by
Colin Campbell
on 2012-04-02 14:44:19 UTC
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Colin Campbell
Created:
2012-04-02 14:44:19 UTC
Size:
2.36 KB
patch
obsolete
>From c6ddef9a552a8119b99327b2840b27f89666db71 Mon Sep 17 00:00:00 2001 >From: Colin Campbell <colin.campbell@ptfs-europe.com> >Date: Mon, 2 Apr 2012 15:06:28 +0100 >Subject: [PATCH] [Bug 7874] Stop unnecessary warnings in get_language > >Refactor code to be more idiomatic and clarify its intention > was testing undef against languages causing log warn > was creating and assigning to unnecessary variables > calling accept_language with an undef is an > expensive way to get undef returned to the caller > test we are asking it a meabingful question > use any rather than first ( we dont care about firstness it > should be unique anyway but it obscures the meaning of the test ) > split takes a pattern not a string >--- > C4/Templates.pm | 24 +++++++++++------------- > 1 files changed, 11 insertions(+), 13 deletions(-) > >diff --git a/C4/Templates.pm b/C4/Templates.pm >index 0741040..d6e3ce4 100644 >--- a/C4/Templates.pm >+++ b/C4/Templates.pm >@@ -4,7 +4,7 @@ use strict; > use warnings; > use Carp; > use CGI; >-use List::Util qw/first/; >+use List::MoreUtils qw/any/; > > # Copyright 2009 Chris Cormack and The Koha Dev Team > # >@@ -313,9 +313,9 @@ sub getlanguage { > my ($query, $interface) = @_; > > # Select a language based on cookie, syspref available languages & browser >- my $is_intranet = $interface eq 'intranet'; >- my @languages = split(",", C4::Context->preference( >- $is_intranet ? 'language' : 'opaclanguages')); >+ my $preference_to_check = >+ $interface eq 'intranet' ? 'language' : 'opaclanguages'; >+ my @languages = split /,/, C4::Context->preference($preference_to_check); > > my $lang; > >@@ -326,20 +326,18 @@ sub getlanguage { > } > > #Â HTTP_ACCEPT_LANGUAGE >- unless ($lang) { >- my $http_accept_language = $ENV{ HTTP_ACCEPT_LANGUAGE }; >- $lang = accept_language( $http_accept_language, >- getTranslatedLanguages($interface,'prog') ); >+ if ( !$lang && $ENV{HTTP_ACCEPT_LANGUAGE} ) { >+ $lang = accept_language( $ENV{HTTP_ACCEPT_LANGUAGE}, >+ getTranslatedLanguages( $interface, 'prog' ) ); > } > > # Ignore a lang not selected in sysprefs >- $lang = undef unless first { $_ eq $lang } @languages; >+ if ( $lang && any { $_ eq $lang } @languages ) { >+ return $lang; >+ } > > # Fall back to English if necessary >- $lang = 'en' unless $lang; >- >- return $lang; >+ return 'en'; > } > > 1; >- >-- >1.7.7.6 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7874
:
8775
|
8811