static function initialize($request)
{
self::$request = $request;
// Use defaults if locale info unspecified.
$locale = AppLocale::getLocale();
$sysLocale = $locale . '.' . LOCALE_ENCODING;
if (!@setlocale(LC_ALL, $sysLocale, $locale)) {
// For PHP < 4.3.0
if (setlocale(LC_ALL, $sysLocale) != $sysLocale) {
setlocale(LC_ALL, $locale);
}
}
AppLocale::registerLocaleFile($locale, "lib/pkp/locale/{$locale}/common.xml");
// Set site time zone
// Starting from PHP 5.3.0 PHP will throw an E_WARNING if the default
// time zone is not set and date/time functions are used
// http://pl.php.net/manual/en/function.date-default-timezone-set.php
$timeZone = self::getTimeZone();
date_default_timezone_set($timeZone);
if (Config::getVar('general', 'installed')) {
// Set the time zone for DB
// Get the offset from UTC
$now = new DateTime();
$mins = $now->getOffset() / 60;
$sgn = $mins < 0 ? -1 : 1;
$mins = abs($mins);
$hrs = floor($mins / 60);
$mins -= $hrs * 60;
$offset = sprintf('%+d:%02d', $hrs * $sgn, $mins);
$conn = DBConnection::getInstance();
$dbconn =& $conn->getDBConn();
switch ($conn->getDriver()) {
case 'mysql':
case 'mysqli':
$dbconn->execute('SET time_zone = \'' . $offset . '\'');
break;
case 'postgres':
$dbconn->execute('SET TIME ZONE INTERVAL \'' . $offset . '\' HOUR TO MINUTE');
break;
default:
assert(false);
}
}
}