mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
DbConnection: Set current user's timezone on the connection
resolves #3525
This commit is contained in:
parent
ed23d12c4f
commit
14b6e40562
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
namespace Icinga\Data\Db;
|
namespace Icinga\Data\Db;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use DateTimeZone;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Icinga\Data\Inspectable;
|
use Icinga\Data\Inspectable;
|
||||||
use Icinga\Data\Inspection;
|
use Icinga\Data\Inspection;
|
||||||
@ -205,6 +207,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
|||||||
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', NAMES ' . $adapterParamaters['charset'];
|
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', NAMES ' . $adapterParamaters['charset'];
|
||||||
unset($adapterParamaters['charset']);
|
unset($adapterParamaters['charset']);
|
||||||
}
|
}
|
||||||
|
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', time_zone=\'' . $this->getTimezoneOffset() . '\'';
|
||||||
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .=';';
|
$driverOptions[PDO::MYSQL_ATTR_INIT_COMMAND] .=';';
|
||||||
$defaultPort = 3306;
|
$defaultPort = 3306;
|
||||||
break;
|
break;
|
||||||
@ -287,6 +290,22 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get offset from the current default timezone to GMT
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTimezoneOffset()
|
||||||
|
{
|
||||||
|
$tz = new DateTimeZone(date_default_timezone_get());
|
||||||
|
$offset = $tz->getOffset(new DateTime());
|
||||||
|
$prefix = $offset >= 0 ? '+' : '-';
|
||||||
|
$offset = abs($offset);
|
||||||
|
$hours = (int) floor($offset / 3600);
|
||||||
|
$minutes = (int) floor(($offset % 3600) / 60);
|
||||||
|
return sprintf('%s%d:%02d', $prefix, $hours, $minutes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count all rows of the result set
|
* Count all rows of the result set
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user