Index: trunk/extensions/FlaggedRevs/maintenance/updateTracking.php |
— | — | @@ -6,22 +6,23 @@ |
7 | 7 | $IP = dirname(__FILE__).'/../../..'; |
8 | 8 | } |
9 | 9 | |
10 | | -$options = array( 'updateonly', 'help', 'start' ); |
| 10 | +$options = array( 'updateonly', 'help', 'startrev', 'startpage' ); |
11 | 11 | require "$IP/maintenance/commandLine.inc"; |
12 | 12 | require dirname(__FILE__) . '/updateTracking.inc'; |
13 | 13 | |
14 | | -if( isset($options['help']) ) { |
| 14 | +if ( isset($options['help']) ) { |
15 | 15 | echo <<<TEXT |
16 | 16 | Purpose: |
17 | | - Correct the data in the flaggedrevs tracking tables and |
18 | | - remove any extraneous template/file inclusion data. |
| 17 | + Correct the page data in the flaggedrevs tracking tables. |
| 18 | + Update the quality tier of revisions based on their rating tags. |
| 19 | + Migrate flagged revision file version data to proper table. |
19 | 20 | Usage: |
20 | 21 | php updateLinks.php --help |
21 | | - php updateLinks.php [--start <ID> | --updateonly <CALL> ] |
| 22 | + php updateLinks.php [--startpage <ID> | --startrev <ID> | --updateonly <CALL> ] |
22 | 23 | |
23 | 24 | --help : This help message |
24 | | - --<ID> : The ID of the starting rev |
25 | | - --<CALL> : One of revs,pages,templates, or images |
| 25 | + --<ID> : The ID of the starting rev/page |
| 26 | + --<CALL> : One of (revs, pages) |
26 | 27 | |
27 | 28 | TEXT; |
28 | 29 | exit(0); |
— | — | @@ -29,20 +30,27 @@ |
30 | 31 | |
31 | 32 | error_reporting( E_ALL ); |
32 | 33 | |
33 | | -$start = isset($options['start']) ? $options['start'] : null; |
34 | | -$updateonly = isset($options['updateonly']) ? $options['updateonly'] : null; |
| 34 | +$startPage = isset( $options['startpage'] ) ? |
| 35 | + (int)$options['startpage'] : null; |
| 36 | +$startRev = isset( $options['startrev'] ) ? |
| 37 | + (int)$options['startrev'] : null; |
| 38 | +$updateonly = isset( $options['updateonly'] ) ? |
| 39 | + $options['updateonly'] : null; |
35 | 40 | |
36 | | -$actions = array( 'revs', 'pages', 'templates', 'images' ); |
37 | | -if( $updateonly && in_array($updateonly,$actions) ) { |
38 | | - $do = "update_flagged{$updateonly}"; |
39 | | - $do($start); |
40 | | - exit(0); |
| 41 | +if ( $updateonly ) { |
| 42 | + switch ( $updateonly ) { |
| 43 | + case 'revs': |
| 44 | + update_flaggedrevs( $startRev ); |
| 45 | + break; |
| 46 | + case 'pages': |
| 47 | + update_flaggedpages( $startPage ); |
| 48 | + break; |
| 49 | + default: |
| 50 | + echo "Invalidate operation specified.\n"; |
| 51 | + } |
| 52 | + exit( 0 ); |
41 | 53 | } |
42 | 54 | |
43 | | -update_flaggedrevs($start); |
| 55 | +update_flaggedrevs( $startRev ); |
44 | 56 | |
45 | | -update_flaggedpages(); |
46 | | - |
47 | | -update_flaggedtemplates($start); |
48 | | - |
49 | | -update_flaggedimages($start); |
| 57 | +update_flaggedpages( $startPage ); |
Index: trunk/extensions/FlaggedRevs/maintenance/updateTracking.inc |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | function update_flaggedrevs( $start = null ) { |
5 | 5 | echo "Populating and correcting flaggedrevs columns\n"; |
6 | 6 | |
7 | | - $BATCH_SIZE = 500; |
| 7 | + $BATCH_SIZE = 1000; |
8 | 8 | |
9 | 9 | $db = wfGetDB( DB_MASTER ); |
10 | 10 | |
— | — | @@ -28,7 +28,9 @@ |
29 | 29 | $res = $db->select( array('revision','flaggedrevs','page'), |
30 | 30 | array('fr_rev_id','fr_tags','fr_quality','page_namespace','page_title', |
31 | 31 | 'fr_img_name','fr_img_timestamp','fr_img_sha1','rev_page'), |
32 | | - $cond, __FUNCTION__ ); |
| 32 | + $cond, __FUNCTION__ |
| 33 | + ); |
| 34 | + $db->begin(); |
33 | 35 | # Go through and clean up missing items, as well as correct fr_quality... |
34 | 36 | foreach( $res as $row ) { |
35 | 37 | $tags = FlaggedRevision::expandRevisionTags( $row->fr_tags ); |
— | — | @@ -70,20 +72,20 @@ |
71 | 73 | || $sha1 != $row->fr_img_sha1 |
72 | 74 | || $time != $row->fr_img_timestamp ) |
73 | 75 | { |
| 76 | + # Update the row... |
| 77 | + $db->update( 'flaggedrevs', |
| 78 | + array( 'fr_quality' => $quality, |
| 79 | + 'fr_img_name' => $file, |
| 80 | + 'fr_img_sha1' => $sha1, |
| 81 | + 'fr_img_timestamp' => $time ), |
| 82 | + array( 'fr_rev_id' => $row->fr_rev_id, 'fr_page_id' => $row->rev_page ), |
| 83 | + __FUNCTION__ |
| 84 | + ); |
74 | 85 | $changed++; |
75 | 86 | } |
76 | | - # Update the row... |
77 | | - $db->begin(); |
78 | | - $db->update( 'flaggedrevs', |
79 | | - array( 'fr_quality' => $quality, |
80 | | - 'fr_img_name' => $file, |
81 | | - 'fr_img_sha1' => $sha1, |
82 | | - 'fr_img_timestamp' => $time ), |
83 | | - array( 'fr_rev_id' => $row->fr_rev_id, 'fr_page_id' => $row->rev_page ), |
84 | | - __FUNCTION__ ); |
85 | | - $db->commit(); |
86 | 87 | $count++; |
87 | 88 | } |
| 89 | + $db->commit(); |
88 | 90 | $db->freeResult( $res ); |
89 | 91 | $blockStart += $BATCH_SIZE; |
90 | 92 | $blockEnd += $BATCH_SIZE; |
— | — | @@ -99,7 +101,9 @@ |
100 | 102 | |
101 | 103 | $db = wfGetDB( DB_MASTER ); |
102 | 104 | |
103 | | - $start = $start ? $start : $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
| 105 | + if( $start === null ) { |
| 106 | + $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
| 107 | + } |
104 | 108 | $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ ); |
105 | 109 | if( is_null( $start ) || is_null( $end ) ){ |
106 | 110 | echo "...flaggedpages table seems to be empty.\n"; |
— | — | @@ -138,8 +142,9 @@ |
139 | 143 | # Correct page_latest if needed (import/files made plenty of bad rows) |
140 | 144 | if( $revRow ) { |
141 | 145 | $revision = new Revision( $revRow ); |
142 | | - if( $article->updateIfNewerOn( $db, $revision ) ) |
| 146 | + if( $article->updateIfNewerOn( $db, $revision ) ) { |
143 | 147 | $fixed++; |
| 148 | + } |
144 | 149 | } |
145 | 150 | $count++; |
146 | 151 | } |
— | — | @@ -161,107 +166,3 @@ |
162 | 167 | } |
163 | 168 | echo "flaggedpage columns update complete ... {$count} rows [{$fixed} fixed] [{$deleted} deleted]\n"; |
164 | 169 | } |
165 | | - |
166 | | -function update_flaggedtemplates( $start = null ) { |
167 | | - echo "Removing unreferenced flaggedtemplates columns\n"; |
168 | | - |
169 | | - $BATCH_SIZE = 500; |
170 | | - |
171 | | - $db = wfGetDB( DB_MASTER ); |
172 | | - |
173 | | - if( $start === null ) { |
174 | | - $start = $db->selectField( 'flaggedtemplates', 'MIN(ft_rev_id)', false, __FUNCTION__ ); |
175 | | - } |
176 | | - $end = $db->selectField( 'flaggedtemplates', 'MAX(ft_rev_id)', false, __FUNCTION__ ); |
177 | | - if( is_null( $start ) || is_null( $end ) ){ |
178 | | - echo "...flaggedtemplates table seems to be empty.\n"; |
179 | | - return; |
180 | | - } |
181 | | - # Do remaining chunk |
182 | | - $end += $BATCH_SIZE - 1; |
183 | | - $blockStart = $start; |
184 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
185 | | - $count = 0; |
186 | | - $deleted = 0; |
187 | | - while( $blockEnd <= $end ) { |
188 | | - echo "...doing ft_rev_id from $blockStart to $blockEnd\n"; |
189 | | - $cond = "ft_rev_id BETWEEN $blockStart AND $blockEnd"; |
190 | | - $res = $db->select( 'flaggedtemplates', array('ft_rev_id'), $cond, __FUNCTION__ ); |
191 | | - # Go through and update the de-normalized references... |
192 | | - foreach( $res as $row ) { |
193 | | - $revision = Revision::newFromId( $row->ft_rev_id ); |
194 | | - # Replaces new fields into flaggedpages |
195 | | - $frev = $revision |
196 | | - ? FlaggedRevision::newFromTitle( $revision->getTitle(), $row->ft_rev_id ) |
197 | | - : null; |
198 | | - # Somethings broke? Delete the row... |
199 | | - if( !$frev ) { |
200 | | - $db->begin(); |
201 | | - $db->delete( 'flaggedtemplates', |
202 | | - array( 'ft_rev_id' => $row->ft_rev_id ), |
203 | | - __FUNCTION__ ); |
204 | | - if( $db->affectedRows() > 0 ) |
205 | | - $deleted++; |
206 | | - $db->commit(); |
207 | | - } |
208 | | - $count++; |
209 | | - } |
210 | | - $db->freeResult( $res ); |
211 | | - $blockStart += $BATCH_SIZE; |
212 | | - $blockEnd += $BATCH_SIZE; |
213 | | - wfWaitForSlaves( 5 ); |
214 | | - } |
215 | | - echo "flaggedtemplates columns update complete ... {$count} rows [{$deleted} deleted]\n"; |
216 | | -} |
217 | | - |
218 | | -function update_flaggedimages( $start = null ) { |
219 | | - echo "Removing unreferenced flaggedimages columns\n"; |
220 | | - |
221 | | - $BATCH_SIZE = 500; |
222 | | - |
223 | | - $db = wfGetDB( DB_MASTER ); |
224 | | - |
225 | | - if( $start === null ) { |
226 | | - $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __FUNCTION__ ); |
227 | | - } |
228 | | - $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, __FUNCTION__ ); |
229 | | - if( is_null( $start ) || is_null( $end ) ){ |
230 | | - echo "...flaggedimages table seems to be empty.\n"; |
231 | | - return; |
232 | | - } |
233 | | - # Do remaining chunk |
234 | | - $end += $BATCH_SIZE - 1; |
235 | | - $blockStart = $start; |
236 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
237 | | - $count = 0; |
238 | | - $deleted = 0; |
239 | | - while( $blockEnd <= $end ) { |
240 | | - echo "...doing fi_rev_id from $blockStart to $blockEnd\n"; |
241 | | - $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd"; |
242 | | - $res = $db->select( 'flaggedimages', array('fi_rev_id'), $cond, __FUNCTION__ ); |
243 | | - # Go through and update the de-normalized references... |
244 | | - foreach( $res as $row ) { |
245 | | - $revision = Revision::newFromId( $row->fi_rev_id ); |
246 | | - # Replaces new fields into flaggedpages |
247 | | - $frev = $revision |
248 | | - ? FlaggedRevision::newFromTitle( $revision->getTitle(), $row->fi_rev_id ) |
249 | | - : null; |
250 | | - # Somethings broke? Delete the row... |
251 | | - if( !$frev ) { |
252 | | - $db->begin(); |
253 | | - $db->delete( 'flaggedimages', |
254 | | - array( 'fi_rev_id' => $row->fi_rev_id ), |
255 | | - __FUNCTION__ ); |
256 | | - if( $db->affectedRows() > 0 ) |
257 | | - $deleted++; |
258 | | - $db->commit(); |
259 | | - } |
260 | | - $count++; |
261 | | - } |
262 | | - $db->freeResult( $res ); |
263 | | - $blockStart += $BATCH_SIZE; |
264 | | - $blockEnd += $BATCH_SIZE; |
265 | | - wfWaitForSlaves( 5 ); |
266 | | - } |
267 | | - echo "flaggedtemplates columns update complete ... {$count} rows [{$deleted} deleted]\n"; |
268 | | -} |