mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
Make timezone configuration impossible to get wrong
Summary: Fixes T2269. If the user manages to mess up both the PHP and Phabricator configurations, set the timezone to UTC. We basically never use this anyway (we always render into the user's time), PHP just gets angry at us if we don't set it. (We do use it for logged-out users, I suppose.) Test Plan: Set PHP and Phabricator timezones to goofy nonsense, verified we recover sensibly from it. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T2228, T2269 Differential Revision: https://secure.phabricator.com/D4496
This commit is contained in:
parent
da9315b145
commit
d5c29e1135
3 changed files with 27 additions and 35 deletions
|
@ -3,6 +3,26 @@
|
|||
final class PhabricatorSetupCheckTimezone extends PhabricatorSetupCheck {
|
||||
|
||||
protected function executeChecks() {
|
||||
$php_value = ini_get('date.timezone');
|
||||
if ($php_value) {
|
||||
$old = date_default_timezone_get();
|
||||
$ok = @date_default_timezone_set($php_value);
|
||||
date_default_timezone_set($old);
|
||||
|
||||
if (!$ok) {
|
||||
$message = pht(
|
||||
'Your PHP configuration configuration selects an invalid timezone. '.
|
||||
'Select a valid timezone.');
|
||||
|
||||
$this
|
||||
->newIssue('php.date.timezone')
|
||||
->setShortName(pht('PHP Timezone'))
|
||||
->setName(pht('PHP Timezone Invalid'))
|
||||
->setMessage($message)
|
||||
->addPHPConfig('date.timezone');
|
||||
}
|
||||
}
|
||||
|
||||
$timezone = nonempty(
|
||||
PhabricatorEnv::getEnvConfig('phabricator.timezone'),
|
||||
ini_get('date.timezone'));
|
||||
|
|
|
@ -358,22 +358,6 @@ final class PhabricatorSetup {
|
|||
}
|
||||
}
|
||||
|
||||
$timezone = nonempty(
|
||||
PhabricatorEnv::getEnvConfig('phabricator.timezone'),
|
||||
ini_get('date.timezone'));
|
||||
if (!$timezone) {
|
||||
self::writeFailure();
|
||||
self::write(
|
||||
"Setup failure! Your configuration fails to specify a server ".
|
||||
"timezone. Either set 'date.timezone' in your php.ini or ".
|
||||
"'phabricator.timezone' in your Phabricator configuration. See the ".
|
||||
"PHP documentation for a list of supported timezones:\n\n".
|
||||
"http://www.php.net/manual/en/timezones.php\n");
|
||||
return;
|
||||
} else {
|
||||
self::write(" okay Timezone '{$timezone}' configured.\n");
|
||||
}
|
||||
|
||||
self::write("[OKAY] Basic configuration OKAY\n");
|
||||
|
||||
|
||||
|
@ -587,24 +571,6 @@ final class PhabricatorSetup {
|
|||
self::write(" skip Not configured for local disk storage.\n");
|
||||
}
|
||||
|
||||
$selector = PhabricatorEnv::getEnvConfig('storage.engine-selector');
|
||||
|
||||
try {
|
||||
$storage_selector_exists = class_exists($selector);
|
||||
} catch (Exception $ex) {
|
||||
$storage_selector_exists = false;
|
||||
}
|
||||
|
||||
if ($storage_selector_exists) {
|
||||
self::write(" okay Using '{$selector}' as a storage engine selector.\n");
|
||||
} else {
|
||||
self::writeFailure();
|
||||
self::write(
|
||||
"Setup failure! You have configured '{$selector}' as a storage engine ".
|
||||
"selector but it does not exist or could not be loaded.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
self::write("[OKAY] Database and storage configuration OKAY\n");
|
||||
|
||||
self::writeHeader('SUCCESS!');
|
||||
|
|
8
src/infrastructure/env/PhabricatorEnv.php
vendored
8
src/infrastructure/env/PhabricatorEnv.php
vendored
|
@ -107,9 +107,15 @@ final class PhabricatorEnv {
|
|||
|
||||
self::buildConfigurationSourceStack();
|
||||
|
||||
// Force a valid timezone. If both PHP and Phabricator configuration are
|
||||
// invalid, use UTC.
|
||||
$tz = PhabricatorEnv::getEnvConfig('phabricator.timezone');
|
||||
if ($tz) {
|
||||
date_default_timezone_set($tz);
|
||||
@date_default_timezone_set($tz);
|
||||
}
|
||||
$ok = @date_default_timezone_set(date_default_timezone_get());
|
||||
if (!$ok) {
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
// Append any paths to $PATH if we need to.
|
||||
|
|
Loading…
Reference in a new issue