Fix timezone setup

The CLI must not try to use our web timezone detection thingy.

refs #6073
This commit is contained in:
Eric Lippmann 2014-11-13 17:07:36 +01:00
parent ac2ec83852
commit e3c70bec6d
2 changed files with 28 additions and 36 deletions

View File

@ -478,27 +478,31 @@ abstract class ApplicationBootstrap
}
/**
* Setup default timezone
* Detect the timezone
*
* @return self
* @throws ConfigurationError if the timezone in config.ini isn't valid
* @return null|string
*/
protected function setupTimezone()
protected function detectTimezone()
{
$detect = new TimezoneDetect();
return null;
}
if ($detect->success()) {
$default = $detect->getTimezoneName();
} else {
$default = @date_default_timezone_get();
/**
* Set up the timezone
*
* @return $this
*/
protected final function setupTimezone()
{
$timezone = $this->detectTimeZone();
if ($timezone === null || @date_default_timezone_set($timezone) === false) {
$timezone = @date_default_timezone_get();
if ($timezone === false) {
$timezone = 'UTC';
date_default_timezone_set($timezone);
}
}
if (! $default) {
$default = 'UTC';
}
$timeZoneString = $this->config->fromSection('global', 'timezone', $default);
date_default_timezone_set($timeZoneString);
DateTimeFactory::setConfig(array('timezone' => $timeZoneString));
DateTimeFactory::setConfig(array('timezone' => $timezone));
return $this;
}

View File

@ -291,31 +291,19 @@ class Web extends ApplicationBootstrap
}
/**
* Setup user timezone if set and valid, otherwise global default timezone
*
* @return self
* @see ApplicationBootstrap::setupTimezone
* (non-PHPDoc)
* @see ApplicationBootstrap::detectTimezone() For the method documentation.
*/
protected function setupTimezone()
protected function detectTimezone()
{
$auth = Manager::getInstance();
if ($auth->isAuthenticated() &&
($timezone = $auth->getUser()->getPreferences()->getValue('icingaweb', 'timezone')) !== null
if (! $auth->isAuthenticated()
|| ($timezone = $auth->getUser()->getPreferences()->getValue('icingaweb', 'timezone')) === null
) {
$userTimezone = $timezone;
} else {
$userTimezone = null;
$detect = new TimezoneDetect();
$timezone = $detect->getTimezoneName();
}
try {
DateTimeFactory::setConfig(array('timezone' => $userTimezone));
date_default_timezone_set($userTimezone);
} catch (ConfigurationError $e) {
return parent::setupTimezone();
}
return $this;
return $timezone;
}
/**