From 3d6150c9bda6f86aa3b9a193455fd229ca554cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Anne?= Date: Wed, 18 Dec 2024 14:48:37 +0100 Subject: [PATCH] Fix session defaults --- src/Glpi/Console/Application.php | 3 +++ src/Glpi/Kernel/Listener/SessionStart.php | 10 ---------- src/Session.php | 5 +++++ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Glpi/Console/Application.php b/src/Glpi/Console/Application.php index 73b02f6a88e..7091bf217a0 100644 --- a/src/Glpi/Console/Application.php +++ b/src/Glpi/Console/Application.php @@ -116,6 +116,9 @@ public function __construct(private Kernel $kernel) global $CFG_GLPI; $this->config = &$CFG_GLPI; + // Force the current "username" + $_SESSION['glpiname'] = 'cli'; + $this->computeAndLoadOutputLang(); // Load core commands only to check if called command prevent or not usage of plugins diff --git a/src/Glpi/Kernel/Listener/SessionStart.php b/src/Glpi/Kernel/Listener/SessionStart.php index 7ea8e58e5b8..09527e455b4 100644 --- a/src/Glpi/Kernel/Listener/SessionStart.php +++ b/src/Glpi/Kernel/Listener/SessionStart.php @@ -96,15 +96,5 @@ public function onPostBoot(): void Session::start(); } - - if (isCommandLine()) { - // Default value for use mode - $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE; - $_SESSION['glpiname'] = 'cli'; - } else { - // Initialize some session data before everything else so all layers can use it, even if session isn't started - $_SESSION['glpi_use_mode'] = null; - $_SESSION['glpilanguage'] = Session::getPreferredLanguage(); - } } } diff --git a/src/Session.php b/src/Session.php index 9241aab899a..0db48d8ad4a 100644 --- a/src/Session.php +++ b/src/Session.php @@ -267,6 +267,11 @@ public static function start() if (!isset($_SESSION['glpi_use_mode'])) { $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE; } + + // Define default language + if (!isset($_SESSION['glpilanguage'])) { + $_SESSION['glpilanguage'] = Session::getPreferredLanguage(); + } }