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 * @return null|string
* @throws ConfigurationError if the timezone in config.ini isn't valid
*/ */
protected function setupTimezone() protected function detectTimezone()
{ {
$detect = new TimezoneDetect(); return null;
}
if ($detect->success()) { /**
$default = $detect->getTimezoneName(); * Set up the timezone
} else { *
$default = @date_default_timezone_get(); * @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);
}
} }
DateTimeFactory::setConfig(array('timezone' => $timezone));
if (! $default) {
$default = 'UTC';
}
$timeZoneString = $this->config->fromSection('global', 'timezone', $default);
date_default_timezone_set($timeZoneString);
DateTimeFactory::setConfig(array('timezone' => $timeZoneString));
return $this; return $this;
} }

View File

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