database: Don't treat $defaultSchemas as containing all types/drivers
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 15 Jun 2015 17:15:28 +0000 (18:15 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 15 Jun 2015 17:16:32 +0000 (18:16 +0100)
The Database::factory() method treats $dbType as of one of
predefined "canonicalDBTypes", and defaults to using it as driver.
Which is then used for the name of the Database subclass.

This allows extensions and wiki farms to have custom subclasses
to override certain methods, or even provide new drivers.

The $defaultSchemas array added in f7174057a4 was given all canonical
keys (with null values) to allow unconditionally access. This
doesn't scale very well and is error-prone. Reduce it to the
override only and fallback make the fallback to null explicitly.

See T102285 for where this would help prevent a PHP Notice.

Change-Id: I3f1e1f59c300d34de30f6480ff4e54f159d51b16

includes/db/Database.php

index e15c248..94cf1f2 100644 (file)
@@ -915,10 +915,6 @@ abstract class DatabaseBase implements IDatabase {
                // Although postgres and oracle support schemas, we don't use them (yet)
                // to maintain backwards compatibility
                $defaultSchemas = array(
-                       'mysql' => null,
-                       'postgres' => null,
-                       'sqlite' => null,
-                       'oracle' => null,
                        'mssql' => 'get from global',
                );
 
@@ -932,7 +928,9 @@ abstract class DatabaseBase implements IDatabase {
                        $p['flags'] = isset( $p['flags'] ) ? $p['flags'] : 0;
                        $p['variables'] = isset( $p['variables'] ) ? $p['variables'] : array();
                        $p['tablePrefix'] = isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global';
-                       $p['schema'] = isset( $p['schema'] ) ? $p['schema'] : $defaultSchemas[$dbType];
+                       if ( !isset( $p['schema'] ) ) {
+                               $p['schema'] = isset( $defaultSchemas[$dbType] ) ? $defaultSchemas[$dbType] : null;
+                       }
                        $p['foreign'] = isset( $p['foreign'] ) ? $p['foreign'] : false;
 
                        return new $class( $p );