Merge "Translate ApiHelp, ApiSandbox and Autoblocklist to Spanish"
[lhc/web/wiklou.git] / includes / installer / DatabaseUpdater.php
index 04132ad..ba10278 100644 (file)
@@ -136,7 +136,7 @@ abstract class DatabaseUpdater {
                        $wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
 
                # For extensions only, should be populated via hooks
-               # $wgDBtype should be checked to specifiy the proper file
+               # $wgDBtype should be checked to specify the proper file
                $wgExtNewTables = []; // table, dir
                $wgExtNewFields = []; // table, column, dir
                $wgExtPGNewFields = []; // table, column, column attributes; for PostgreSQL
@@ -974,6 +974,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
         *
@@ -1257,10 +1282,15 @@ abstract class DatabaseUpdater {
         * @since 1.31
         */
        protected function migrateArchiveText() {
-               $this->output( "Migrating archive ar_text to modern storage.\n" );
-               $task = $this->maintenance->runChild( MigrateArchiveText::class, 'migrateArchiveText.php' );
-               $task->execute();
-               $this->output( "done.\n" );
+               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' );
+                       $task->setForce();
+                       if ( $task->execute() ) {
+                               $this->applyPatch( 'patch-drop-ar_text.sql', false,
+                                       'Dropping ar_text and ar_flags columns' );
+                       }
+               }
        }
 
        /**
@@ -1282,4 +1312,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" );
+               }
+       }
 }