@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+62 -30
+1 -22
scripts/__init_script__.php
··· 1 1 <?php 2 2 3 - function init_phabricator_script() { 4 - error_reporting(E_ALL | E_STRICT); 5 - ini_set('display_errors', 1); 6 - 7 - $include_path = ini_get('include_path'); 8 - ini_set( 9 - 'include_path', 10 - $include_path.PATH_SEPARATOR.dirname(__FILE__).'/../../'); 11 - @include_once 'libphutil/scripts/__init_script__.php'; 12 - if (!@constant('__LIBPHUTIL__')) { 13 - echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to ". 14 - "include the parent directory of libphutil/.\n"; 15 - exit(1); 16 - } 17 - 18 - phutil_load_library('arcanist/src'); 19 - phutil_load_library(dirname(__FILE__).'/../src/'); 20 - 21 - PhabricatorEnv::initializeScriptEnvironment(); 22 - } 23 - 24 - init_phabricator_script(); 3 + require_once dirname(__FILE__).'/init/init-script.php';
+10
scripts/init/init-script.php
··· 1 + <?php 2 + 3 + // Initialize a standard script. 4 + 5 + require_once dirname(__FILE__).'/lib.php'; 6 + 7 + init_phabricator_script( 8 + array( 9 + 'config.optional' => false, 10 + ));
+12
scripts/init/init-setup.php
··· 1 + <?php 2 + 3 + // Initialize a setup script which may run before database connections have 4 + // been configured. Scripts initialized in this way ignore database errors 5 + // while building database configuration and continue. 6 + 7 + require_once dirname(__FILE__).'/lib.php'; 8 + 9 + init_phabricator_script( 10 + array( 11 + 'config.optional' => true, 12 + ));
+23
scripts/init/lib.php
··· 1 + <?php 2 + 3 + function init_phabricator_script(array $options) { 4 + error_reporting(E_ALL | E_STRICT); 5 + ini_set('display_errors', 1); 6 + 7 + $include_path = ini_get('include_path'); 8 + ini_set( 9 + 'include_path', 10 + $include_path.PATH_SEPARATOR.dirname(__FILE__).'/../../../'); 11 + @include_once 'libphutil/scripts/__init_script__.php'; 12 + if (!@constant('__LIBPHUTIL__')) { 13 + echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to ". 14 + "include the parent directory of libphutil/.\n"; 15 + exit(1); 16 + } 17 + 18 + phutil_load_library('arcanist/src'); 19 + phutil_load_library(dirname(__FILE__).'/../../src/'); 20 + 21 + $config_optional = $options['config.optional']; 22 + PhabricatorEnv::initializeScriptEnvironment($config_optional); 23 + }
+1 -1
scripts/setup/manage_config.php
··· 2 2 <?php 3 3 4 4 $root = dirname(dirname(dirname(__FILE__))); 5 - require_once $root.'/scripts/__init_script__.php'; 5 + require_once $root.'/scripts/init/init-setup.php'; 6 6 7 7 $args = new PhutilArgumentParser($argv); 8 8 $args->setTagline(pht('manage configuration'));
+1 -1
scripts/sql/manage_storage.php
··· 2 2 <?php 3 3 4 4 $root = dirname(dirname(dirname(__FILE__))); 5 - require_once $root.'/scripts/__init_script__.php'; 5 + require_once $root.'/scripts/init/init-setup.php'; 6 6 7 7 $args = new PhutilArgumentParser($argv); 8 8 $args->setTagline(pht('manage Phabricator storage and schemata'));
+14 -6
src/infrastructure/env/PhabricatorEnv.php
··· 68 68 * @phutil-external-symbol class PhabricatorStartup 69 69 */ 70 70 public static function initializeWebEnvironment() { 71 - self::initializeCommonEnvironment(); 71 + self::initializeCommonEnvironment(false); 72 72 } 73 73 74 - public static function initializeScriptEnvironment() { 75 - self::initializeCommonEnvironment(); 74 + public static function initializeScriptEnvironment($config_optional) { 75 + self::initializeCommonEnvironment($config_optional); 76 76 77 77 // NOTE: This is dangerous in general, but we know we're in a script context 78 78 // and are not vulnerable to CSRF. ··· 88 88 } 89 89 90 90 91 - private static function initializeCommonEnvironment() { 91 + private static function initializeCommonEnvironment($config_optional) { 92 92 PhutilErrorHandler::initialize(); 93 93 94 94 self::resetUmask(); 95 - self::buildConfigurationSourceStack(); 95 + self::buildConfigurationSourceStack($config_optional); 96 96 97 97 // Force a valid timezone. If both PHP and Phabricator configuration are 98 98 // invalid, use UTC. ··· 174 174 } 175 175 } 176 176 177 - private static function buildConfigurationSourceStack() { 177 + private static function buildConfigurationSourceStack($config_optional) { 178 178 self::dropConfigCache(); 179 179 180 180 $stack = new PhabricatorConfigStackSource(); ··· 235 235 // If the database is not available, just skip this configuration 236 236 // source. This happens during `bin/storage upgrade`, `bin/conf` before 237 237 // schema setup, etc. 238 + } catch (AphrontConnectionQueryException $ex) { 239 + if (!$config_optional) { 240 + throw $ex; 241 + } 242 + } catch (AphrontInvalidCredentialsQueryException $ex) { 243 + if (!$config_optional) { 244 + throw $ex; 245 + } 238 246 } 239 247 } 240 248