Index: trunk/phase3/maintenance/populateRevisionSha1.php |
— | — | @@ -1,116 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Fills the rev_sha1 and ar_sha1 columns of revision |
5 | | - * and archive tables for revisions created before MW 1.19. |
6 | | - * |
7 | | - * This program is free software; you can redistribute it and/or modify |
8 | | - * it under the terms of the GNU General Public License as published by |
9 | | - * the Free Software Foundation; either version 2 of the License, or |
10 | | - * (at your option) any later version. |
11 | | - * |
12 | | - * This program is distributed in the hope that it will be useful, |
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | - * GNU General Public License for more details. |
16 | | - * |
17 | | - * You should have received a copy of the GNU General Public License along |
18 | | - * with this program; if not, write to the Free Software Foundation, Inc., |
19 | | - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | | - * http://www.gnu.org/copyleft/gpl.html |
21 | | - * |
22 | | - * @ingroup Maintenance |
23 | | - */ |
24 | | - |
25 | | -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
26 | | - |
27 | | -class PopulateRevisionSha1 extends LoggedUpdateMaintenance { |
28 | | - public function __construct() { |
29 | | - parent::__construct(); |
30 | | - $this->mDescription = "Populates the rev_sha1 and ar_sha1 fields"; |
31 | | - $this->setBatchSize( 200 ); |
32 | | - } |
33 | | - |
34 | | - protected function getUpdateKey() { |
35 | | - return 'populate rev_sha1'; |
36 | | - } |
37 | | - |
38 | | - protected function updateSkippedMessage() { |
39 | | - return 'rev_sha1 column of revision table already populated.'; |
40 | | - } |
41 | | - |
42 | | - protected function updatelogFailedMessage() { |
43 | | - return 'Could not insert rev_sha1 population row.'; |
44 | | - } |
45 | | - |
46 | | - protected function doDBUpdates() { |
47 | | - $db = $this->getDB( DB_MASTER ); |
48 | | - if ( !$db->tableExists( 'revision' ) ) { |
49 | | - $this->error( "revision table does not exist", true ); |
50 | | - } |
51 | | - if ( !$db->tableExists( 'archive' ) ) { |
52 | | - $this->error( "archive table does not exist", true ); |
53 | | - } |
54 | | - |
55 | | - $this->output( "Populating rev_sha1 column\n" ); |
56 | | - $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' ); |
57 | | - |
58 | | - $this->output( "Populating ar_sha1 column\n" ); |
59 | | - $ac = $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' ); |
60 | | - |
61 | | - $this->output( "rev_sha1 and ar_sha1 population complete [$rc revision rows, $ac archive rows].\n" ); |
62 | | - return true; |
63 | | - } |
64 | | - |
65 | | - /** |
66 | | - * @return Integer Rows changed |
67 | | - */ |
68 | | - protected function doSha1Updates( $db, $table, $idCol, $prefix ) { |
69 | | - $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ ); |
70 | | - $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ ); |
71 | | - if ( !$start || !$end ) { |
72 | | - $this->output( "...$table table seems to be empty.\n" ); |
73 | | - return true; |
74 | | - } |
75 | | - |
76 | | - $count = 0; |
77 | | - # Do remaining chunk |
78 | | - $end += $this->mBatchSize - 1; |
79 | | - $blockStart = $start; |
80 | | - $blockEnd = $start + $this->mBatchSize - 1; |
81 | | - while ( $blockEnd <= $end ) { |
82 | | - $this->output( "...doing $idCol from $blockStart to $blockEnd\n" ); |
83 | | - $cond = "$idCol BETWEEN $blockStart AND $blockEnd |
84 | | - AND $idCol IS NOT NULL AND {$prefix}_sha1 = ''"; |
85 | | - $res = $db->select( $table, '*', $cond, __METHOD__ ); |
86 | | - |
87 | | - $db->begin(); |
88 | | - foreach ( $res as $row ) { |
89 | | - if ( $table === 'archive' ) { |
90 | | - $rev = Revision::newFromArchiveRow( $row ); |
91 | | - } else { |
92 | | - $rev = new Revision( $row ); |
93 | | - } |
94 | | - $text = $rev->getRawText(); |
95 | | - if ( !is_string( $text ) ) { |
96 | | - # This should not happen, but sometimes does (bug 20757) |
97 | | - $this->output( "Text of revision {$row->$idCol} unavailable!\n" ); |
98 | | - } else { |
99 | | - $db->update( $table, |
100 | | - array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ), |
101 | | - array( $idCol => $row->$idCol ), |
102 | | - __METHOD__ ); |
103 | | - $count++; |
104 | | - } |
105 | | - } |
106 | | - $db->commit(); |
107 | | - |
108 | | - $blockStart += $this->mBatchSize; |
109 | | - $blockEnd += $this->mBatchSize; |
110 | | - wfWaitForSlaves(); |
111 | | - } |
112 | | - return $count; |
113 | | - } |
114 | | -} |
115 | | - |
116 | | -$maintClass = "PopulateRevisionSha1"; |
117 | | -require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/phase3/maintenance/archives/patch-ar_sha1.sql |
— | — | @@ -1,3 +0,0 @@ |
2 | | -ALTER TABLE /*$wgDBprefix*/archive |
3 | | - ADD ar_sha1 varbinary(32) NOT NULL default ''; |
Index: trunk/phase3/maintenance/archives/patch-rev_sha1.sql |
— | — | @@ -1,3 +0,0 @@ |
2 | | -ALTER TABLE /*$wgDBprefix*/revision |
3 | | - ADD rev_sha1 varbinary(32) NOT NULL default ''; |
Index: trunk/phase3/maintenance/populateRevisionLength.php |
— | — | @@ -22,39 +22,29 @@ |
23 | 23 | |
24 | 24 | require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
25 | 25 | |
26 | | -class PopulateRevisionLength extends LoggedUpdateMaintenance { |
| 26 | +class PopulateRevisionLength extends Maintenance { |
27 | 27 | public function __construct() { |
28 | 28 | parent::__construct(); |
29 | | - $this->mDescription = "Populates the rev_len field"; |
| 29 | + $this->mDescription = "Populates rev_len"; |
30 | 30 | $this->setBatchSize( 200 ); |
31 | 31 | } |
32 | 32 | |
33 | | - protected function getUpdateKey() { |
34 | | - return 'populate rev_len'; |
35 | | - } |
36 | | - |
37 | | - protected function updateSkippedMessage() { |
38 | | - return 'rev_len column of revision table already populated.'; |
39 | | - } |
40 | | - |
41 | | - protected function updatelogFailedMessage() { |
42 | | - return 'Could not insert rev_len population row.'; |
43 | | - } |
44 | | - |
45 | | - public function doDBUpdates() { |
| 33 | + public function execute() { |
46 | 34 | $db = $this->getDB( DB_MASTER ); |
47 | 35 | if ( !$db->tableExists( 'revision' ) ) { |
48 | 36 | $this->error( "revision table does not exist", true ); |
49 | 37 | } |
50 | 38 | $this->output( "Populating rev_len column\n" ); |
51 | | - |
52 | | - $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __METHOD__ ); |
53 | | - $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ ); |
54 | | - if ( !$start || !$end ) { |
| 39 | + $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ ); |
| 40 | + $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ ); |
| 41 | + if ( is_null( $start ) || is_null( $end ) ) { |
55 | 42 | $this->output( "...revision table seems to be empty.\n" ); |
56 | | - return true; |
| 43 | + $db->insert( 'updatelog', |
| 44 | + array( 'ul_key' => 'populate rev_len' ), |
| 45 | + __METHOD__, |
| 46 | + 'IGNORE' ); |
| 47 | + return; |
57 | 48 | } |
58 | | - |
59 | 49 | # Do remaining chunks |
60 | 50 | $blockStart = intval( $start ); |
61 | 51 | $blockEnd = intval( $start ) + $this->mBatchSize - 1; |
— | — | @@ -90,9 +80,17 @@ |
91 | 81 | $blockEnd += $this->mBatchSize; |
92 | 82 | wfWaitForSlaves(); |
93 | 83 | } |
94 | | - |
95 | | - $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" ); |
96 | | - return true; |
| 84 | + $logged = $db->insert( 'updatelog', |
| 85 | + array( 'ul_key' => 'populate rev_len' ), |
| 86 | + __METHOD__, |
| 87 | + 'IGNORE' ); |
| 88 | + if ( $logged ) { |
| 89 | + $this->output( "rev_len population complete ... {$count} rows changed ({$missing} missing)\n" ); |
| 90 | + return true; |
| 91 | + } else { |
| 92 | + $this->output( "Could not insert rev_len population row.\n" ); |
| 93 | + return false; |
| 94 | + } |
97 | 95 | } |
98 | 96 | } |
99 | 97 | |
Index: trunk/phase3/maintenance/tables.sql |
— | — | @@ -317,11 +317,8 @@ |
318 | 318 | |
319 | 319 | -- Key to revision.rev_id |
320 | 320 | -- This field is used to add support for a tree structure (The Adjacency List Model) |
321 | | - rev_parent_id int unsigned default NULL, |
| 321 | + rev_parent_id int unsigned default NULL |
322 | 322 | |
323 | | - -- SHA-1 text content hash in base-36 |
324 | | - rev_sha1 varbinary(32) NOT NULL default '' |
325 | | - |
326 | 323 | ) /*$wgDBTableOptions*/ MAX_ROWS=10000000 AVG_ROW_LENGTH=1024; |
327 | 324 | -- In case tables are created as MyISAM, use row hints for MySQL <5.0 to avoid 4GB limit |
328 | 325 | |
— | — | @@ -427,10 +424,7 @@ |
428 | 425 | ar_page_id int unsigned, |
429 | 426 | |
430 | 427 | -- Original previous revision |
431 | | - ar_parent_id int unsigned default NULL, |
432 | | - |
433 | | - -- SHA-1 text content hash in base-36 |
434 | | - ar_sha1 varbinary(32) NOT NULL default '' |
| 428 | + ar_parent_id int unsigned default NULL |
435 | 429 | ) /*$wgDBTableOptions*/; |
436 | 430 | |
437 | 431 | CREATE INDEX /*i*/name_title_timestamp ON /*_*/archive (ar_namespace,ar_title,ar_timestamp); |
Index: trunk/phase3/includes/installer/DatabaseUpdater.php |
— | — | @@ -40,10 +40,7 @@ |
41 | 41 | protected $shared = false; |
42 | 42 | |
43 | 43 | protected $postDatabaseUpdateMaintenance = array( |
44 | | - 'DeleteDefaultMessages', |
45 | | - 'PopulateRevisionLength', |
46 | | - 'PopulateRevisionSha1', |
47 | | - 'PopulateImageSha1' |
| 44 | + 'DeleteDefaultMessages' |
48 | 45 | ); |
49 | 46 | |
50 | 47 | /** |
Index: trunk/phase3/includes/installer/MysqlUpdater.php |
— | — | @@ -158,6 +158,7 @@ |
159 | 159 | array( 'doUpdateTranscacheField' ), |
160 | 160 | array( 'renameEuWikiId' ), |
161 | 161 | array( 'doUpdateMimeMinorField' ), |
| 162 | + array( 'doPopulateRevLen' ), |
162 | 163 | |
163 | 164 | // 1.17 |
164 | 165 | array( 'addTable', 'iwlinks', 'patch-iwlinks.sql' ), |
— | — | @@ -185,8 +186,6 @@ |
186 | 187 | // 1.19 |
187 | 188 | array( 'addTable', 'config', 'patch-config.sql' ), |
188 | 189 | array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql'), |
189 | | - array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ), |
190 | | - array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ) |
191 | 190 | ); |
192 | 191 | } |
193 | 192 | |
— | — | @@ -810,6 +809,16 @@ |
811 | 810 | $this->output( "done.\n" ); |
812 | 811 | } |
813 | 812 | |
| 813 | + protected function doPopulateRevLen() { |
| 814 | + if ( $this->updateRowExists( 'populate rev_len' ) ) { |
| 815 | + $this->output( "...rev_len column already populated.\n" ); |
| 816 | + return; |
| 817 | + } |
| 818 | + |
| 819 | + $task = $this->maintenance->runChild( 'PopulateRevisionLength' ); |
| 820 | + $task->execute(); |
| 821 | + } |
| 822 | + |
814 | 823 | protected function doClFieldsUpdate() { |
815 | 824 | if ( $this->updateRowExists( 'cl_fields_update' ) ) { |
816 | 825 | $this->output( "...categorylinks up-to-date.\n" ); |
Index: trunk/phase3/includes/installer/SqliteUpdater.php |
— | — | @@ -62,9 +62,7 @@ |
63 | 63 | |
64 | 64 | // 1.19 |
65 | 65 | array( 'addTable', 'config', 'patch-config.sql' ), |
66 | | - array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql'), |
67 | | - array( 'addField', 'revision', 'rev_sha1', 'patch-rev_sha1.sql' ), |
68 | | - array( 'addField', 'archive', 'ar_sha1', 'patch-ar_sha1.sql' ) |
| 66 | + array( 'addIndex', 'logging', 'type_action', 'patch-logging-type-action-index.sql') |
69 | 67 | ); |
70 | 68 | } |
71 | 69 | |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -833,7 +833,6 @@ |
834 | 834 | 'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc', |
835 | 835 | 'DeleteDefaultMessages' => 'maintenance/deleteDefaultMessages.php', |
836 | 836 | 'FakeMaintenance' => 'maintenance/Maintenance.php', |
837 | | - 'LoggedUpdateMaintenance' => 'maintenance/Maintenance.php', |
838 | 837 | 'Maintenance' => 'maintenance/Maintenance.php', |
839 | 838 | 'PopulateCategory' => 'maintenance/populateCategory.php', |
840 | 839 | 'PopulateImageSha1' => 'maintenance/populateImageSha1.php', |
— | — | @@ -841,7 +840,6 @@ |
842 | 841 | 'PopulateLogUsertext' => 'maintenance/populateLogUsertext.php', |
843 | 842 | 'PopulateParentId' => 'maintenance/populateParentId.php', |
844 | 843 | 'PopulateRevisionLength' => 'maintenance/populateRevisionLength.php', |
845 | | - 'PopulateRevisionSha1' => 'maintenance/populateRevisionSha1.php', |
846 | 844 | 'SevenZipStream' => 'maintenance/7zip.inc', |
847 | 845 | 'Sqlite' => 'maintenance/sqlite.inc', |
848 | 846 | 'UpdateCollation' => 'maintenance/updateCollation.php', |