mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +01:00
(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
This commit is contained in:
parent
a1338bd2d8
commit
32a580c720
7 changed files with 62 additions and 30 deletions
|
@ -1,24 +1,3 @@
|
|||
<?php
|
||||
|
||||
function init_phabricator_script() {
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$include_path = ini_get('include_path');
|
||||
ini_set(
|
||||
'include_path',
|
||||
$include_path.PATH_SEPARATOR.dirname(__FILE__).'/../../');
|
||||
@include_once 'libphutil/scripts/__init_script__.php';
|
||||
if (!@constant('__LIBPHUTIL__')) {
|
||||
echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to ".
|
||||
"include the parent directory of libphutil/.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
phutil_load_library('arcanist/src');
|
||||
phutil_load_library(dirname(__FILE__).'/../src/');
|
||||
|
||||
PhabricatorEnv::initializeScriptEnvironment();
|
||||
}
|
||||
|
||||
init_phabricator_script();
|
||||
require_once dirname(__FILE__).'/init/init-script.php';
|
||||
|
|
10
scripts/init/init-script.php
Normal file
10
scripts/init/init-script.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
// Initialize a standard script.
|
||||
|
||||
require_once dirname(__FILE__).'/lib.php';
|
||||
|
||||
init_phabricator_script(
|
||||
array(
|
||||
'config.optional' => false,
|
||||
));
|
12
scripts/init/init-setup.php
Normal file
12
scripts/init/init-setup.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
// Initialize a setup script which may run before database connections have
|
||||
// been configured. Scripts initialized in this way ignore database errors
|
||||
// while building database configuration and continue.
|
||||
|
||||
require_once dirname(__FILE__).'/lib.php';
|
||||
|
||||
init_phabricator_script(
|
||||
array(
|
||||
'config.optional' => true,
|
||||
));
|
23
scripts/init/lib.php
Normal file
23
scripts/init/lib.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
function init_phabricator_script(array $options) {
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$include_path = ini_get('include_path');
|
||||
ini_set(
|
||||
'include_path',
|
||||
$include_path.PATH_SEPARATOR.dirname(__FILE__).'/../../../');
|
||||
@include_once 'libphutil/scripts/__init_script__.php';
|
||||
if (!@constant('__LIBPHUTIL__')) {
|
||||
echo "ERROR: Unable to load libphutil. Update your PHP 'include_path' to ".
|
||||
"include the parent directory of libphutil/.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
phutil_load_library('arcanist/src');
|
||||
phutil_load_library(dirname(__FILE__).'/../../src/');
|
||||
|
||||
$config_optional = $options['config.optional'];
|
||||
PhabricatorEnv::initializeScriptEnvironment($config_optional);
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
<?php
|
||||
|
||||
$root = dirname(dirname(dirname(__FILE__)));
|
||||
require_once $root.'/scripts/__init_script__.php';
|
||||
require_once $root.'/scripts/init/init-setup.php';
|
||||
|
||||
$args = new PhutilArgumentParser($argv);
|
||||
$args->setTagline(pht('manage configuration'));
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<?php
|
||||
|
||||
$root = dirname(dirname(dirname(__FILE__)));
|
||||
require_once $root.'/scripts/__init_script__.php';
|
||||
require_once $root.'/scripts/init/init-setup.php';
|
||||
|
||||
$args = new PhutilArgumentParser($argv);
|
||||
$args->setTagline(pht('manage Phabricator storage and schemata'));
|
||||
|
|
20
src/infrastructure/env/PhabricatorEnv.php
vendored
20
src/infrastructure/env/PhabricatorEnv.php
vendored
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue