From c2893d86705a27ea7719dbd6a3a466412d45a13f Mon Sep 17 00:00:00 2001 From: adonohue Date: Fri, 29 Apr 2011 17:23:25 -0700 Subject: [PATCH] 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 --- conf/default.conf.php | 7 --- src/__phutil_library_map__.php | 1 + .../DatabaseConfigurationProvider.php | 51 +++++++++++++++++++ .../base/storage/configuration/__init__.php | 12 +++++ .../base/storage/lisk/PhabricatorLiskDAO.php | 18 +++---- .../base/storage/lisk/__init__.php | 3 ++ src/storage/lisk/dao/LiskDAO.php | 3 ++ 7 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 src/applications/base/storage/configuration/DatabaseConfigurationProvider.php create mode 100644 src/applications/base/storage/configuration/__init__.php diff --git a/conf/default.conf.php b/conf/default.conf.php index 2b17b52e4f..956d7c5fe8 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -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 diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 458b0a6ee0..5bbb5e1a98 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/base/storage/configuration/DatabaseConfigurationProvider.php b/src/applications/base/storage/configuration/DatabaseConfigurationProvider.php new file mode 100644 index 0000000000..6ec9771dd9 --- /dev/null +++ b/src/applications/base/storage/configuration/DatabaseConfigurationProvider.php @@ -0,0 +1,51 @@ +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; + } +} diff --git a/src/applications/base/storage/configuration/__init__.php b/src/applications/base/storage/configuration/__init__.php new file mode 100644 index 0000000000..bf6cd309d0 --- /dev/null +++ b/src/applications/base/storage/configuration/__init__.php @@ -0,0 +1,12 @@ + 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() { diff --git a/src/applications/base/storage/lisk/__init__.php b/src/applications/base/storage/lisk/__init__.php index 0177e6f7fd..1a3b8cd7f1 100644 --- a/src/applications/base/storage/lisk/__init__.php +++ b/src/applications/base/storage/lisk/__init__.php @@ -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'); diff --git a/src/storage/lisk/dao/LiskDAO.php b/src/storage/lisk/dao/LiskDAO.php index 2f41ebc080..2fedac8392 100644 --- a/src/storage/lisk/dao/LiskDAO.php +++ b/src/storage/lisk/dao/LiskDAO.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); }