Merge "API: Remove deprecated response values from action=login"
[lhc/web/wiklou.git] / includes / installer / DatabaseUpdater.php
index 86b2f3b..6f066ce 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup Deployment
  */
+use MediaWiki\MediaWikiServices;
 
 require_once __DIR__ . '/../../maintenance/Maintenance.php';
 
@@ -56,7 +57,7 @@ abstract class DatabaseUpdater {
        /**
         * Handle to the database subclass
         *
-        * @var DatabaseBase
+        * @var Database
         */
        protected $db;
 
@@ -76,6 +77,7 @@ abstract class DatabaseUpdater {
                PopulateBacklinkNamespace::class,
                FixDefaultJsonContentPages::class,
                CleanupEmptyCategories::class,
+               AddRFCAndPMIDInterwiki::class,
        ];
 
        /**
@@ -100,11 +102,11 @@ abstract class DatabaseUpdater {
        /**
         * Constructor
         *
-        * @param DatabaseBase $db To perform updates on
+        * @param Database $db To perform updates on
         * @param bool $shared Whether to perform updates on shared tables
         * @param Maintenance $maintenance Maintenance object which created us
         */
-       protected function __construct( DatabaseBase &$db, $shared, Maintenance $maintenance = null ) {
+       protected function __construct( Database &$db, $shared, Maintenance $maintenance = null ) {
                $this->db = $db;
                $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
                $this->shared = $shared;
@@ -170,14 +172,14 @@ abstract class DatabaseUpdater {
        }
 
        /**
-        * @param DatabaseBase $db
+        * @param Database $db
         * @param bool $shared
         * @param Maintenance $maintenance
         *
         * @throws MWException
         * @return DatabaseUpdater
         */
-       public static function newForDB( &$db, $shared = false, $maintenance = null ) {
+       public static function newForDB( Database $db, $shared = false, $maintenance = null ) {
                $type = $db->getType();
                if ( in_array( $type, Installer::getDBTypes() ) ) {
                        $class = ucfirst( $type ) . 'Updater';
@@ -191,7 +193,7 @@ abstract class DatabaseUpdater {
        /**
         * Get a database connection to run updates
         *
-        * @return DatabaseBase
+        * @return Database
         */
        public function getDB() {
                return $this->db;
@@ -402,6 +404,20 @@ abstract class DatabaseUpdater {
                }
        }
 
+       /**
+        * Get appropriate schema variables in the current database connection.
+        *
+        * This should be called after any request data has been imported, but before
+        * any write operations to the database. The result should be passed to the DB
+        * setSchemaVars() method.
+        *
+        * @return array
+        * @since 1.28
+        */
+       public function getSchemaVars() {
+               return []; // DB-type specific
+       }
+
        /**
         * Do all the updates
         *
@@ -410,6 +426,8 @@ abstract class DatabaseUpdater {
        public function doUpdates( $what = [ 'core', 'extensions', 'stats' ] ) {
                global $wgVersion;
 
+               $this->db->setSchemaVars( $this->getSchemaVars() );
+
                $what = array_flip( $what );
                $this->skipSchema = isset( $what['noschema'] ) || $this->fileHandle !== null;
                if ( isset( $what['core'] ) ) {
@@ -440,6 +458,8 @@ abstract class DatabaseUpdater {
         * @param bool $passSelf Whether to pass this object we calling external functions
         */
        private function runUpdates( array $updates, $passSelf ) {
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+
                $updatesDone = [];
                $updatesSkipped = [];
                foreach ( $updates as $params ) {
@@ -454,7 +474,7 @@ abstract class DatabaseUpdater {
                        flush();
                        if ( $ret !== false ) {
                                $updatesDone[] = $origParams;
-                               wfGetLBFactory()->waitForReplication();
+                               $lbFactory->waitForReplication();
                        } else {
                                $updatesSkipped[] = [ $func, $params, $origParams ];
                        }
@@ -614,7 +634,11 @@ abstract class DatabaseUpdater {
         * @param string $filename File name to open
         */
        public function copyFile( $filename ) {
-               $this->db->sourceFile( $filename, false, false, false,
+               $this->db->sourceFile(
+                       $filename,
+                       null,
+                       null,
+                       __METHOD__,
                        [ $this, 'appendLine' ]
                );
        }
@@ -659,7 +683,7 @@ abstract class DatabaseUpdater {
                $this->output( "$msg ..." );
 
                if ( !$isFullPath ) {
-                       $path = $this->db->patchPath( $path );
+                       $path = $this->patchPath( $this->db, $path );
                }
                if ( $this->fileHandle !== null ) {
                        $this->copyFile( $path );
@@ -671,6 +695,26 @@ abstract class DatabaseUpdater {
                return true;
        }
 
+       /**
+        * Get the full path of a patch file. Originally based on archive()
+        * from updaters.inc. Keep in mind this always returns a patch, as
+        * it fails back to MySQL if no DB-specific patch can be found
+        *
+        * @param IDatabase $db
+        * @param string $patch The name of the patch, like patch-something.sql
+        * @return string Full path to patch file
+        */
+       public function patchPath( IDatabase $db, $patch ) {
+               global $IP;
+
+               $dbType = $db->getType();
+               if ( file_exists( "$IP/maintenance/$dbType/archives/$patch" ) ) {
+                       return "$IP/maintenance/$dbType/archives/$patch";
+               } else {
+                       return "$IP/maintenance/archives/$patch";
+               }
+       }
+
        /**
         * Add a new table to the database
         *
@@ -1078,7 +1122,7 @@ abstract class DatabaseUpdater {
                global $wgProfiler;
 
                if ( !$this->doTable( 'profiling' ) ) {
-                       return true;
+                       return;
                }
 
                $profileToDb = false;