Merge "Do not require titles on Special:ComparePages"
[lhc/web/wiklou.git] / includes / installer / DatabaseUpdater.php
index 1f6110b..1cd76b9 100644 (file)
@@ -82,7 +82,7 @@ abstract class DatabaseUpdater {
                PopulateBacklinkNamespace::class,
                FixDefaultJsonContentPages::class,
                CleanupEmptyCategories::class,
-               AddRFCAndPMIDInterwiki::class,
+               AddRFCandPMIDInterwiki::class,
                PopulatePPSortKey::class,
                PopulateIpChanges::class,
        ];
@@ -410,9 +410,9 @@ abstract class DatabaseUpdater {
 
                foreach ( $updates as $funcList ) {
                        $func = $funcList[0];
-                       $arg = $funcList[1];
+                       $args = $funcList[1];
                        $origParams = $funcList[2];
-                       call_user_func_array( $func, $arg );
+                       $func( ...$args );
                        flush();
                        $this->updatesSkipped[] = $origParams;
                }
@@ -479,7 +479,7 @@ abstract class DatabaseUpdater {
                        } elseif ( $passSelf ) {
                                array_unshift( $params, $this );
                        }
-                       $ret = call_user_func_array( $func, $params );
+                       $ret = $func( ...$params );
                        flush();
                        if ( $ret !== false ) {
                                $updatesDone[] = $origParams;
@@ -779,6 +779,39 @@ abstract class DatabaseUpdater {
                return true;
        }
 
+       /**
+        * Add a new index to an existing table if none of the given indexes exist
+        *
+        * @param string $table Name of the table to modify
+        * @param string[] $indexes Name of the indexes to check. $indexes[0] should
+        *  be the one actually being added.
+        * @param string $patch Path to the patch file
+        * @param bool $fullpath Whether to treat $patch path as a relative or not
+        * @return bool False if this was skipped because schema changes are skipped
+        */
+       protected function addIndexIfNoneExist( $table, $indexes, $patch, $fullpath = false ) {
+               if ( !$this->doTable( $table ) ) {
+                       return true;
+               }
+
+               if ( !$this->db->tableExists( $table, __METHOD__ ) ) {
+                       $this->output( "...skipping: '$table' table doesn't exist yet.\n" );
+                       return true;
+               }
+
+               $newIndex = $indexes[0];
+               foreach ( $indexes as $index ) {
+                       if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) {
+                               $this->output(
+                                       "...skipping index $newIndex because index $index already set on $table table.\n"
+                               );
+                               return true;
+                       }
+               }
+
+               return $this->applyPatch( $patch, $fullpath, "Adding index $index to table $table" );
+       }
+
        /**
         * Drop a field from an existing table
         *
@@ -974,6 +1007,31 @@ abstract class DatabaseUpdater {
                return true;
        }
 
+       /**
+        * Run a maintenance script
+        *
+        * This should only be used when the maintenance script must run before
+        * later updates. If later updates don't depend on the script, add it to
+        * DatabaseUpdater::$postDatabaseUpdateMaintenance instead.
+        *
+        * The script's execute() method must return true to indicate successful
+        * completion, and must return false (or throw an exception) to indicate
+        * unsuccessful completion.
+        *
+        * @since 1.32
+        * @param string $class Maintenance subclass
+        * @param string $script Script path and filename, usually "maintenance/fooBar.php"
+        */
+       public function runMaintenance( $class, $script ) {
+               $this->output( "Running $script...\n" );
+               $task = $this->maintenance->runChild( $class );
+               $ok = $task->execute();
+               if ( !$ok ) {
+                       throw new RuntimeException( "Execution of $script did not complete successfully." );
+               }
+               $this->output( "done.\n" );
+       }
+
        /**
         * Set any .htaccess files or equivilent for storage repos
         *
@@ -1287,4 +1345,21 @@ abstract class DatabaseUpdater {
                 }
         }
 
+       /**
+        * Populates the externallinks.el_index_60 field
+        * @since 1.32
+        */
+       protected function populateExternallinksIndex60() {
+               if ( !$this->updateRowExists( 'populate externallinks.el_index_60' ) ) {
+                       $this->output(
+                               "Populating el_index_60 field, printing progress markers. For large\n" .
+                               "databases, you may want to hit Ctrl-C and do this manually with\n" .
+                               "maintenance/populateExternallinksIndex60.php.\n"
+                       );
+                       $task = $this->maintenance->runChild( 'PopulateExternallinksIndex60',
+                               'populateExternallinksIndex60.php' );
+                       $task->execute();
+                       $this->output( "done.\n" );
+               }
+       }
 }