Merge "Ensure users are able to edit the page after changing the content model"
[lhc/web/wiklou.git] / includes / installer / DatabaseInstaller.php
index 79bd961..4f10367 100644 (file)
@@ -192,7 +192,7 @@ abstract class DatabaseInstaller {
                $this->db->begin( __METHOD__ );
 
                $error = $this->db->sourceFile(
-                       call_user_func( [ $this->db, $sourceFileMethod ] )
+                       call_user_func( [ $this, $sourceFileMethod ], $this->db )
                );
                if ( $error !== true ) {
                        $this->db->reportQueryError( $error, 0, '', __METHOD__ );
@@ -227,6 +227,47 @@ abstract class DatabaseInstaller {
                return $this->stepApplySourceFile( 'getUpdateKeysPath', 'updates', false );
        }
 
+       /**
+        * Return a path to the DBMS-specific SQL file if it exists,
+        * otherwise default SQL file
+        *
+        * @param IDatabase $db
+        * @param string $filename
+        * @return string
+        */
+       private function getSqlFilePath( $db, $filename ) {
+               global $IP;
+
+               $dbmsSpecificFilePath = "$IP/maintenance/" . $db->getType() . "/$filename";
+               if ( file_exists( $dbmsSpecificFilePath ) ) {
+                       return $dbmsSpecificFilePath;
+               } else {
+                       return "$IP/maintenance/$filename";
+               }
+       }
+
+       /**
+        * Return a path to the DBMS-specific schema file,
+        * otherwise default to tables.sql
+        *
+        * @param IDatabase $db
+        * @return string
+        */
+       public function getSchemaPath( $db ) {
+               return $this->getSqlFilePath( $db, 'tables.sql' );
+       }
+
+       /**
+        * Return a path to the DBMS-specific update key file,
+        * otherwise default to update-keys.sql
+        *
+        * @param IDatabase $db
+        * @return string
+        */
+       public function getUpdateKeysPath( $db ) {
+               return $this->getSqlFilePath( $db, 'update-keys.sql' );
+       }
+
        /**
         * Create the tables for each extension the user enabled
         * @return Status
@@ -287,8 +328,15 @@ abstract class DatabaseInstaller {
                if ( !$status->isOK() ) {
                        throw new MWException( __METHOD__ . ': unexpected DB connection error' );
                }
-               LBFactory::setInstance( new LBFactorySingle( [
-                       'connection' => $status->value ] ) );
+
+               \MediaWiki\MediaWikiServices::resetGlobalInstance();
+               $services = \MediaWiki\MediaWikiServices::getInstance();
+
+               $connection = $status->value;
+               $services->redefineService( 'DBLoadBalancerFactory', function() use ( $connection ) {
+                       return LBFactorySingle::newFromConnection( $connection );
+               } );
+
        }
 
        /**