From f2efdd07a7784d08a19d6186fd5ee3f041897a69 Mon Sep 17 00:00:00 2001 From: Jason Ge Date: Sat, 11 Jun 2011 15:11:50 -0700 Subject: [PATCH] Use DatabaseConfigurationProvider to get DB info Summary: remove accessing the db config info directly. Use DatabaseConfigurationProvider instead. Also fixed a minor issue where different number of newlines are output in PhabricatorSetup.php's output. Test Plan: executed upgrade_schema.php; executed PhabricatorSetup.php by setting 'phabricator.setup' to true. Reviewed By: epriestley Reviewers: epriestley CC: aran, jungejason, epriestley Differential Revision: 443 --- scripts/sql/upgrade_schema.php | 9 +++++---- .../configuration/DatabaseConfigurationProvider.php | 11 +++++++++++ .../base/storage/configuration/__init__.php | 4 ++++ src/infrastructure/setup/PhabricatorSetup.php | 11 ++++++----- src/infrastructure/setup/__init__.php | 6 +++++- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/scripts/sql/upgrade_schema.php b/scripts/sql/upgrade_schema.php index f7a718f575..10d0159885 100755 --- a/scripts/sql/upgrade_schema.php +++ b/scripts/sql/upgrade_schema.php @@ -59,15 +59,16 @@ if (empty($options['f'])) { // Use always the version from the commandline if it is defined $next_version = isset($options['v']) ? (int)$options['v'] : null; -// TODO: Get this stuff from DatabaseConfigurationProvider? +$conf = DatabaseConfigurationProvider::getConfiguration(); + if ($options['u']) { $conn_user = $options['u']; $conn_pass = $options['p']; } else { - $conn_user = PhabricatorEnv::getEnvConfig('mysql.user'); - $conn_pass = PhabricatorEnv::getEnvConfig('mysql.pass'); + $conn_user = $conf->getUser(); + $conn_pass = $conf->getPassword(); } -$conn_host = PhabricatorEnv::getEnvConfig('mysql.host'); +$conn_host = $conf->getHost(); // Split out port information, since the command-line client requires a // separate flag for the port. diff --git a/src/applications/base/storage/configuration/DatabaseConfigurationProvider.php b/src/applications/base/storage/configuration/DatabaseConfigurationProvider.php index 6ec9771dd9..cdc9652890 100644 --- a/src/applications/base/storage/configuration/DatabaseConfigurationProvider.php +++ b/src/applications/base/storage/configuration/DatabaseConfigurationProvider.php @@ -48,4 +48,15 @@ class DatabaseConfigurationProvider { final protected function getMode() { return $this->mode; } + + public static function getConfiguration() { + // Get DB info. Note that we are using a dummy PhabricatorUser object in + // creating the DatabaseConfigurationProvider, which is not used at all. + $conf_provider = PhabricatorEnv::getEnvConfig( + 'mysql.configuration_provider', 'DatabaseConfigurationProvider'); + PhutilSymbolLoader::loadClass($conf_provider); + $conf = newv($conf_provider, array(new PhabricatorUser(), 'r')); + return $conf; + } + } diff --git a/src/applications/base/storage/configuration/__init__.php b/src/applications/base/storage/configuration/__init__.php index bf6cd309d0..5aa96d158c 100644 --- a/src/applications/base/storage/configuration/__init__.php +++ b/src/applications/base/storage/configuration/__init__.php @@ -6,7 +6,11 @@ +phutil_require_module('phabricator', 'applications/people/storage/user'); phutil_require_module('phabricator', 'infrastructure/env'); +phutil_require_module('phutil', 'symbols'); +phutil_require_module('phutil', 'utils'); + phutil_require_source('DatabaseConfigurationProvider.php'); diff --git a/src/infrastructure/setup/PhabricatorSetup.php b/src/infrastructure/setup/PhabricatorSetup.php index ff4e559b79..c8f97b47e3 100644 --- a/src/infrastructure/setup/PhabricatorSetup.php +++ b/src/infrastructure/setup/PhabricatorSetup.php @@ -68,7 +68,7 @@ class PhabricatorSetup { } else { if (trim($stdout) == 'YES') { self::write(" okay pcntl is available from the command line.\n"); - self::write("[OKAY] All extensions OKAY\n\n"); + self::write("[OKAY] All extensions OKAY\n"); } else { self::write(" warn pcntl is not available!\n"); self::write("[WARN] *** WARNING *** pcntl extension not available. ". @@ -120,7 +120,7 @@ class PhabricatorSetup { } } } - self::write("[OKAY] All submodules OKAY."); + self::write("[OKAY] All submodules OKAY.\n"); self::writeHeader("BASIC CONFIGURATION"); @@ -241,9 +241,10 @@ class PhabricatorSetup { self::writeHeader("MySQL DATABASE CONFIGURATION"); - $conn_user = PhabricatorEnv::getEnvConfig('mysql.user'); - $conn_pass = PhabricatorEnv::getEnvConfig('mysql.pass'); - $conn_host = PhabricatorEnv::getEnvConfig('mysql.host'); + $conf = DatabaseConfigurationProvider::getConfiguration(); + $conn_user = $conf->getUser(); + $conn_pass = $conf->getPassword(); + $conn_host = $conf->getHost(); $timeout = ini_get('mysql.connect_timeout'); if ($timeout > 5) { diff --git a/src/infrastructure/setup/__init__.php b/src/infrastructure/setup/__init__.php index b2b41afd60..61104d7777 100644 --- a/src/infrastructure/setup/__init__.php +++ b/src/infrastructure/setup/__init__.php @@ -4,6 +4,9 @@ * @generated */ + + +phutil_require_module('phabricator', 'applications/base/storage/configuration'); phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'infrastructure/setup/sql'); phutil_require_module('phabricator', 'storage/connection/mysql'); @@ -15,4 +18,5 @@ phutil_require_module('phutil', 'moduleutils'); phutil_require_module('phutil', 'parser/uri'); phutil_require_module('phutil', 'utils'); -phutil_require_source('PhabricatorSetup.php'); \ No newline at end of file + +phutil_require_source('PhabricatorSetup.php');