From 8d82ff1069d4ed8995a59b2e1232c5979fec4b5e Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 15 Sep 2016 13:51:31 -0700 Subject: [PATCH] Clean up $wgDBmwschema handling and only apply it to mssql Follow-up to 61762bf3f8f904bcc5a0f90985e7f787756032a7 Change-Id: Ib8dc247ba17d7cbf4cf0f46dbe82983a715f2c8d --- includes/db/loadbalancer/LBFactoryMW.php | 15 +++++++++++++-- includes/libs/rdbms/database/Database.php | 12 +----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/includes/db/loadbalancer/LBFactoryMW.php b/includes/db/loadbalancer/LBFactoryMW.php index 5db773676b..69fd21dc16 100644 --- a/includes/db/loadbalancer/LBFactoryMW.php +++ b/includes/db/loadbalancer/LBFactoryMW.php @@ -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; diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 3672f4a238..de0de6e59f 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -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 ); -- 2.20.1