From 0d5c91241b7cd924e27224ff093cf4abb16df1e3 Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Sun, 9 Jun 2024 19:41:50 +0200 Subject: [PATCH] Fix language setting in installation wizard --- API/Pages/Panel/APIInstallWizard.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/API/Pages/Panel/APIInstallWizard.php b/API/Pages/Panel/APIInstallWizard.php index 059a09f..bb836e8 100644 --- a/API/Pages/Panel/APIInstallWizard.php +++ b/API/Pages/Panel/APIInstallWizard.php @@ -73,8 +73,11 @@ class APIInstallWizard extends BaculumAPIPage public function onPreInit($param) { parent::onPreInit($param); - if (isset($_SESSION['language'])) { - $this->Application->getGlobalization()->Culture = $_SESSION['language']; + $session = $this->Application->getSession(); + // Open new session if no session exists + $session->open(); + if ($session->contains('language')) { + $this->Application->getGlobalization()->Culture = $session->itemAt('language'); } } @@ -86,8 +89,9 @@ public function onInit($param) $this->first_run = (count($this->config) === 0); $oauth2_cfg = $this->getModule('oauth2_config')->getConfig(); $this->add_auth_params = (count($oauth2_cfg) === 0); - if (isset($_SESSION['language'])) { - $this->Lang->SelectedValue = $_SESSION['language']; + $session = $this->Application->getSession(); + if ($session->contains('language')) { + $this->Lang->SelectedValue = $session->itemAt('language'); } elseif (!$this->first_run && isset($this->config['api']['lang'])) { $this->Lang->SelectedValue = $this->config['api']['lang']; } @@ -233,8 +237,9 @@ public function wizardCompleted($sender, $param) } elseif ($this->AuthOAuth2->Checked) { $cfg_data['api']['auth_type'] = 'oauth2'; } + $session = $this->Application->getSession(); $cfg_data['api']['debug'] = $this->config['api']['debug'] ?? "0"; - $cfg_data['api']['lang'] = $_SESSION['language'] ?? APIConfig::DEF_LANG; + $cfg_data['api']['lang'] = $session->itemAt('language') ?? APIConfig::DEF_LANG; $cfg_data['db']['enabled'] = (int) ($this->DatabaseYes->Checked === true); $cfg_data['db']['type'] = $this->DBType->SelectedValue; $cfg_data['db']['name'] = $this->DBName->Text; @@ -480,7 +485,8 @@ public function setDBPath($db) public function setLang($sender, $param) { - $_SESSION['language'] = $sender->SelectedValue; + $session = $this->Application->getSession(); + $session->add('language', $sender->SelectedValue); } public function renderPanel($sender, $param)