Merge "[search] Fix method call on null value"
[lhc/web/wiklou.git] / includes / filerepo / ForeignDBRepo.php
index 6e9e6ad..283576a 100644 (file)
@@ -72,33 +72,44 @@ class ForeignDBRepo extends LocalRepo {
        }
 
        /**
-        * @return DatabaseBase
+        * @return IDatabase
         */
        function getMasterDB() {
                if ( !isset( $this->dbConn ) ) {
-                       $this->dbConn = DatabaseBase::factory( $this->dbType,
-                               array(
-                                       'host' => $this->dbServer,
-                                       'user' => $this->dbUser,
-                                       'password' => $this->dbPassword,
-                                       'dbname' => $this->dbName,
-                                       'flags' => $this->dbFlags,
-                                       'tablePrefix' => $this->tablePrefix,
-                                       'foreign' => true,
-                               )
-                       );
+                       $func = $this->getDBFactory();
+                       $this->dbConn = $func( DB_MASTER );
                }
 
                return $this->dbConn;
        }
 
        /**
-        * @return DatabaseBase
+        * @return IDatabase
         */
        function getSlaveDB() {
                return $this->getMasterDB();
        }
 
+       /**
+        * @return Closure
+        */
+       protected function getDBFactory() {
+               $type = $this->dbType;
+               $params = array(
+                       'host' => $this->dbServer,
+                       'user' => $this->dbUser,
+                       'password' => $this->dbPassword,
+                       'dbname' => $this->dbName,
+                       'flags' => $this->dbFlags,
+                       'tablePrefix' => $this->tablePrefix,
+                       'foreign' => true,
+               );
+
+               return function ( $index ) use ( $type, $params ) {
+                       return DatabaseBase::factory( $type, $params );
+               };
+       }
+
        /**
         * @return bool
         */