Skip to content

Commit f2efdd0

Browse files
author
Jason Ge
committed
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
1 parent bb7e175 commit f2efdd0

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

scripts/sql/upgrade_schema.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@
5959
// Use always the version from the commandline if it is defined
6060
$next_version = isset($options['v']) ? (int)$options['v'] : null;
6161

62-
// TODO: Get this stuff from DatabaseConfigurationProvider?
62+
$conf = DatabaseConfigurationProvider::getConfiguration();
63+
6364
if ($options['u']) {
6465
$conn_user = $options['u'];
6566
$conn_pass = $options['p'];
6667
} else {
67-
$conn_user = PhabricatorEnv::getEnvConfig('mysql.user');
68-
$conn_pass = PhabricatorEnv::getEnvConfig('mysql.pass');
68+
$conn_user = $conf->getUser();
69+
$conn_pass = $conf->getPassword();
6970
}
70-
$conn_host = PhabricatorEnv::getEnvConfig('mysql.host');
71+
$conn_host = $conf->getHost();
7172

7273
// Split out port information, since the command-line client requires a
7374
// separate flag for the port.

src/applications/base/storage/configuration/DatabaseConfigurationProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@ final protected function getDao() {
4848
final protected function getMode() {
4949
return $this->mode;
5050
}
51+
52+
public static function getConfiguration() {
53+
// Get DB info. Note that we are using a dummy PhabricatorUser object in
54+
// creating the DatabaseConfigurationProvider, which is not used at all.
55+
$conf_provider = PhabricatorEnv::getEnvConfig(
56+
'mysql.configuration_provider', 'DatabaseConfigurationProvider');
57+
PhutilSymbolLoader::loadClass($conf_provider);
58+
$conf = newv($conf_provider, array(new PhabricatorUser(), 'r'));
59+
return $conf;
60+
}
61+
5162
}

src/applications/base/storage/configuration/__init__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77

88

9+
phutil_require_module('phabricator', 'applications/people/storage/user');
910
phutil_require_module('phabricator', 'infrastructure/env');
1011

12+
phutil_require_module('phutil', 'symbols');
13+
phutil_require_module('phutil', 'utils');
14+
1115

1216
phutil_require_source('DatabaseConfigurationProvider.php');

src/infrastructure/setup/PhabricatorSetup.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function runSetup() {
6868
} else {
6969
if (trim($stdout) == 'YES') {
7070
self::write(" okay pcntl is available from the command line.\n");
71-
self::write("[OKAY] All extensions OKAY\n\n");
71+
self::write("[OKAY] All extensions OKAY\n");
7272
} else {
7373
self::write(" warn pcntl is not available!\n");
7474
self::write("[WARN] *** WARNING *** pcntl extension not available. ".
@@ -120,7 +120,7 @@ public static function runSetup() {
120120
}
121121
}
122122
}
123-
self::write("[OKAY] All submodules OKAY.");
123+
self::write("[OKAY] All submodules OKAY.\n");
124124

125125
self::writeHeader("BASIC CONFIGURATION");
126126

@@ -241,9 +241,10 @@ public static function runSetup() {
241241

242242
self::writeHeader("MySQL DATABASE CONFIGURATION");
243243

244-
$conn_user = PhabricatorEnv::getEnvConfig('mysql.user');
245-
$conn_pass = PhabricatorEnv::getEnvConfig('mysql.pass');
246-
$conn_host = PhabricatorEnv::getEnvConfig('mysql.host');
244+
$conf = DatabaseConfigurationProvider::getConfiguration();
245+
$conn_user = $conf->getUser();
246+
$conn_pass = $conf->getPassword();
247+
$conn_host = $conf->getHost();
247248

248249
$timeout = ini_get('mysql.connect_timeout');
249250
if ($timeout > 5) {

src/infrastructure/setup/__init__.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @generated
55
*/
66

7+
8+
9+
phutil_require_module('phabricator', 'applications/base/storage/configuration');
710
phutil_require_module('phabricator', 'infrastructure/env');
811
phutil_require_module('phabricator', 'infrastructure/setup/sql');
912
phutil_require_module('phabricator', 'storage/connection/mysql');
@@ -15,4 +18,5 @@
1518
phutil_require_module('phutil', 'parser/uri');
1619
phutil_require_module('phutil', 'utils');
1720

18-
phutil_require_source('PhabricatorSetup.php');
21+
22+
phutil_require_source('PhabricatorSetup.php');

0 commit comments

Comments
 (0)