Skip to content

Commit 2c8e6f9

Browse files
author
vrana
committed
Standardize mysql.configuration-provider
Summary: NOTE: BC break! Test Plan: / Reviewers: epriestley Reviewed By: epriestley CC: aran, nh Differential Revision: https://secure.phabricator.com/D2130
1 parent 6c1e2cd commit 2c8e6f9

File tree

13 files changed

+73
-44
lines changed

13 files changed

+73
-44
lines changed

conf/default.conf.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@
106106

107107
// -- MySQL --------------------------------------------------------------- //
108108

109+
// Class providing database configuration. It must implement
110+
// DatabaseConfigurationProvider.
111+
'mysql.configuration-provider' => 'DefaultDatabaseConfigurationProvider',
112+
109113
// The username to use when connecting to MySQL.
110114
'mysql.user' => 'root',
111115

scripts/sql/upgrade_schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
$next_version = isset($options['v']) ? (int)$options['v'] : null;
6262
$max_version = isset($options['m']) ? (int)$options['m'] : null;
6363

64-
$conf = DatabaseConfigurationProvider::getConfiguration();
64+
$conf = PhabricatorEnv::newObjectFromConfig('mysql.configuration-provider');
6565

6666
if ($options['u']) {
6767
$conn_user = $options['u'];

src/__phutil_library_map__.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@
190190
'DarkConsoleServicesPlugin' => 'aphront/console/plugin/services',
191191
'DarkConsoleXHProfPlugin' => 'aphront/console/plugin/xhprof',
192192
'DarkConsoleXHProfPluginAPI' => 'aphront/console/plugin/xhprof/api',
193-
'DatabaseConfigurationProvider' => 'applications/base/storage/configuration',
193+
'DatabaseConfigurationProvider' => 'applications/base/storage/configuration/base',
194+
'DefaultDatabaseConfigurationProvider' => 'applications/base/storage/configuration/default',
194195
'DifferentialAction' => 'applications/differential/constants/action',
195196
'DifferentialActionHasNoEffectException' => 'applications/differential/exception/noeffect',
196197
'DifferentialAddCommentView' => 'applications/differential/view/addcomment',
@@ -1134,6 +1135,7 @@
11341135
'DarkConsoleRequestPlugin' => 'DarkConsolePlugin',
11351136
'DarkConsoleServicesPlugin' => 'DarkConsolePlugin',
11361137
'DarkConsoleXHProfPlugin' => 'DarkConsolePlugin',
1138+
'DefaultDatabaseConfigurationProvider' => 'DatabaseConfigurationProvider',
11371139
'DifferentialActionHasNoEffectException' => 'DifferentialException',
11381140
'DifferentialAddCommentView' => 'AphrontView',
11391141
'DifferentialAffectedPath' => 'DifferentialDAO',

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

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2012 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* @stable
21+
*/
22+
interface DatabaseConfigurationProvider {
23+
24+
public function __construct(LiskDAO $dao = null, $mode = 'r');
25+
public function getUser();
26+
public function getPassword();
27+
public function getHost();
28+
public function getDatabase();
29+
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
10+
phutil_require_source('DatabaseConfigurationProvider.php');

src/applications/base/storage/configuration/DatabaseConfigurationProvider.php renamed to src/applications/base/storage/configuration/default/DefaultDatabaseConfigurationProvider.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
* limitations under the License.
1717
*/
1818

19-
/**
20-
* TODO: Can we final this?
21-
*/
22-
class DatabaseConfigurationProvider {
19+
final class DefaultDatabaseConfigurationProvider
20+
implements DatabaseConfigurationProvider {
21+
2322
private $dao;
2423
private $mode;
2524

26-
public function __construct(LiskDAO $dao, $mode) {
25+
public function __construct(LiskDAO $dao = null, $mode = 'r') {
2726
$this->dao = $dao;
2827
$this->mode = $mode;
2928
}
@@ -41,25 +40,14 @@ public function getHost() {
4140
}
4241

4342
public function getDatabase() {
43+
if (!$this->getDao()) {
44+
return null;
45+
}
4446
return 'phabricator_'.$this->getDao()->getApplicationName();
4547
}
4648

4749
final protected function getDao() {
4850
return $this->dao;
4951
}
5052

51-
final protected function getMode() {
52-
return $this->mode;
53-
}
54-
55-
public static function getConfiguration() {
56-
// Get DB info. Note that we are using a dummy PhabricatorUser object in
57-
// creating the DatabaseConfigurationProvider, which is not used at all.
58-
$conf_provider = PhabricatorEnv::getEnvConfig(
59-
'mysql.configuration_provider', 'DatabaseConfigurationProvider');
60-
PhutilSymbolLoader::loadClass($conf_provider);
61-
$conf = newv($conf_provider, array(new PhabricatorUser(), 'r'));
62-
return $conf;
63-
}
64-
6553
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/base/storage/configuration/base');
10+
phutil_require_module('phabricator', 'infrastructure/env');
11+
12+
13+
phutil_require_source('DefaultDatabaseConfigurationProvider.php');

src/applications/base/storage/lisk/PhabricatorLiskDAO.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ public function getEdgePHIDs($type) {
6666
* @task config
6767
*/
6868
public function establishLiveConnection($mode) {
69-
$conf_provider = PhabricatorEnv::getEnvConfig(
70-
'mysql.configuration_provider', 'DatabaseConfigurationProvider');
71-
PhutilSymbolLoader::loadClass($conf_provider);
72-
$conf = newv($conf_provider, array($this, $mode));
69+
$conf = PhabricatorEnv::newObjectFromConfig(
70+
'mysql.configuration-provider',
71+
array($this, $mode));
7372

7473
return PhabricatorEnv::newObjectFromConfig(
7574
'mysql.implementation',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
phutil_require_module('phabricator', 'infrastructure/env');
1010
phutil_require_module('phabricator', 'storage/lisk/dao');
1111

12-
phutil_require_module('phutil', 'symbols');
1312
phutil_require_module('phutil', 'utils');
1413

1514

0 commit comments

Comments
 (0)