* Added rev_sha1 and ar_sha1 columns to revision/archive tables (useful for bug 25312)
[lhc/web/wiklou.git] / includes / installer / MysqlUpdater.php
index 4550e05..f95351f 100644 (file)
@@ -8,12 +8,12 @@
 
 /**
  * Mysql update list and mysql-specific update functions.
- * 
+ *
  * @ingroup Deployment
  * @since 1.17
  */
 class MysqlUpdater extends DatabaseUpdater {
-       
+
        protected function getCoreUpdateList() {
                return array(
                        // 1.2
@@ -147,8 +147,9 @@ class MysqlUpdater extends DatabaseUpdater {
                        // 1.16
                        array( 'addTable', 'user_properties',                   'patch-user_properties.sql' ),
                        array( 'addTable', 'log_search',                        'patch-log_search.sql' ),
-                       array( 'doLogSearchPopulation' ),
                        array( 'addField', 'logging',       'log_user_text',    'patch-log_user_text.sql' ),
+                       array( 'doLogUsertextPopulation' ), # listed separately from the previous update because 1.16 was released without this update
+                       array( 'doLogSearchPopulation' ),
                        array( 'addTable', 'l10n_cache',                        'patch-l10n_cache.sql' ),
                        array( 'addTable', 'external_user',                     'patch-external_user.sql' ),
                        array( 'addIndex', 'log_search',    'ls_field_val',     'patch-log_search-rename-index.sql' ),
@@ -161,16 +162,33 @@ class MysqlUpdater extends DatabaseUpdater {
 
                        // 1.17
                        array( 'addTable', 'iwlinks',                           'patch-iwlinks.sql' ),
+                       array( 'addTable', 'user_former_groups',                'patch-user_former_groups.sql'),
                        array( 'addIndex', 'iwlinks', 'iwl_prefix_title_from',  'patch-rename-iwl_prefix.sql' ),
-                       array( 'addField', 'updatelog', 'ul_value',              'patch-ul_value.sql' ),
+                       array( 'addField', 'updatelog',     'ul_value',         'patch-ul_value.sql' ),
                        array( 'addField', 'interwiki',     'iw_api',           'patch-iw_api_and_wikiid.sql' ),
-                       array( 'dropIndex', 'iwlinks', 'iwl_prefix',  'patch-kill-iwl_prefix.sql' ),
-                       array( 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ),
-                       array( 'addField', 'categorylinks', 'cl_collation', 'patch-categorylinks-better-collation.sql' ),
+                       array( 'dropIndex', 'iwlinks',      'iwl_prefix',       'patch-kill-iwl_prefix.sql' ),
+                       array( 'dropIndex', 'iwlinks',      'iwl_prefix_from_title', 'patch-kill-iwl_pft.sql' ),
+                       array( 'addField', 'categorylinks', 'cl_collation',     'patch-categorylinks-better-collation.sql' ),
                        array( 'doClFieldsUpdate' ),
                        array( 'doCollationUpdate' ),
                        array( 'addTable', 'msg_resource',                      'patch-msg_resource.sql' ),
                        array( 'addTable', 'module_deps',                       'patch-module_deps.sql' ),
+                       array( 'dropIndex', 'archive',      'ar_page_revid',    'patch-archive_kill_ar_page_revid.sql' ),
+                       array( 'addIndex', 'archive',       'ar_revid',         'patch-archive_ar_revid.sql' ),
+                       array( 'doLangLinksLengthUpdate' ),
+
+                       // 1.18
+                       array( 'doUserNewTalkTimestampNotNull' ),
+                       array( 'addIndex', 'user',          'user_email',       'patch-user_email_index.sql' ),
+                       array( 'modifyField', 'user_properties', 'up_property', 'patch-up_property.sql' ),
+                       array( 'addTable', 'uploadstash',                       'patch-uploadstash.sql' ),
+
+                       // 1.19
+                       array( 'addTable', 'config',                            'patch-config.sql' ),
+                       array( 'addIndex', 'logging',       'type_action',      'patch-logging-type-action-index.sql'),
+                       array( 'addField', 'revision',      'rev_sha1',         'patch-rev_sha1.sql' ),
+                       array( 'addField', 'archive',       'ar_sha1',          'patch-ar_sha1.sql' ),
+                       array( 'doPopulateRevSha1' )
                );
        }
 
@@ -191,8 +209,8 @@ class MysqlUpdater extends DatabaseUpdater {
                        $this->output( "...$table table has correct $field encoding.\n" );
                } else {
                        $this->output( "Fixing $field encoding on $table table... " );
-                       $this->db->applyPatch( $patchFile );
-                       $this->output( "ok\n" );
+                       $this->applyPatch( $patchFile );
+                       $this->output( "done.\n" );
                }
        }
 
@@ -234,7 +252,7 @@ class MysqlUpdater extends DatabaseUpdater {
                $this->output( "ok\n" );
                $this->output( 'Adding default interwiki definitions...' );
                $this->applyPatch( "$IP/maintenance/interwiki.sql", true );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        /**
@@ -242,6 +260,9 @@ class MysqlUpdater extends DatabaseUpdater {
         */
        protected function doIndexUpdate() {
                $meta = $this->db->fieldInfo( 'recentchanges', 'rc_timestamp' );
+               if ( $meta === false ) {
+                       throw new MWException( 'Missing rc_timestamp field of recentchanges table. Should not happen.' );
+               }
                if ( $meta->isMultipleKey() ) {
                        $this->output( "...indexes seem up to 20031107 standards\n" );
                        return;
@@ -249,11 +270,11 @@ class MysqlUpdater extends DatabaseUpdater {
 
                $this->output( "Updating indexes to 20031107..." );
                $this->applyPatch( 'patch-indexes.sql', true );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        protected function doOldLinksUpdate() {
-               $cl = new ConvertLinks();
+               $cl = $this->maintenance->runChild( 'ConvertLinks' );
                $cl->execute();
        }
 
@@ -267,7 +288,7 @@ class MysqlUpdater extends DatabaseUpdater {
                $this->output( "Fixing ancient broken imagelinks table.\n" );
                $this->output( "NOTE: you will have to run maintenance/refreshLinks.php after this.\n" );
                $this->applyPatch( 'patch-fix-il_from.sql' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        /**
@@ -289,7 +310,7 @@ class MysqlUpdater extends DatabaseUpdater {
                                'wl_title' => 'wl_title',
                                'wl_notificationtimestamp' => 'wl_notificationtimestamp'
                        ), array( 'NOT (wl_namespace & 1)' ), __METHOD__, 'IGNORE' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        function doSchemaRestructuring() {
@@ -311,6 +332,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        $this->output( wfTimestamp( TS_DB ) );
                        $this->output( "......<b>Found duplicate entries</b>\n" );
                        $this->output( sprintf( "<b>      %-60s %3s %5s</b>\n", 'Title', 'NS', 'Count' ) );
+                       $duplicate = array();
                        foreach ( $rows as $row ) {
                                if ( ! isset( $duplicate[$row->cur_namespace] ) ) {
                                        $duplicate[$row->cur_namespace] = array();
@@ -355,12 +377,11 @@ class MysqlUpdater extends DatabaseUpdater {
                                $prev_namespace = $row->cur_namespace;
                        }
                        $sql = "DELETE FROM $cur WHERE cur_id IN ( " . join( ',', $deleteId ) . ')';
-                       $rows = $this->db->query( $sql, __METHOD__ );
+                       $this->db->query( $sql, __METHOD__ );
                        $this->output( wfTimestamp( TS_DB ) );
                        $this->output( "......<b>Deleted</b> " . $this->db->affectedRows() . " records.\n" );
                }
 
-
                $this->output( wfTimestamp( TS_DB ) );
                $this->output( "......Creating tables.\n" );
                $this->db->query( "CREATE TABLE $page (
@@ -478,7 +499,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        } else {
                                $this->output( "Promoting $field from $info->Type to int... " );
                                $this->db->query( "ALTER TABLE $tablename MODIFY $field int NOT NULL", __METHOD__ );
-                               $this->output( "ok\n" );
+                               $this->output( "done.\n" );
                        }
                }
        }
@@ -491,7 +512,7 @@ class MysqlUpdater extends DatabaseUpdater {
 
                $this->output( "Converting links and brokenlinks tables to pagelinks... " );
                $this->applyPatch( 'patch-pagelinks.sql' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
 
                global $wgContLang;
                foreach ( MWNamespace::getCanonicalNamespaces() as $ns => $name ) {
@@ -507,18 +528,18 @@ class MysqlUpdater extends DatabaseUpdater {
                        $likeprefix = str_replace( '_', '\\_', $prefix );
 
                        $sql = "UPDATE $pagelinks
-                                  SET pl_namespace=$ns,
-                                      pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
-                                WHERE pl_namespace=0
-                                  AND pl_title LIKE '$likeprefix:%'";
+                                          SET pl_namespace=$ns,
+                                                  pl_title=TRIM(LEADING '$prefix:' FROM pl_title)
+                                        WHERE pl_namespace=0
+                                          AND pl_title LIKE '$likeprefix:%'";
 
                        $this->db->query( $sql, __METHOD__ );
-                       $this->output( "ok\n" );
+                       $this->output( "done.\n" );
                }
        }
 
        protected function doUserUniqueUpdate() {
-               $duper = new UserDupes( $this->db );
+               $duper = new UserDupes( $this->db, array( $this, 'output' ) );
                if ( $duper->hasUniqueIndex() ) {
                        $this->output( "...already have unique user_name index.\n" );
                        return;
@@ -529,7 +550,7 @@ class MysqlUpdater extends DatabaseUpdater {
                }
                $this->output( "Adding unique index on user_name... " );
                $this->applyPatch( 'patch-user_nameindex.sql' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        protected function doUserGroupsUpdate() {
@@ -592,7 +613,7 @@ class MysqlUpdater extends DatabaseUpdater {
                                        __METHOD__ );
                        }
                }
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        /**
@@ -601,14 +622,14 @@ class MysqlUpdater extends DatabaseUpdater {
         */
        protected function doWatchlistNull() {
                $info = $this->db->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
-               if ( $info->nullable() ) {
+               if ( $info->isNullable() ) {
                        $this->output( "...wl_notificationtimestamp is already nullable.\n" );
                        return;
                }
 
                $this->output( "Making wl_notificationtimestamp nullable... " );
                $this->applyPatch( 'patch-watchlist-null.sql' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        /**
@@ -617,13 +638,15 @@ class MysqlUpdater extends DatabaseUpdater {
         * @see bug 3946
         */
        protected function doPageRandomUpdate() {
-               $this->output( "Setting page_random to a random value on rows where it equals 0..." );
-
                $page = $this->db->tableName( 'page' );
                $this->db->query( "UPDATE $page SET page_random = RAND() WHERE page_random = 0", __METHOD__ );
                $rows = $this->db->affectedRows();
 
-               $this->output( "changed $rows rows\n" );
+               if( $rows ) {
+                       $this->output( "Set page_random to a random value on $rows rows where it was set to 0\n" );
+               } else {
+                       $this->output( "...no page_random rows needed to be set\n" );
+               }
        }
 
        protected function doTemplatelinksUpdate() {
@@ -643,7 +666,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        foreach ( $res as $row ) {
                                $count = ( $count + 1 ) % 100;
                                if ( $count == 0 ) {
-                                       wfWaitForSlaves( 10 );
+                                       wfWaitForSlaves();
                                }
                                $this->db->insert( 'templatelinks',
                                        array(
@@ -689,14 +712,14 @@ class MysqlUpdater extends DatabaseUpdater {
                        $this->output( "...page_restrictions table already exists.\n" );
                        return;
                }
-       
+
                $this->output( "Creating page_restrictions table..." );
                $this->applyPatch( 'patch-page_restrictions.sql' );
                $this->applyPatch( 'patch-page_restrictions_sortkey.sql' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
 
                $this->output( "Migrating old restrictions to new table...\n" );
-               $task = new UpdateRestrictions();
+               $task = $this->maintenance->runChild( 'UpdateRestrictions' );
                $task->execute();
        }
 
@@ -719,7 +742,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        "may want to hit Ctrl-C and do this manually with maintenance/\n" .
                        "populateCategory.php.\n"
                );
-               $task = new PopulateCategory();
+               $task = $this->maintenance->runChild( 'PopulateCategory' );
                $task->execute();
                $this->output( "Done populating category table.\n" );
        }
@@ -730,7 +753,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        return;
                }
 
-               $task = new PopulateParentId();
+               $task = $this->maintenance->runChild( 'PopulateParentId' );
                $task->execute();
        }
 
@@ -742,15 +765,16 @@ class MysqlUpdater extends DatabaseUpdater {
                } else {
                        $this->output( "Adding pf_memory field to table profiling..." );
                        $this->applyPatch( 'patch-profiling-memory.sql' );
-                       $this->output( "ok\n" );
+                       $this->output( "done.\n" );
                }
        }
 
        protected function doFilearchiveIndicesUpdate() {
                $info = $this->db->indexInfo( 'filearchive', 'fa_user_timestamp', __METHOD__ );
                if ( !$info ) {
+                       $this->output( "Updating filearchive indices..." );
                        $this->applyPatch( 'patch-filearchive-user-index.sql' );
-                       $this->output( "...filearchive indices updated\n" );
+                       $this->output( "done.\n" );
                }
        }
 
@@ -763,7 +787,7 @@ class MysqlUpdater extends DatabaseUpdater {
 
                $this->output( "Making pl_namespace, tl_namespace and il_to indices UNIQUE... " );
                $this->applyPatch( 'patch-pl-tl-il-unique.sql' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        protected function renameEuWikiId() {
@@ -774,7 +798,7 @@ class MysqlUpdater extends DatabaseUpdater {
 
                $this->output( "Renaming eu_wiki_id -> eu_local_id... " );
                $this->applyPatch( 'patch-eu_local_id.sql' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        protected function doUpdateMimeMinorField() {
@@ -785,7 +809,7 @@ class MysqlUpdater extends DatabaseUpdater {
 
                $this->output( "Altering all *_mime_minor fields to 100 bytes in size ... " );
                $this->applyPatch( 'patch-mime_minor_length.sql' );
-               $this->output( "ok\n" );
+               $this->output( "done.\n" );
        }
 
        protected function doPopulateRevLen() {
@@ -794,7 +818,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        return;
                }
 
-               $task = new PopulateRevisionLength();
+               $task = $this->maintenance->runChild( 'PopulateRevisionLength' );
                $task->execute();
        }
 
@@ -808,4 +832,40 @@ class MysqlUpdater extends DatabaseUpdater {
                $this->applyPatch( 'patch-categorylinks-better-collation2.sql' );
                $this->output( "done.\n" );
        }
+
+       protected function doLangLinksLengthUpdate() {
+               $langlinks = $this->db->tableName( 'langlinks' );
+               $res = $this->db->query( "SHOW COLUMNS FROM $langlinks LIKE 'll_lang'" );
+               $row = $this->db->fetchObject( $res );
+
+               if ( $row && $row->Type == "varbinary(10)" ) {
+                       $this->output( 'Updating length of ll_lang in langlinks...' );
+                       $this->applyPatch( 'patch-langlinks-ll_lang-20.sql' );
+                       $this->output( "done.\n" );
+               } else {
+                       $this->output( "...ll_lang is up-to-date.\n" );
+               }
+       }
+
+       protected function doUserNewTalkTimestampNotNull() {
+               $info = $this->db->fieldInfo( 'user_newtalk', 'user_last_timestamp' );
+               if ( $info->isNullable() ) {
+                       $this->output( "...user_last_timestamp is already nullable.\n" );
+                       return;
+               }
+
+               $this->output( "Making user_last_timestamp nullable... " );
+               $this->applyPatch( 'patch-user-newtalk-timestamp-null.sql' );
+               $this->output( "done.\n" );
+       }
+
+       protected function doPopulateRevSha1() {
+               if ( $this->updateRowExists( 'populate rev_sha1' ) ) {
+                       $this->output( "...rev_sha1/ar_sha1 columns already populated.\n" );
+                       return;
+               }
+
+               $task = $this->maintenance->runChild( 'PopulateRevisionSha1' );
+               $task->execute();
+       }
 }