Note that only one extension uses this class and should not be affected.
Also, make the constructor take an optional LoadBalancer for DI.
Change-Id: Ibb7192ac199427266d7e3f3f14437d0495061911
* @author Daniel Kinzler
*/
abstract class DBAccessBase implements IDBAccessObject {
* @author Daniel Kinzler
*/
abstract class DBAccessBase implements IDBAccessObject {
- /**
- * @var string|bool $wiki The target wiki's name. This must be an ID
- * that LBFactory can understand.
- */
- protected $wiki = false;
+ /** @var ILoadBalancer */
+ private $lb;
+
+ /** @var string|bool The target wiki's DB domain */
+ protected $dbDomain = false;
- * @param string|bool $wiki The target wiki's name. This must be an ID
- * that LBFactory can understand.
+ * @param string|bool $dbDomain The target wiki's DB domain
- public function __construct( $wiki = false ) {
- $this->wiki = $wiki;
+ public function __construct( $dbDomain = false ) {
+ $this->dbDomain = $dbDomain;
+ $this->lb = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()
+ ->getMainLB( $dbDomain );
}
/**
* Returns a database connection.
*
}
/**
* Returns a database connection.
*
* @see LoadBalancer::getConnection()
*
* @since 1.21
* @see LoadBalancer::getConnection()
*
* @since 1.21
* @return IDatabase
*/
protected function getConnection( $id, array $groups = [] ) {
* @return IDatabase
*/
protected function getConnection( $id, array $groups = [] ) {
- $loadBalancer = $this->getLoadBalancer();
-
- return $loadBalancer->getConnection( $id, $groups, $this->wiki );
+ return $this->getLoadBalancer()->getConnectionRef( $id, $groups, $this->dbDomain );
* @since 1.21
*
* @param IDatabase $db The database connection to release.
* @since 1.21
*
* @param IDatabase $db The database connection to release.
+ * @deprecated Since 1.34
*/
protected function releaseConnection( IDatabase $db ) {
*/
protected function releaseConnection( IDatabase $db ) {
- if ( $this->wiki !== false ) {
- $loadBalancer = $this->getLoadBalancer();
- $loadBalancer->reuseConnection( $db );
- }
*
* @return ILoadBalancer The database load balancer object
*/
*
* @return ILoadBalancer The database load balancer object
*/
- public function getLoadBalancer() {
- $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
- return $lbFactory->getMainLB( $this->wiki );
+ protected function getLoadBalancer() {
+ return $this->lb;