Merge "StringUtils: Add a utility for checking if a string is a valid regex"
[lhc/web/wiklou.git] / includes / installer / DatabaseUpdater.php
index de7a347..3412aef 100644 (file)
@@ -419,6 +419,7 @@ abstract class DatabaseUpdater {
 
                foreach ( $updates as $funcList ) {
                        list( $func, $args, $origParams ) = $funcList;
+                       // @phan-suppress-next-line PhanUndeclaredInvokeInCallable
                        $func( ...$args );
                        flush();
                        $this->updatesSkipped[] = $origParams;
@@ -1232,6 +1233,7 @@ abstract class DatabaseUpdater {
                $cl = $this->maintenance->runChild(
                        RebuildLocalisationCache::class, 'rebuildLocalisationCache.php'
                );
+               '@phan-var RebuildLocalisationCache $cl';
                $this->output( "Rebuilding localisation cache...\n" );
                $cl->setForce();
                $cl->execute();
@@ -1291,6 +1293,7 @@ abstract class DatabaseUpdater {
                        $task = $this->maintenance->runChild(
                                MigrateImageCommentTemp::class, 'migrateImageCommentTemp.php'
                        );
+                       // @phan-suppress-next-line PhanUndeclaredMethod
                        $task->setForce();
                        $ok = $task->execute();
                        $this->output( $ok ? "done.\n" : "errors were encountered.\n" );
@@ -1305,10 +1308,7 @@ abstract class DatabaseUpdater {
         * @since 1.31
         */
        protected function migrateActors() {
-               global $wgActorTableSchemaMigrationStage;
-               if ( ( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) &&
-                       !$this->updateRowExists( 'MigrateActors' )
-               ) {
+               if ( !$this->updateRowExists( 'MigrateActors' ) ) {
                        $this->output(
                                "Migrating actors to the 'actor' table, printing progress markers. For large\n" .
                                "databases, you may want to hit Ctrl-C and do this manually with\n" .
@@ -1328,6 +1328,7 @@ abstract class DatabaseUpdater {
                if ( $this->db->fieldExists( 'archive', 'ar_text', __METHOD__ ) ) {
                        $this->output( "Migrating archive ar_text to modern storage.\n" );
                        $task = $this->maintenance->runChild( MigrateArchiveText::class, 'migrateArchiveText.php' );
+                       // @phan-suppress-next-line PhanUndeclaredMethod
                        $task->setForce();
                        if ( $task->execute() ) {
                                $this->applyPatch( 'patch-drop-ar_text.sql', false,
@@ -1397,4 +1398,43 @@ abstract class DatabaseUpdater {
                        }
                }
        }
+
+       /**
+        * Only run a function if the `actor` table does not exist
+        *
+        * The transition to the actor table is dropping several indexes (and a few
+        * fields) that old upgrades want to add. This function is used to prevent
+        * those from running to re-add things when the `actor` table exists, while
+        * still allowing them to run if this really is an upgrade from an old MW
+        * version.
+        *
+        * @since 1.34
+        * @param string|array|static $func Normally this is the string naming the method on $this to
+        *  call. It may also be an array callable. If passed $this, it's assumed to be a call from
+        *  runUpdates() with $passSelf = true: $params[0] is assumed to be the real $func and $this
+        *  is prepended to the rest of $params.
+        * @param mixed ...$params Parameters for `$func`
+        * @return mixed Whatever $func returns, or null when skipped.
+        */
+       protected function ifNoActorTable( $func, ...$params ) {
+               if ( $this->tableExists( 'actor' ) ) {
+                       return null;
+               }
+
+               // Handle $passSelf from runUpdates().
+               $passSelf = false;
+               if ( $func === $this ) {
+                       $passSelf = true;
+                       $func = array_shift( $params );
+               }
+
+               if ( !is_array( $func ) && method_exists( $this, $func ) ) {
+                       $func = [ $this, $func ];
+               } elseif ( $passSelf ) {
+                       array_unshift( $params, $this );
+               }
+
+               // @phan-suppress-next-line PhanUndeclaredInvokeInCallable Phan is confused
+               return $func( ...$params );
+       }
 }