From d5c29e11351d178f01cb238d01d006d1195d1e03 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 19 Jan 2013 08:38:37 -0800 Subject: [PATCH] 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 --- .../check/PhabricatorSetupCheckTimezone.php | 20 +++++++++++ src/infrastructure/PhabricatorSetup.php | 34 ------------------- src/infrastructure/env/PhabricatorEnv.php | 8 ++++- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/applications/config/check/PhabricatorSetupCheckTimezone.php b/src/applications/config/check/PhabricatorSetupCheckTimezone.php index 834afb14b1..ebff55f6f6 100644 --- a/src/applications/config/check/PhabricatorSetupCheckTimezone.php +++ b/src/applications/config/check/PhabricatorSetupCheckTimezone.php @@ -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')); diff --git a/src/infrastructure/PhabricatorSetup.php b/src/infrastructure/PhabricatorSetup.php index 7e7edfef15..8645b9c729 100644 --- a/src/infrastructure/PhabricatorSetup.php +++ b/src/infrastructure/PhabricatorSetup.php @@ -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!'); diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index 79c6b40c49..627b70bcbc 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -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.