N°1427 New method to fix timezone where datamodel is not yet loaded

SVN:trunk[5761]
This commit is contained in:
Pierre Goiffon
2018-05-02 06:36:57 +00:00
parent 56e5616080
commit 820c257e96
2 changed files with 32 additions and 7 deletions

View File

@@ -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 <code>require_once(APPROOT.'core/metamodel.class.php');</code>
*/
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

View File

@@ -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 == '')