[icinga-checkins] icinga.org: icingaweb2/feature/localization-form-6073: Fix `setupTimezone' and `setupInternationalization' for user preferences

git at icinga.org git at icinga.org
Wed Nov 12 13:37:20 CET 2014


Module: icingaweb2
Branch: feature/localization-form-6073
Commit: 533d2207fdb0bc43f964bb5a95c94660c1e64c2e
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=533d2207fdb0bc43f964bb5a95c94660c1e64c2e

Author: Alexander Fuhr <alexander.fuhr at netways.de>
Date:   Wed Nov 12 12:16:05 2014 +0100

Fix `setupTimezone' and `setupInternationalization' for user preferences

---

 library/Icinga/Application/Web.php |   26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php
index 3c1835b..eda2372 100644
--- a/library/Icinga/Application/Web.php
+++ b/library/Icinga/Application/Web.php
@@ -7,6 +7,7 @@ namespace Icinga\Application;
 require_once __DIR__ . '/ApplicationBootstrap.php';
 
 use Icinga\Authentication\Manager as AuthenticationManager;
+use Icinga\Authentication\Manager;
 use Icinga\Exception\ConfigurationError;
 use Icinga\Exception\NotReadableError;
 use Icinga\Application\Logger;
@@ -296,8 +297,12 @@ class Web extends ApplicationBootstrap
      */
     protected function setupTimezone()
     {
-        if ($this->user !== null && $this->user->getPreferences() !== null) {
-            $userTimezone = $this->user->getPreferences()->get('app.timezone');
+        $auth = Manager::getInstance();
+
+        if ($auth->isAuthenticated() &&
+            ($timezone = $auth->getUser()->getPreferences()->getValue('icingaweb', 'timezone')) !== null
+        ) {
+            $userTimezone = $timezone;
         } else {
             $userTimezone = null;
         }
@@ -323,21 +328,10 @@ class Web extends ApplicationBootstrap
     {
         parent::setupInternationalization();
 
-        $locale = Session::getSession()->get('language');
-        if ($locale !== null) {
-            try {
-                Translator::setupLocale($locale);
-            } catch (Exception $e) {
-                Logger::debug(
-                    'Cannot set locale "' . $locale . '" configured in session' .
-                    ' "' . session_id() . '" (' . $e->getMessage() . ')'
-                );
-                $locale = null;
-            }
-        }
+        $auth = Manager::getInstance();
 
-        if ($locale === null && $this->user !== null && $this->user->getPreferences() !== null
-            && (($locale = $this->user->getPreferences()->getValue('icingaweb', 'language')) !== null)
+        if ($auth->isAuthenticated() &&
+            ($locale = $auth->getUser()->getPreferences()->getValue('icingaweb', 'language')) !== null
         ) {
             try {
                 Translator::setupLocale($locale);



More information about the icinga-checkins mailing list