From 32a580c720e31b0e4d7c5e8846870e8ce9fe3978 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 6 Sep 2016 13:20:31 -0700 Subject: [PATCH] (stable) Continue on bad database configuration from select scripts Summary: Ref T11589. Provide a way for scripts to say "just continue if database config fails", and use it in `bin/config` and `bin/storage`. Test Plan: - Broke database config. - Ran `bin/config`, worked fine. - Ran `bin/storage`, got helpful "set up the database" message. - Ran `bin/repository`, got fatal. - Ran normal site with valid/invalid config, got proper feedback. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11589 Differential Revision: https://secure.phabricator.com/D16502 --- scripts/__init_script__.php | 23 +---------------------- scripts/init/init-script.php | 10 ++++++++++ scripts/init/init-setup.php | 12 ++++++++++++ scripts/init/lib.php | 23 +++++++++++++++++++++++ scripts/setup/manage_config.php | 2 +- scripts/sql/manage_storage.php | 2 +- src/infrastructure/env/PhabricatorEnv.php | 20 ++++++++++++++------ 7 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 scripts/init/init-script.php create mode 100644 scripts/init/init-setup.php create mode 100644 scripts/init/lib.php diff --git a/scripts/__init_script__.php b/scripts/__init_script__.php index 57ada96e64..b807ae68a4 100644 --- a/scripts/__init_script__.php +++ b/scripts/__init_script__.php @@ -1,24 +1,3 @@ false, + )); diff --git a/scripts/init/init-setup.php b/scripts/init/init-setup.php new file mode 100644 index 0000000000..fea975830d --- /dev/null +++ b/scripts/init/init-setup.php @@ -0,0 +1,12 @@ + true, + )); diff --git a/scripts/init/lib.php b/scripts/init/lib.php new file mode 100644 index 0000000000..431d2c1373 --- /dev/null +++ b/scripts/init/lib.php @@ -0,0 +1,23 @@ +setTagline(pht('manage configuration')); diff --git a/scripts/sql/manage_storage.php b/scripts/sql/manage_storage.php index 7ad94277f7..2ba1e9920c 100755 --- a/scripts/sql/manage_storage.php +++ b/scripts/sql/manage_storage.php @@ -2,7 +2,7 @@ setTagline(pht('manage Phabricator storage and schemata')); diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index 221d553d2b..7ea00957ff 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -68,11 +68,11 @@ final class PhabricatorEnv extends Phobject { * @phutil-external-symbol class PhabricatorStartup */ public static function initializeWebEnvironment() { - self::initializeCommonEnvironment(); + self::initializeCommonEnvironment(false); } - public static function initializeScriptEnvironment() { - self::initializeCommonEnvironment(); + public static function initializeScriptEnvironment($config_optional) { + self::initializeCommonEnvironment($config_optional); // NOTE: This is dangerous in general, but we know we're in a script context // and are not vulnerable to CSRF. @@ -88,11 +88,11 @@ final class PhabricatorEnv extends Phobject { } - private static function initializeCommonEnvironment() { + private static function initializeCommonEnvironment($config_optional) { PhutilErrorHandler::initialize(); self::resetUmask(); - self::buildConfigurationSourceStack(); + self::buildConfigurationSourceStack($config_optional); // Force a valid timezone. If both PHP and Phabricator configuration are // invalid, use UTC. @@ -174,7 +174,7 @@ final class PhabricatorEnv extends Phobject { } } - private static function buildConfigurationSourceStack() { + private static function buildConfigurationSourceStack($config_optional) { self::dropConfigCache(); $stack = new PhabricatorConfigStackSource(); @@ -235,6 +235,14 @@ final class PhabricatorEnv extends Phobject { // If the database is not available, just skip this configuration // source. This happens during `bin/storage upgrade`, `bin/conf` before // schema setup, etc. + } catch (AphrontConnectionQueryException $ex) { + if (!$config_optional) { + throw $ex; + } + } catch (AphrontInvalidCredentialsQueryException $ex) { + if (!$config_optional) { + throw $ex; + } } }