jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/335391 )

Change subject: Use DBConnRef for central DB connections
......................................................................


Use DBConnRef for central DB connections

DBConnRef is a wrapper that automatically calls reuseConnection() when
the object goes out of scope, which prevents annoying "Foreign domain
connections are still in use (centralauth)" exceptions at the end of
unit test runs.

This also necessitates changing a bunch of typehints and doc blocks to
"IDatabase" rather than "Database".

Change-Id: I40efc73affed9428b11f4f0f94cb12efe50777f9
---
M AntiSpoof/CentralAuthSpoofUser.php
M AntiSpoof/batchCAAntiSpoof.php
M includes/CentralAuthUser.php
M includes/CentralAuthUtils.php
M includes/GlobalRename/GlobalRenameRequest.php
M includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php
M includes/GlobalRename/GlobalRenameUserStatus.php
M includes/GlobalRename/GlobalUserMergeDatabaseUpdates.php
M includes/UsersToRename/UsersToRenameDatabaseUpdates.php
M includes/api/ApiQueryGlobalAllUsers.php
M maintenance/forceRenameUsers.php
M tests/phpunit/CentralAuthTestUser.php
12 files changed, 26 insertions(+), 26 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/AntiSpoof/CentralAuthSpoofUser.php 
b/AntiSpoof/CentralAuthSpoofUser.php
index f19b88a..96a0e04 100644
--- a/AntiSpoof/CentralAuthSpoofUser.php
+++ b/AntiSpoof/CentralAuthSpoofUser.php
@@ -2,14 +2,14 @@
 
 class CentralAuthSpoofUser extends SpoofUser {
        /**
-        * @return Database
+        * @return IDatabase
         */
        protected function getDBSlave() {
                return CentralAuthUtils::getCentralSlaveDB();
        }
 
        /**
-        * @return Database
+        * @return IDatabase
         */
        protected function getDBMaster() {
                return CentralAuthUtils::getCentralDB();
diff --git a/AntiSpoof/batchCAAntiSpoof.php b/AntiSpoof/batchCAAntiSpoof.php
index 4daae86..dabba84 100644
--- a/AntiSpoof/batchCAAntiSpoof.php
+++ b/AntiSpoof/batchCAAntiSpoof.php
@@ -17,7 +17,7 @@
        }
 
        /**
-        * @return Database
+        * @return IDatabase
         */
        protected function getDB() {
                return CentralAuthUtils::getCentralDB();
diff --git a/includes/CentralAuthUser.php b/includes/CentralAuthUser.php
index 46e1734..208e1ee 100644
--- a/includes/CentralAuthUser.php
+++ b/includes/CentralAuthUser.php
@@ -204,10 +204,10 @@
 
        /**
         * @param string $wikiID
-        * @return Database
+        * @return IDatabase
         */
        public static function getLocalDB( $wikiID ) {
-               return wfGetLB( $wikiID )->getConnection( DB_MASTER, array(), 
$wikiID );
+               return wfGetLB( $wikiID )->getConnectionRef( DB_MASTER, 
array(), $wikiID );
        }
 
        /**
@@ -220,7 +220,7 @@
        }
 
        /**
-        * @return Database Master or slave based on shouldUseMasterDB()
+        * @return IDatabase Master or slave based on shouldUseMasterDB()
         * @throws CentralAuthReadOnlyError
         */
        protected function getSafeReadDB() {
@@ -1723,7 +1723,7 @@
                global $wgConf;
 
                $lb = wfGetLB( $wiki );
-               $dbw = $lb->getConnection( DB_MASTER, array(), $wiki );
+               $dbw = $lb->getConnectionRef( DB_MASTER, array(), $wiki );
                $data = $this->localUserData( $wiki );
 
                if ( $suppress ) {
diff --git a/includes/CentralAuthUtils.php b/includes/CentralAuthUtils.php
index e4b9367..d649afc 100644
--- a/includes/CentralAuthUtils.php
+++ b/includes/CentralAuthUtils.php
@@ -39,7 +39,7 @@
        /**
         * Gets a master (read/write) database connection to the CentralAuth 
database
         *
-        * @return Database
+        * @return IDatabase
         * @throws CentralAuthReadOnlyError
         */
        public static function getCentralDB() {
@@ -49,19 +49,19 @@
                        throw new CentralAuthReadOnlyError();
                }
 
-               return wfGetLB( $wgCentralAuthDatabase )->getConnection( 
DB_MASTER, array(),
+               return wfGetLB( $wgCentralAuthDatabase )->getConnectionRef( 
DB_MASTER, array(),
                        $wgCentralAuthDatabase );
        }
 
        /**
         * Gets a slave (readonly) database connection to the CentralAuth 
database
         *
-        * @return Database
+        * @return IDatabase
         */
        public static function getCentralSlaveDB() {
                global $wgCentralAuthDatabase;
 
-               return wfGetLB( $wgCentralAuthDatabase )->getConnection(
+               return wfGetLB( $wgCentralAuthDatabase )->getConnectionRef(
                        DB_REPLICA, 'centralauth', $wgCentralAuthDatabase );
        }
 
diff --git a/includes/GlobalRename/GlobalRenameRequest.php 
b/includes/GlobalRename/GlobalRenameRequest.php
index d8d9317..4adcdb2 100644
--- a/includes/GlobalRename/GlobalRenameRequest.php
+++ b/includes/GlobalRename/GlobalRenameRequest.php
@@ -369,7 +369,7 @@
         * Get a Database object for the CentralAuth db
         *
         * @param int $type DB_REPLICA or DB_MASTER
-        * @return Database
+        * @return IDatabase
         */
        protected static function getDB( $type ) {
                if ( $type === DB_MASTER ) {
diff --git a/includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php 
b/includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php
index a4e7441..4e19747 100644
--- a/includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php
+++ b/includes/GlobalRename/GlobalRenameUserDatabaseUpdates.php
@@ -9,7 +9,7 @@
 
 class GlobalRenameUserDatabaseUpdates {
        /**
-        * @return Database
+        * @return IDatabase
         */
        protected function getDB() {
                return CentralAuthUtils::getCentralDB();
diff --git a/includes/GlobalRename/GlobalRenameUserStatus.php 
b/includes/GlobalRename/GlobalRenameUserStatus.php
index 73733b9..80b5164 100644
--- a/includes/GlobalRename/GlobalRenameUserStatus.php
+++ b/includes/GlobalRename/GlobalRenameUserStatus.php
@@ -30,7 +30,7 @@
         *
         * @param int $type DB_REPLICA or DB_MASTER
         *
-        * @return Database
+        * @return IDatabase
         */
        protected function getDB( $type = DB_REPLICA ) {
                if ( $type === DB_MASTER ) {
@@ -43,11 +43,11 @@
        /**
         * Get the where clause to query rows by either old or new name
         *
-        * @param Database $db
+        * @param IDatabase $db
         *
         * @return string
         */
-       private function getNameWhereClause( Database $db ) {
+       private function getNameWhereClause( IDatabase $db ) {
                return $db->makeList(
                        array( 'ru_oldname' => $this->name, 'ru_newname' => 
$this->name ),
                        LIST_OR
diff --git a/includes/GlobalRename/GlobalUserMergeDatabaseUpdates.php 
b/includes/GlobalRename/GlobalUserMergeDatabaseUpdates.php
index a6d8a68..9739e17 100644
--- a/includes/GlobalRename/GlobalUserMergeDatabaseUpdates.php
+++ b/includes/GlobalRename/GlobalUserMergeDatabaseUpdates.php
@@ -9,7 +9,7 @@
 
 class GlobalUserMergeDatabaseUpdates {
        /**
-        * @return Database
+        * @return IDatabase
         */
        protected function getDB() {
                return CentralAuthUtils::getCentralDB();
diff --git a/includes/UsersToRename/UsersToRenameDatabaseUpdates.php 
b/includes/UsersToRename/UsersToRenameDatabaseUpdates.php
index ff8aeb4..a37a7a7 100644
--- a/includes/UsersToRename/UsersToRenameDatabaseUpdates.php
+++ b/includes/UsersToRename/UsersToRenameDatabaseUpdates.php
@@ -16,11 +16,11 @@
        const RENAMED = 8;
 
        /**
-        * @var Database
+        * @var IDatabase
         */
        private $db;
 
-       public function __construct( Database $db ) {
+       public function __construct( IDatabase $db ) {
                $this->db = $db;
        }
 
diff --git a/includes/api/ApiQueryGlobalAllUsers.php 
b/includes/api/ApiQueryGlobalAllUsers.php
index 75036d1..3edb9db 100644
--- a/includes/api/ApiQueryGlobalAllUsers.php
+++ b/includes/api/ApiQueryGlobalAllUsers.php
@@ -33,7 +33,7 @@
         * Get the Query database connection (read-only)
         *
         * @see ApiQueryBase::getDB
-        * @return Database
+        * @return IDatabase
         */
        protected function getDB() {
                static $db = null ;
diff --git a/maintenance/forceRenameUsers.php b/maintenance/forceRenameUsers.php
index 12ccfa2..ade3086 100644
--- a/maintenance/forceRenameUsers.php
+++ b/maintenance/forceRenameUsers.php
@@ -53,7 +53,7 @@
                }
        }
 
-       protected function getCurrentRenameCount( Database $dbw ) {
+       protected function getCurrentRenameCount( IDatabase $dbw ) {
                $row = $dbw->selectRow(
                        array( 'renameuser_status'),
                        array( 'COUNT(*) as count' ),
@@ -63,7 +63,7 @@
                return (int)$row->count;
        }
 
-       protected function rename( $row, Database $dbw ) {
+       protected function rename( $row, IDatabase $dbw ) {
                $wiki = $row->utr_wiki;
                $name = $row->utr_name;
                $newNamePrefix = User::getCanonicalName(
@@ -129,10 +129,10 @@
 
        /**
         * @param string $wiki
-        * @param Database $dbw
+        * @param IDatabase $dbw
         * @return stdClass[]
         */
-       protected function findUsers( $wiki, Database $dbw ) {
+       protected function findUsers( $wiki, IDatabase $dbw ) {
                $rowsToRename = array();
                $updates = new UsersToRenameDatabaseUpdates( $dbw );
                $rows = $updates->findUsers( $wiki, 
UsersToRenameDatabaseUpdates::NOTIFIED, $this->mBatchSize );
diff --git a/tests/phpunit/CentralAuthTestUser.php 
b/tests/phpunit/CentralAuthTestUser.php
index 7b4883a..b2330df 100644
--- a/tests/phpunit/CentralAuthTestUser.php
+++ b/tests/phpunit/CentralAuthTestUser.php
@@ -138,9 +138,9 @@
 
        /**
         * Save the user into a centralauth database
-        * @param Database $db
+        * @param IDatabase $db
         */
-       public function save( Database $db ) {
+       public function save( IDatabase $db ) {
                // Setup local wiki user
                if ( $this->createLocal ) {
                        $user = User::newFromName( $this->username );

-- 
To view, visit https://gerrit.wikimedia.org/r/335391
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I40efc73affed9428b11f4f0f94cb12efe50777f9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: MarcoAurelio <strig...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to