viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

Make Yioop User language preference reflect in db storred session, a=chris

Chris Pollett [2020-08-10 04:Aug:th]
Make Yioop User language preference reflect in db storred session, a=chris
Filename
src/controllers/components/AccountaccessComponent.php
diff --git a/src/controllers/components/AccountaccessComponent.php b/src/controllers/components/AccountaccessComponent.php
index 082c5c755..d244554d4 100644
--- a/src/controllers/components/AccountaccessComponent.php
+++ b/src/controllers/components/AccountaccessComponent.php
@@ -67,6 +67,7 @@ class AccountaccessComponent extends Component
         $data["ELEMENT"] = "manageaccount";
         $data['SCRIPT'] = "";
         $data['MESSAGE'] = "";
+        $changed_settings_flag = false;
         $data['yioop_bot_configuration'] = $profile['CONFIGURE_BOT'];
         if ($profile['CONFIGURE_BOT'] == 'enable_bot_users') {
             $data['yioop_bot_configuration'] = true;
@@ -114,8 +115,8 @@ class AccountaccessComponent extends Component
             }
         }
         if (!empty($data['EDIT_USER'])) {
+            $user_session = $user_model->getUserSession($user_id);
             if (C\RECOVERY_MODE == C\EMAIL_AND_QUESTIONS_RECOVERY) {
-                $user_session = $user_model->getUserSession($user_id);
                 if (!isset($user_session['RECOVERY']) &&
                     !isset($_SESSION['RECOVERY'])) {
                     $data['RECOVERY'] = $this->makeRecoveryQuestions();
@@ -151,7 +152,7 @@ class AccountaccessComponent extends Component
                 }
                 if ($recovery_answer_change) {
                     $user_session['RECOVERY'] = $data['RECOVERY'];
-                    $user_model->setUserSession($user_id, $user_session);
+                    $changed_settings_flag = true;
                 }
             }
         }
@@ -213,8 +214,10 @@ class AccountaccessComponent extends Component
                 $_SESSION['l'] : L\getLocaleTag();
             $_SESSION['l'] = $_REQUEST['lang'];
             L\setLocaleObject($_SESSION['l']);
-            if ($old_value != $_SESSION['l']) {
+            if ($old_value != $_SESSION['l'] || empty($user_session['l'])
+                || $user_session['l'] != $_SESSION['l']) {
                 $changed_settings_flag = true;
+                $user_session['l'] = $_SESSION['l'];
             }
         }
         $data['LANGUAGES_TO_SHOW'] = 1;
@@ -312,6 +315,9 @@ class AccountaccessComponent extends Component
                     }
                 }
                 $user_model->updateUser($user);
+                if ($changed_settings_flag) {
+                    $user_model->setUserSession($user_id, $user_session);
+                }
                 if ($is_bot_updated) {
                     $user_model->updateBot($user);
                 }
ViewGit