Never prefix table names with $wgSharedDB when used in foreign DB
authorLiangent <liangent@gmail.com>
Sun, 26 May 2013 07:37:42 +0000 (07:37 +0000)
committerLiangent <liangent@gmail.com>
Mon, 27 May 2013 04:52:20 +0000 (04:52 +0000)
Now database classes have an extra "foreign" property when used in
foreign databases, where $wgSharedDB and $wgSharedTables are not
considered.

Bug: 48819
Change-Id: I45db6860d0a4b4480e0b93aa7e750f096424e40f

includes/db/Database.php
includes/db/LoadBalancer.php
includes/filerepo/ForeignDBRepo.php

index 85c459e..8b56ab0 100644 (file)
@@ -236,6 +236,7 @@ abstract class DatabaseBase implements DatabaseType {
 
        protected $mTablePrefix;
        protected $mFlags;
+       protected $mForeign;
        protected $mTrxLevel = 0;
        protected $mErrorCount = 0;
        protected $mLBInfo = array();
@@ -660,9 +661,10 @@ abstract class DatabaseBase implements DatabaseType {
         * @param string $dbName database name
         * @param $flags
         * @param string $tablePrefix database table prefixes. By default use the prefix gave in LocalSettings.php
+        * @param bool $foreign disable some operations specific to local databases
         */
        function __construct( $server = false, $user = false, $password = false, $dbName = false,
-               $flags = 0, $tablePrefix = 'get from global'
+               $flags = 0, $tablePrefix = 'get from global', $foreign = false
        ) {
                global $wgDBprefix, $wgCommandLineMode, $wgDebugDBTransactions;
 
@@ -689,6 +691,8 @@ abstract class DatabaseBase implements DatabaseType {
                        $this->mTablePrefix = $tablePrefix;
                }
 
+               $this->mForeign = $foreign;
+
                if ( $user ) {
                        $this->open( $server, $user, $password, $dbName );
                }
@@ -738,7 +742,8 @@ abstract class DatabaseBase implements DatabaseType {
                                isset( $p['password'] ) ? $p['password'] : false,
                                isset( $p['dbname'] ) ? $p['dbname'] : false,
                                isset( $p['flags'] ) ? $p['flags'] : 0,
-                               isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global'
+                               isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global',
+                               isset( $p['foreign'] ) ? $p['foreign'] : false
                        );
                } else {
                        return null;
@@ -2068,6 +2073,7 @@ abstract class DatabaseBase implements DatabaseType {
                } else {
                        list( $table ) = $dbDetails;
                        if ( $wgSharedDB !== null # We have a shared database
+                               && $this->mForeign == false # We're not working on a foreign database
                                && !$this->isQuotedIdentifier( $table ) # Paranoia check to prevent shared tables listing '`table`'
                                && in_array( $table, $wgSharedTables ) # A shared table is selected
                        ) {
index f702047..1d27308 100644 (file)
@@ -636,6 +636,7 @@ class LoadBalancer {
                        $server = $this->mServers[$i];
                        $server['serverIndex'] = $i;
                        $server['foreignPoolRefCount'] = 0;
+                       $server['foreign'] = true;
                        $conn = $this->reallyOpenConnection( $server, $dbName );
                        if ( !$conn->isOpen() ) {
                                wfDebug( __METHOD__ . ": error opening connection for $i/$wiki\n" );
index ecad618..37c6572 100644 (file)
@@ -63,7 +63,8 @@ class ForeignDBRepo extends LocalRepo {
                                        'password' => $this->dbPassword,
                                        'dbname' => $this->dbName,
                                        'flags' => $this->dbFlags,
-                                       'tablePrefix' => $this->tablePrefix
+                                       'tablePrefix' => $this->tablePrefix,
+                                       'foreign' => true,
                                )
                        );
                }