Set an initial dummy domain in Database::__construct()
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 20 Sep 2016 15:15:39 +0000 (08:15 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 20 Sep 2016 18:05:25 +0000 (18:05 +0000)
This avoids errors when LoadBalancer calls getWikiId() in
reallyOpenConnection() after a failed connection.

Change-Id: Idc3d93ae39be09f2da277df57cdc5a564cb3408d

includes/libs/rdbms/database/Database.php

index a5b9284..901afd1 100644 (file)
@@ -281,6 +281,9 @@ abstract class Database implements IDatabase, LoggerAwareInterface {
                        ? $params['queryLogger']
                        : new \Psr\Log\NullLogger();
 
+               // Set initial dummy domain until open() sets the final DB/prefix
+               $this->currentDomain = DatabaseDomain::newUnspecified();
+
                if ( $user ) {
                        $this->open( $server, $user, $password, $dbName );
                } elseif ( $this->requiresDatabaseUser() ) {
@@ -288,9 +291,10 @@ abstract class Database implements IDatabase, LoggerAwareInterface {
                }
 
                // Set the domain object after open() sets the relevant fields
-               $this->currentDomain = ( $this->mDBname != '' )
-                       ? new DatabaseDomain( $this->mDBname, null, $this->mTablePrefix )
-                       : DatabaseDomain::newUnspecified();
+               if ( $this->mDBname != '' ) {
+                       // Domains with server scope but a table prefix are not used by IDatabase classes
+                       $this->currentDomain = new DatabaseDomain( $this->mDBname, null, $this->mTablePrefix );
+               }
        }
 
        /**