Index: trunk/phase3/maintenance/populateRevisionSha1.php |
— | — | @@ -36,31 +36,33 @@ |
37 | 37 | |
38 | 38 | protected function doDBUpdates() { |
39 | 39 | $db = $this->getDB( DB_MASTER ); |
| 40 | + |
40 | 41 | if ( !$db->tableExists( 'revision' ) ) { |
41 | 42 | $this->error( "revision table does not exist", true ); |
42 | | - } |
43 | | - if ( !$db->tableExists( 'archive' ) ) { |
| 43 | + } elseif ( !$db->tableExists( 'archive' ) ) { |
44 | 44 | $this->error( "archive table does not exist", true ); |
45 | 45 | } |
46 | 46 | |
47 | 47 | $this->output( "Populating rev_sha1 column\n" ); |
48 | | - $rc = $this->doSha1Updates( $db, 'revision', 'rev_id', 'rev' ); |
| 48 | + $rc = $this->doSha1Updates( 'revision', 'rev_id', 'rev' ); |
49 | 49 | |
50 | 50 | $this->output( "Populating ar_sha1 column\n" ); |
51 | | - $ac = $this->doSha1Updates( $db, 'archive', 'ar_rev_id', 'ar' ); |
| 51 | + $ac = $this->doSha1Updates( 'archive', 'ar_rev_id', 'ar' ); |
| 52 | + $this->output( "Populating ar_sha1 column legacy rows\n" ); |
| 53 | + $ac += $this->doSha1LegacyUpdates(); |
52 | 54 | |
53 | 55 | $this->output( "rev_sha1 and ar_sha1 population complete [$rc revision rows, $ac archive rows].\n" ); |
54 | 56 | return true; |
55 | 57 | } |
56 | 58 | |
57 | 59 | /** |
58 | | - * @param $db DatabaseBase |
59 | 60 | * @param $table string |
60 | 61 | * @param $idCol |
61 | 62 | * @param $prefix string |
62 | 63 | * @return Integer Rows changed |
63 | 64 | */ |
64 | | - protected function doSha1Updates( $db, $table, $idCol, $prefix ) { |
| 65 | + protected function doSha1Updates( $table, $idCol, $prefix ) { |
| 66 | + $db = $this->getDB( DB_MASTER ); |
65 | 67 | $start = $db->selectField( $table, "MIN($idCol)", false, __METHOD__ ); |
66 | 68 | $end = $db->selectField( $table, "MAX($idCol)", false, __METHOD__ ); |
67 | 69 | if ( !$start || !$end ) { |
— | — | @@ -81,20 +83,7 @@ |
82 | 84 | |
83 | 85 | $db->begin(); |
84 | 86 | foreach ( $res as $row ) { |
85 | | - if ( $table === 'archive' ) { |
86 | | - $rev = Revision::newFromArchiveRow( $row ); |
87 | | - } else { |
88 | | - $rev = new Revision( $row ); |
89 | | - } |
90 | | - $text = $rev->getRawText(); |
91 | | - if ( !is_string( $text ) ) { |
92 | | - # This should not happen, but sometimes does (bug 20757) |
93 | | - $this->output( "Text of revision {$row->$idCol} unavailable!\n" ); |
94 | | - } else { |
95 | | - $db->update( $table, |
96 | | - array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ), |
97 | | - array( $idCol => $row->$idCol ), |
98 | | - __METHOD__ ); |
| 87 | + if ( $this->upgradeRow( $row, $db, $table, $idCol, $prefix ) ) { |
99 | 88 | $count++; |
100 | 89 | } |
101 | 90 | } |
— | — | @@ -106,6 +95,50 @@ |
107 | 96 | } |
108 | 97 | return $count; |
109 | 98 | } |
| 99 | + |
| 100 | + protected function doSha1LegacyUpdates() { |
| 101 | + $count = 0; |
| 102 | + $db = $this->getDB( DB_MASTER ); |
| 103 | + $res = $db->select( 'archive', '*', array( 'ar_rev_id IS NULL' ), __METHOD__ ); |
| 104 | + |
| 105 | + $updateSize = 0; |
| 106 | + $db->begin(); |
| 107 | + foreach ( $res as $row ) { |
| 108 | + if ( $this->upgradeRow( $row, 'archive', 'ar_timestamp', 'ar' ) ) { |
| 109 | + ++$count; |
| 110 | + } |
| 111 | + if ( ++$updateSize >= 100 ) { |
| 112 | + $updateSize = 0; |
| 113 | + $db->commit(); |
| 114 | + $this->output( "Commited row with ar_timestamp={$row->ar_timestamp}\n" ); |
| 115 | + wfWaitForSlaves(); |
| 116 | + $db->begin(); |
| 117 | + } |
| 118 | + } |
| 119 | + $db->commit(); |
| 120 | + } |
| 121 | + |
| 122 | + protected function upgradeRow( $row, $table, $idCol, $prefix ) { |
| 123 | + $db = $this->getDB( DB_MASTER ); |
| 124 | + if ( $table === 'archive' ) { |
| 125 | + $rev = Revision::newFromArchiveRow( $row ); |
| 126 | + } else { |
| 127 | + $rev = new Revision( $row ); |
| 128 | + } |
| 129 | + $text = $rev->getRawText(); |
| 130 | + if ( !is_string( $text ) ) { |
| 131 | + # This should not happen, but sometimes does (bug 20757) |
| 132 | + $this->output( "Text of revision with {$idCol}={$row->$idCol} unavailable!\n" ); |
| 133 | + return false; |
| 134 | + } else { |
| 135 | + $db->update( $table, |
| 136 | + array( "{$prefix}_sha1" => Revision::base36Sha1( $text ) ), |
| 137 | + array( $idCol => $row->$idCol ), |
| 138 | + __METHOD__ |
| 139 | + ); |
| 140 | + return true; |
| 141 | + } |
| 142 | + } |
110 | 143 | } |
111 | 144 | |
112 | 145 | $maintClass = "PopulateRevisionSha1"; |