forked from extern/egroupware
* Api: setting configured server-timezone for the databases connection, to fix cases were they do not match
This commit is contained in:
parent
5288e3a0fd
commit
496c168db4
@ -1155,6 +1155,35 @@ class Db
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set session timezone, to get automatic timestamps to be in our configured timezone
|
||||
*
|
||||
* @param string $timezone
|
||||
* @return ?boolean
|
||||
*/
|
||||
public function setTimeZone($timezone)
|
||||
{
|
||||
if (!$this->Link_ID && !$this->connect())
|
||||
{
|
||||
return False;
|
||||
}
|
||||
switch ($this->Type)
|
||||
{
|
||||
case 'pgsql':
|
||||
$sql = 'SET TIME ZONE ' . $this->quote($timezone);
|
||||
break;
|
||||
case 'mysql':
|
||||
case 'mysqli':
|
||||
$sql = 'SET time_zone=' . $this->quote($timezone);
|
||||
break;
|
||||
}
|
||||
if (!empty($timezone) && !empty($sql))
|
||||
{
|
||||
$this->Link_ID->Execute($sql);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* concat a variable number of strings together, to be used in a query
|
||||
*
|
||||
|
@ -122,7 +122,7 @@ class Egw extends Egw\Base
|
||||
// Set the DB's client charset if a system-charset is set and some other values needed by egw_cache (used in Config::read)
|
||||
foreach($this->db->select(Config::TABLE,'config_name,config_value',array(
|
||||
'config_app' => 'phpgwapi',
|
||||
'config_name' => array('system_charset','install_id','temp_dir'),
|
||||
'config_name' => array('system_charset','install_id','temp_dir','server_timezone'),
|
||||
),__LINE__,__FILE__) as $row)
|
||||
{
|
||||
$GLOBALS['egw_info']['server'][$row['config_name']] = $row['config_value'];
|
||||
@ -131,6 +131,8 @@ class Egw extends Egw\Base
|
||||
{
|
||||
$this->db->Link_ID->SetCharSet($GLOBALS['egw_info']['server']['system_charset']);
|
||||
}
|
||||
$this->db->SetTimeZone($GLOBALS['egw_info']['server']['server_timezone']);
|
||||
|
||||
// load up the $GLOBALS['egw_info']['server'] array
|
||||
$GLOBALS['egw_info']['server'] += Config::read('phpgwapi');
|
||||
|
||||
@ -233,6 +235,7 @@ class Egw extends Egw\Base
|
||||
if (!empty($GLOBALS['egw_info']['server']['server_timezone']))
|
||||
{
|
||||
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
||||
$this->db->SetTimeZone($GLOBALS['egw_info']['server']['server_timezone']);
|
||||
}
|
||||
|
||||
$this->define_egw_constants();
|
||||
|
Loading…
Reference in New Issue
Block a user