mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 15:30:58 +01:00
Hook for database configuration plugin
Summary: This permits individual deployments to better configure their database configuration, e.g. to allow more dynamic configuration that reacts to database moves or master/slave replication. Test Plan: Browse Reviewed By: epriestley Reviewers: Girish, epriestley CC: aran, epriestley Differential Revision: 183
This commit is contained in:
parent
c59b56b490
commit
c2893d8670
7 changed files with 79 additions and 16 deletions
|
@ -111,13 +111,6 @@ return array(
|
|||
// The MySQL server to connect to.
|
||||
'mysql.host' => 'localhost',
|
||||
|
||||
// READ-ONLY database connection information
|
||||
// If you have a read-only slave mysql server, then you can fill out the
|
||||
// below fields. If not, duplicate the above information for the slave.
|
||||
'mysql_slave.user' => 'root',
|
||||
'mysql_slave.pass' => '',
|
||||
'mysql_slave.host' => 'localhost',
|
||||
|
||||
// -- Email ----------------------------------------------------------------- //
|
||||
|
||||
// Some Phabricator tools send email notifications, e.g. when Differential
|
||||
|
|
|
@ -107,6 +107,7 @@ phutil_register_library_map(array(
|
|||
'DarkConsoleServicesPluginAPI' => 'aphront/console/plugin/services/api',
|
||||
'DarkConsoleXHProfPlugin' => 'aphront/console/plugin/xhprof',
|
||||
'DarkConsoleXHProfPluginAPI' => 'aphront/console/plugin/xhprof/api',
|
||||
'DatabaseConfigurationProvider' => 'applications/base/storage/configuration',
|
||||
'DifferentialAction' => 'applications/differential/constants/action',
|
||||
'DifferentialAddCommentView' => 'applications/differential/view/addcomment',
|
||||
'DifferentialAttachController' => 'applications/differential/controller/attach',
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class DatabaseConfigurationProvider {
|
||||
private $dao;
|
||||
private $mode;
|
||||
|
||||
public function __construct(LiskDAO $dao, $mode) {
|
||||
$this->dao = $dao;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
public function getUser() {
|
||||
return PhabricatorEnv::getEnvConfig('mysql.user');
|
||||
}
|
||||
|
||||
public function getPassword() {
|
||||
return PhabricatorEnv::getEnvConfig('mysql.pass');
|
||||
}
|
||||
|
||||
public function getHost() {
|
||||
return PhabricatorEnv::getEnvConfig('mysql.host');
|
||||
}
|
||||
|
||||
public function getDatabase() {
|
||||
return 'phabricator_'.$this->getDao()->getApplicationName();
|
||||
}
|
||||
|
||||
final protected function getDao() {
|
||||
return $this->dao;
|
||||
}
|
||||
|
||||
final protected function getMode() {
|
||||
return $this->mode;
|
||||
}
|
||||
}
|
12
src/applications/base/storage/configuration/__init__.php
Normal file
12
src/applications/base/storage/configuration/__init__.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
|
||||
phutil_require_source('DatabaseConfigurationProvider.php');
|
|
@ -20,18 +20,18 @@
|
|||
abstract class PhabricatorLiskDAO extends LiskDAO {
|
||||
|
||||
public function establishConnection($mode) {
|
||||
$mysql_key = 'mysql';
|
||||
if ($mode == 'r') {
|
||||
$mysql_key = 'mysql_slave';
|
||||
}
|
||||
$conf_provider = PhabricatorEnv::getEnvConfig(
|
||||
'mysql.configuration_provider', 'DatabaseConfigurationProvider');
|
||||
PhutilSymbolLoader::loadClass($conf_provider);
|
||||
$conf = newv($conf_provider, array($this, $mode));
|
||||
|
||||
return new AphrontMySQLDatabaseConnection(
|
||||
array(
|
||||
'user' => PhabricatorEnv::getEnvConfig($mysql_key.'.user'),
|
||||
'pass' => PhabricatorEnv::getEnvConfig($mysql_key.'.pass'),
|
||||
'host' => PhabricatorEnv::getEnvConfig($mysql_key.'.host'),
|
||||
'database' => 'phabricator_'.$this->getApplicationName(),
|
||||
'user' => $conf->getUser(),
|
||||
'pass' => $conf->getPassword(),
|
||||
'host' => $conf->getHost(),
|
||||
'database' => $conf->getDatabase(),
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public function getTableName() {
|
||||
|
|
|
@ -10,5 +10,8 @@ phutil_require_module('phabricator', 'infrastructure/env');
|
|||
phutil_require_module('phabricator', 'storage/connection/mysql');
|
||||
phutil_require_module('phabricator', 'storage/lisk/dao');
|
||||
|
||||
phutil_require_module('phutil', 'symbols');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorLiskDAO.php');
|
||||
|
|
|
@ -603,6 +603,9 @@ abstract class LiskDAO {
|
|||
throw new Exception("Unknown mode '{$mode}', should be 'r' or 'w'.");
|
||||
}
|
||||
|
||||
// TODO There is currently no protection on 'r' queries against writing
|
||||
// or on 'w' queries against reading
|
||||
|
||||
if (!isset($this->__connections[$mode])) {
|
||||
$this->__connections[$mode] = $this->establishConnection($mode);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue