Merge "Fix default "srvCache" BagOStuff in DatabaseBase"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 15 Sep 2016 18:43:22 +0000 (18:43 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 15 Sep 2016 18:43:22 +0000 (18:43 +0000)
1  2 
includes/db/Database.php

diff --combined includes/db/Database.php
@@@ -60,8 -60,6 +60,8 @@@ abstract class DatabaseBase implements 
        protected $mPassword;
        /** @var string */
        protected $mDBname;
 +      /** @var array[] $aliases Map of (table => (dbname, schema, prefix) map) */
 +      protected $tableAliases = [];
        /** @var bool */
        protected $cliMode;
  
@@@ -96,6 -94,8 +96,6 @@@
        protected $mSchema;
        /** @var integer */
        protected $mFlags;
 -      /** @var bool */
 -      protected $mForeign;
        /** @var array */
        protected $mLBInfo = [];
        /** @var bool|null */
  
                $this->mSessionVars = $params['variables'];
  
 -              $this->mForeign = $params['foreign'];
 -
                $this->srvCache = isset( $params['srvCache'] )
                        ? $params['srvCache']
-                       : new EmptyBagOStuff();
+                       : new HashBagOStuff();
  
                $this->profiler = isset( $params['profiler'] )
                        ? $params['profiler']
                }
        }
  
 -      /**
 -       * Return a path to the DBMS-specific SQL file if it exists,
 -       * otherwise default SQL file
 -       *
 -       * @param string $filename
 -       * @return string
 -       */
 -      private function getSqlFilePath( $filename ) {
 -              global $IP;
 -              $dbmsSpecificFilePath = "$IP/maintenance/" . $this->getType() . "/$filename";
 -              if ( file_exists( $dbmsSpecificFilePath ) ) {
 -                      return $dbmsSpecificFilePath;
 -              } else {
 -                      return "$IP/maintenance/$filename";
 -              }
 -      }
 -
 -      /**
 -       * Return a path to the DBMS-specific schema file,
 -       * otherwise default to tables.sql
 -       *
 -       * @return string
 -       */
 -      public function getSchemaPath() {
 -              return $this->getSqlFilePath( 'tables.sql' );
 -      }
 -
 -      /**
 -       * Return a path to the DBMS-specific update key file,
 -       * otherwise default to update-keys.sql
 -       *
 -       * @return string
 -       */
 -      public function getUpdateKeysPath() {
 -              return $this->getSqlFilePath( 'update-keys.sql' );
 -      }
 -
        /**
         * Get information about an index into an object
         * @param string $table Table name
         * @return string Full database name
         */
        public function tableName( $name, $format = 'quoted' ) {
 -              global $wgSharedDB, $wgSharedPrefix, $wgSharedTables, $wgSharedSchema;
                # Skip the entire process when we have a string quoted on both ends.
                # Note that we check the end so that we will still quote any use of
                # use of `database`.table. But won't break things if someone wants
                        $schema = null;
                } 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 ) # Prevent shared tables listing '`table`'
 -                              && in_array( $table, $wgSharedTables ) # A shared table is selected
 -                      ) {
 -                              $database = $wgSharedDB;
 -                              $schema = $wgSharedSchema === null ? $this->mSchema : $wgSharedSchema;
 -                              $prefix = $wgSharedPrefix === null ? $this->mTablePrefix : $wgSharedPrefix;
 +                      if ( isset( $this->tableAliases[$table] ) ) {
 +                              $database = $this->tableAliases[$table]['dbname'];
 +                              $schema = is_string( $this->tableAliases[$table]['schema'] )
 +                                      ? $this->tableAliases[$table]['schema']
 +                                      : $this->mSchema;
 +                              $prefix = is_string( $this->tableAliases[$table]['prefix'] )
 +                                      ? $this->tableAliases[$table]['prefix']
 +                                      : $this->mTablePrefix;
                        } else {
                                $database = null;
                                $schema = $this->mSchema; # Default schema
                # Quote $table and apply the prefix if not quoted.
                # $tableName might be empty if this is called from Database::replaceVars()
                $tableName = "{$prefix}{$table}";
 -              if ( $format == 'quoted' && !$this->isQuotedIdentifier( $tableName ) && $tableName !== '' ) {
 +              if ( $format == 'quoted'
 +                      && !$this->isQuotedIdentifier( $tableName ) && $tableName !== ''
 +              ) {
                        $tableName = $this->addIdentifierQuotes( $tableName );
                }
  
                return $error;
        }
  
 -      /**
 -       * Get the full path of a patch file. Originally based on archive()
 -       * from updaters.inc. Keep in mind this always returns a patch, as
 -       * it fails back to MySQL if no DB-specific patch can be found
 -       *
 -       * @param string $patch The name of the patch, like patch-something.sql
 -       * @return string Full path to patch file
 -       */
 -      public function patchPath( $patch ) {
 -              global $IP;
 -
 -              $dbType = $this->getType();
 -              if ( file_exists( "$IP/maintenance/$dbType/archives/$patch" ) ) {
 -                      return "$IP/maintenance/$dbType/archives/$patch";
 -              } else {
 -                      return "$IP/maintenance/archives/$patch";
 -              }
 -      }
 -
        public function setSchemaVars( $vars ) {
                $this->mSchemaVars = $vars;
        }
                return is_string( $reason ) ? $reason : false;
        }
  
 +      public function setTableAliases( array $aliases ) {
 +              $this->tableAliases = $aliases;
 +      }
 +
        /**
         * @since 1.19
         * @return string