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:
		| @@ -111,13 +111,6 @@ return array( | |||||||
|   // The MySQL server to connect to. |   // The MySQL server to connect to. | ||||||
|   'mysql.host' => 'localhost', |   '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 ----------------------------------------------------------------- // | // -- Email ----------------------------------------------------------------- // | ||||||
|  |  | ||||||
|   // Some Phabricator tools send email notifications, e.g. when Differential |   // 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', |     'DarkConsoleServicesPluginAPI' => 'aphront/console/plugin/services/api', | ||||||
|     'DarkConsoleXHProfPlugin' => 'aphront/console/plugin/xhprof', |     'DarkConsoleXHProfPlugin' => 'aphront/console/plugin/xhprof', | ||||||
|     'DarkConsoleXHProfPluginAPI' => 'aphront/console/plugin/xhprof/api', |     'DarkConsoleXHProfPluginAPI' => 'aphront/console/plugin/xhprof/api', | ||||||
|  |     'DatabaseConfigurationProvider' => 'applications/base/storage/configuration', | ||||||
|     'DifferentialAction' => 'applications/differential/constants/action', |     'DifferentialAction' => 'applications/differential/constants/action', | ||||||
|     'DifferentialAddCommentView' => 'applications/differential/view/addcomment', |     'DifferentialAddCommentView' => 'applications/differential/view/addcomment', | ||||||
|     'DifferentialAttachController' => 'applications/differential/controller/attach', |     '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 { | abstract class PhabricatorLiskDAO extends LiskDAO { | ||||||
|  |  | ||||||
|   public function establishConnection($mode) { |   public function establishConnection($mode) { | ||||||
|     $mysql_key = 'mysql'; |     $conf_provider = PhabricatorEnv::getEnvConfig( | ||||||
|     if ($mode == 'r') { |       'mysql.configuration_provider', 'DatabaseConfigurationProvider'); | ||||||
|       $mysql_key = 'mysql_slave'; |     PhutilSymbolLoader::loadClass($conf_provider); | ||||||
|     } |     $conf = newv($conf_provider, array($this, $mode)); | ||||||
|  |  | ||||||
|     return new AphrontMySQLDatabaseConnection( |     return new AphrontMySQLDatabaseConnection( | ||||||
|       array( |       array( | ||||||
|         'user'      => PhabricatorEnv::getEnvConfig($mysql_key.'.user'), |         'user'      => $conf->getUser(), | ||||||
|         'pass'      => PhabricatorEnv::getEnvConfig($mysql_key.'.pass'), |         'pass'      => $conf->getPassword(), | ||||||
|         'host'      => PhabricatorEnv::getEnvConfig($mysql_key.'.host'), |         'host'      => $conf->getHost(), | ||||||
|         'database'  => 'phabricator_'.$this->getApplicationName(), |         'database'  => $conf->getDatabase(), | ||||||
|       )); |       )); | ||||||
|  |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public function getTableName() { |   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/connection/mysql'); | ||||||
| phutil_require_module('phabricator', 'storage/lisk/dao'); | phutil_require_module('phabricator', 'storage/lisk/dao'); | ||||||
|  |  | ||||||
|  | phutil_require_module('phutil', 'symbols'); | ||||||
|  | phutil_require_module('phutil', 'utils'); | ||||||
|  |  | ||||||
|  |  | ||||||
| phutil_require_source('PhabricatorLiskDAO.php'); | phutil_require_source('PhabricatorLiskDAO.php'); | ||||||
|   | |||||||
| @@ -603,6 +603,9 @@ abstract class LiskDAO { | |||||||
|       throw new Exception("Unknown mode '{$mode}', should be 'r' or 'w'."); |       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])) { |     if (!isset($this->__connections[$mode])) { | ||||||
|       $this->__connections[$mode] = $this->establishConnection($mode); |       $this->__connections[$mode] = $this->establishConnection($mode); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 adonohue
					adonohue