From c3a9b5138ed5a4410be522d803d51c0096661235 Mon Sep 17 00:00:00 2001 From: "s.samko" Date: Mon, 30 Sep 2024 15:09:37 +0100 Subject: [PATCH] Fix #10494 - Users save() method always sets the 'timezone' to 'UTC' --- install/install_utils.php | 18 +++++++++++++++++- modules/Users/User.php | 3 +-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/install/install_utils.php b/install/install_utils.php index db7d62ef68e..f0a75f73822 100755 --- a/install/install_utils.php +++ b/install/install_utils.php @@ -1320,6 +1320,10 @@ function create_default_users() $user->employee_status = 'Active'; $user->user_hash = User::getPasswordHash($setup_site_admin_password); + if (isTrue($_SESSION['cli'] ?? false)) { + setTimeZoneForDefaultAdmin($_SESSION['timezone'] ?? null, $user); + } + $GLOBALS['current_user'] = $user; $GLOBALS['current_user']->save(); @@ -1678,7 +1682,7 @@ function pullSilentInstallVarsIntoSession() 'default_currency_symbol', 'default_date_format', 'default_time_format', 'default_decimal_seperator', 'default_export_charset', 'default_language', 'default_locale_name_format', 'default_number_grouping_seperator', 'export_delimiter', 'cache_dir', 'setup_db_options', - 'setup_fts_type', 'setup_fts_host', 'setup_fts_port', 'setup_fts_index_settings'. 'setup_fts_transport'); + 'setup_fts_type', 'setup_fts_host', 'setup_fts_port', 'setup_fts_index_settings'. 'setup_fts_transport', 'timezone'); copyFromArray($sugar_config_si, $needles, $derived); $all_config_vars = array_merge($config_subset, $sugar_config_si, $derived); @@ -2318,3 +2322,15 @@ function enableInsideViewConnector() // $mapping is brought in from the mapping.php file above $source->saveMappingHook($mapping); } + +function setTimeZoneForDefaultAdmin(?string $timezone, SugarBean $user): void +{ + $preference = 'timezone'; + $timezones = TimeDate::getTimezoneList(); + + if ($timezone !== null && array_key_exists($timezone, $timezones)) { + $user->setPreference($preference, $timezone, 0, 'global'); + } else { + $user->setPreference($preference, 'UTC', 0, 'global'); + } +} diff --git a/modules/Users/User.php b/modules/Users/User.php index 851ced158eb..80e6a2107ad 100755 --- a/modules/Users/User.php +++ b/modules/Users/User.php @@ -846,9 +846,8 @@ public function saveFormPreferences() if (isset($_POST['timezone'])) { $this->setPreference('timezone', $_POST['timezone'], 0, 'global'); - } else { - $this->setPreference('timezone', 'UTC', 0, 'global'); } + if (isset($_POST['ut'])) { $this->setPreference('ut', '0', 0, 'global'); } else {