From 820c257e96721c30f99c99b8925774880548b6c4 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 2 May 2018 06:36:57 +0000 Subject: [PATCH] =?UTF-8?q?N=C2=B01427=20New=20method=20to=20fix=20timezon?= =?UTF-8?q?e=20where=20datamodel=20is=20not=20yet=20loaded?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SVN:trunk[5761] --- application/utils.inc.php | 36 +++++++++++++++++++++++++++++------- pages/exec.php | 3 +++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/application/utils.inc.php b/application/utils.inc.php index 45656f2cc..c096b59f6 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -658,27 +658,49 @@ class utils return str_replace($aSearch, $aReplacement, $sOldDateTimeFormat); } + /** + * @return \Config from the current environement, or if not existing from the production env, else new Config made from scratch + * @uses \MetaModel::GetConfig() don't forget to add the needed require_once(APPROOT.'core/metamodel.class.php'); + */ static public function GetConfig() { if (self::$oConfig == null) { self::$oConfig = MetaModel::GetConfig(); + if (self::$oConfig == null) { $sConfigFile = self::GetConfigFilePath(); - if (file_exists($sConfigFile)) + if (!file_exists($sConfigFile)) { - self::$oConfig = new Config($sConfigFile); - } - else - { - // When executing the setup, the config file may be still missing - self::$oConfig = new Config(); + $sConfigFile = self::GetConfigFilePath('production'); + if (!file_exists($sConfigFile)) + { + $sConfigFile = null; + } } + + self::$oConfig = new Config($sConfigFile); } } return self::$oConfig; } + + public static function InitTimeZone() { + $oConfig = self::GetConfig(); + $sItopTimeZone = $oConfig->Get('timezone'); + + if (!empty($sItopTimeZone)) + { + date_default_timezone_set($sItopTimeZone); + } + else + { + // Leave as is... up to the admin to set a value somewhere... + // see http://php.net/manual/en/datetime.configuration.php#ini.date.timezone + } + } + /** * Returns the absolute URL to the application root path * @return string The absolute URL to the application root, without the first slash diff --git a/pages/exec.php b/pages/exec.php index 6513eb25a..0ece3c4a6 100644 --- a/pages/exec.php +++ b/pages/exec.php @@ -36,6 +36,9 @@ require_once('../approot.inc.php'); // Needed to read the parameters (with sanitization) require_once(APPROOT.'application/utils.inc.php'); +require_once(APPROOT.'core/metamodel.class.php'); + +utils::InitTimeZone(); $sModule = utils::ReadParam('exec_module', ''); if ($sModule == '')