Clean up $wgDBmwschema handling and only apply it to mssql
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 15 Sep 2016 20:51:31 +0000 (13:51 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Sat, 17 Sep 2016 23:49:25 +0000 (16:49 -0700)
Follow-up to 61762bf3f8f904bcc5a0f90985e7f787756032a7

Change-Id: Ib8dc247ba17d7cbf4cf0f46dbe82983a715f2c8d

includes/db/loadbalancer/LBFactoryMW.php
includes/libs/rdbms/database/Database.php

index 5db7736..69fd21d 100644 (file)
@@ -28,7 +28,6 @@ use MediaWiki\Logger\LoggerFactory;
  * @ingroup Database
  */
 abstract class LBFactoryMW extends LBFactory {
-       /** @noinspection PhpMissingParentConstructorInspection */
        /**
         * Construct a factory based on a configuration array (typically from $wgLBFactoryConf)
         * @param array $conf
@@ -44,7 +43,8 @@ abstract class LBFactoryMW extends LBFactory {
         * @TODO: inject objects via dependency framework
         */
        public static function applyDefaultConfig( array $conf ) {
-               global $wgCommandLineMode, $wgSQLMode, $wgDBmysql5, $wgDBname, $wgDBprefix;
+               global $wgDBtype, $wgSQLMode, $wgDBmysql5, $wgDBname, $wgDBprefix, $wgDBmwschema;
+               global $wgCommandLineMode;
 
                $defaults = [
                        'localDomain' => new DatabaseDomain( $wgDBname, null, $wgDBprefix ),
@@ -73,9 +73,20 @@ abstract class LBFactoryMW extends LBFactory {
                        $defaults['wanCache'] = $wCache;
                }
 
+               // Determine schema defaults. Currently Microsoft SQL Server uses $wgDBmwschema,
+               // and everything else doesn't use a schema (e.g. null)
+               // Although postgres and oracle support schemas, we don't use them (yet)
+               // to maintain backwards compatibility
+               $schema = ( $wgDBtype === 'mssql' ) ? $wgDBmwschema : null;
+
                if ( isset( $conf['serverTemplate'] ) ) { // LBFactoryMulti
+                       $conf['serverTemplate']['schema'] = $schema;
                        $conf['serverTemplate']['sqlMode'] = $wgSQLMode;
                        $conf['serverTemplate']['utf8Mode'] = $wgDBmysql5;
+               } elseif ( isset( $conf['servers'] ) ) { // LBFactorySimple
+                       foreach ( $conf['servers'] as $i => $server ) {
+                               $conf['servers'][$i]['schema'] = $schema;
+                       }
                }
 
                return $conf + $defaults;
index 3672f4a..de0de6e 100644 (file)
@@ -352,14 +352,6 @@ abstract class Database implements IDatabase, LoggerAwareInterface {
                                " no viable database extension found for type '$dbType'" );
                }
 
-               // Determine schema defaults. Currently Microsoft SQL Server uses $wgDBmwschema,
-               // and everything else doesn't use a schema (e.g. null)
-               // Although postgres and oracle support schemas, we don't use them (yet)
-               // to maintain backwards compatibility
-               $defaultSchemas = [
-                       'mssql' => 'get from global',
-               ];
-
                $class = 'Database' . ucfirst( $driver );
                if ( class_exists( $class ) && is_subclass_of( $class, 'IDatabase' ) ) {
                        // Resolve some defaults for b/c
@@ -370,9 +362,7 @@ abstract class Database implements IDatabase, LoggerAwareInterface {
                        $p['flags'] = isset( $p['flags'] ) ? $p['flags'] : 0;
                        $p['variables'] = isset( $p['variables'] ) ? $p['variables'] : [];
                        $p['tablePrefix'] = isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : '';
-                       if ( !isset( $p['schema'] ) ) {
-                               $p['schema'] = isset( $defaultSchemas[$dbType] ) ? $defaultSchemas[$dbType] : '';
-                       }
+                       $p['schema'] = isset( $p['schema'] ) ? $p['schema'] : '';
                        $p['foreign'] = isset( $p['foreign'] ) ? $p['foreign'] : false;
 
                        $conn = new $class( $p );