Index: trunk/extensions/FlaggedRevs/maintenance/updateAutoPromote.inc |
— | — | @@ -1,70 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -function update_autopromote() { |
5 | | - global $wgContentNamespaces, $wgFlaggedRevsAutopromote; |
6 | | - $batchSize = 50; |
7 | | - echo "Populating and updating flaggedrevs_promote table\n"; |
8 | | - |
9 | | - $dbr = wfGetDB( DB_SLAVE ); |
10 | | - $dbw = wfGetDB( DB_MASTER ); |
11 | | - $start = $dbr->selectField( 'user', 'MIN(user_id)', false, __FUNCTION__ ); |
12 | | - $end = $dbr->selectField( 'user', 'MAX(user_id)', false, __FUNCTION__ ); |
13 | | - if( is_null( $start ) || is_null( $end ) ){ |
14 | | - echo "...user table seems to be empty.\n"; |
15 | | - return; |
16 | | - } |
17 | | - $count = 0; |
18 | | - $changed = 0; |
19 | | - for ( $blockStart = $start; $blockStart <= $end; $blockStart += $batchSize ) { |
20 | | - $blockEnd = min( $end, $blockStart + $batchSize - 1 ); |
21 | | - echo "...doing user_id from $blockStart to $blockEnd\n"; |
22 | | - $cond = "user_id BETWEEN $blockStart AND $blockEnd\n"; |
23 | | - $res = $dbr->select( 'user', '*', $cond, __FUNCTION__ ); |
24 | | - # Go through and clean up missing items, as well as correct fr_quality... |
25 | | - foreach( $res as $row ) { |
26 | | - $dbw->begin(); |
27 | | - $user = User::newFromRow( $row ); |
28 | | - $p = FRUserCounters::getUserParams( $user->getId(), FR_FOR_UPDATE ); |
29 | | - $oldp = $p; |
30 | | - # Get edit comments used |
31 | | - $sres = $dbr->select( 'revision', '1', |
32 | | - array( 'rev_user' => $user->getID(), |
33 | | - "rev_comment NOT LIKE '/*%*/'" ), // manual comments only |
34 | | - __METHOD__, |
35 | | - array( 'LIMIT' => max($wgFlaggedRevsAutopromote['editComments'],500) ) |
36 | | - ); |
37 | | - $p['editComments'] = $dbr->numRows( $sres ); |
38 | | - # Get content page edits |
39 | | - $sres = $dbr->select( array('revision','page'), '1', |
40 | | - array( 'rev_user' => $user->getID(), |
41 | | - 'page_id = rev_page', |
42 | | - 'page_namespace' => $wgContentNamespaces ), |
43 | | - __METHOD__, |
44 | | - array( 'LIMIT' => max($wgFlaggedRevsAutopromote['totalContentEdits'],500) ) |
45 | | - ); |
46 | | - $p['totalContentEdits'] = $dbr->numRows( $sres ); |
47 | | - # Get unique content pages edited |
48 | | - $sres = $dbr->select( array('revision','page'), 'DISTINCT(rev_page)', |
49 | | - array( 'rev_user' => $user->getID(), |
50 | | - 'page_id = rev_page', |
51 | | - 'page_namespace' => $wgContentNamespaces ), |
52 | | - __METHOD__, |
53 | | - array( 'LIMIT' => max($wgFlaggedRevsAutopromote['uniqueContentPages'],50) ) |
54 | | - ); |
55 | | - $p['uniqueContentPages'] = array(); |
56 | | - foreach( $sres as $row ) { |
57 | | - $p['uniqueContentPages'][] = (int)$row->rev_page; |
58 | | - } |
59 | | - # Save the new params... |
60 | | - if( $oldp != $p ) { |
61 | | - FRUserCounters::saveUserParams( $user->getId(), $p ); |
62 | | - $changed++; |
63 | | - } |
64 | | - |
65 | | - $count++; |
66 | | - $dbw->commit(); |
67 | | - } |
68 | | - wfWaitForSlaves( 5 ); |
69 | | - } |
70 | | - echo "flaggedrevs_promote table update complete ... {$count} rows [{$changed} changed or added]\n"; |
71 | | -} |
Index: trunk/extensions/FlaggedRevs/maintenance/populateRevTimestamp.inc |
— | — | @@ -1,68 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -function populate_fr_rev_timestamp( $start = null ) { |
5 | | - echo "Populating and correcting flaggedrevs columns from $start\n"; |
6 | | - |
7 | | - $BATCH_SIZE = 1000; |
8 | | - |
9 | | - $db = wfGetDB( DB_MASTER ); |
10 | | - |
11 | | - if ( $start === null ) { |
12 | | - $start = $db->selectField( 'flaggedrevs', 'MIN(fr_rev_id)', false, __FUNCTION__ ); |
13 | | - } |
14 | | - $end = $db->selectField( 'flaggedrevs', 'MAX(fr_rev_id)', false, __FUNCTION__ ); |
15 | | - if ( is_null( $start ) || is_null( $end ) ) { |
16 | | - echo "...flaggedrevs table seems to be empty.\n"; |
17 | | - return; |
18 | | - } |
19 | | - # Do remaining chunk |
20 | | - $end += $BATCH_SIZE - 1; |
21 | | - $blockStart = $start; |
22 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
23 | | - $count = 0; |
24 | | - $changed = 0; |
25 | | - while ( $blockEnd <= $end ) { |
26 | | - echo "...doing fr_rev_id from $blockStart to $blockEnd\n"; |
27 | | - $cond = "fr_rev_id BETWEEN $blockStart AND $blockEnd AND fr_rev_timestamp = ''"; |
28 | | - $res = $db->select( |
29 | | - array( 'flaggedrevs', 'revision', 'archive' ), |
30 | | - array( 'fr_rev_id', 'rev_timestamp', 'ar_timestamp' ), |
31 | | - $cond, |
32 | | - __FUNCTION__, |
33 | | - array(), |
34 | | - array( 'revision' => array( 'LEFT JOIN', 'rev_id = fr_rev_id' ), |
35 | | - 'archive' => array( 'LEFT JOIN', 'ar_rev_id = fr_rev_id' ) ) // non-unique but OK |
36 | | - ); |
37 | | - $db->begin(); |
38 | | - # Go through and clean up missing items, as well as correct fr_quality... |
39 | | - foreach ( $res as $row ) { |
40 | | - $timestamp = ''; |
41 | | - if ( $row->rev_timestamp ) { |
42 | | - $timestamp = $row->rev_timestamp; |
43 | | - } elseif ( $row->ar_timestamp ) { |
44 | | - $timestamp = $row->ar_timestamp; |
45 | | - } |
46 | | - if ( $timestamp != '' ) { |
47 | | - # Update the row... |
48 | | - $db->update( 'flaggedrevs', |
49 | | - array( 'fr_rev_timestamp' => $timestamp ), |
50 | | - array( 'fr_rev_id' => $row->fr_rev_id ), |
51 | | - __FUNCTION__ |
52 | | - ); |
53 | | - $changed++; |
54 | | - } |
55 | | - $count++; |
56 | | - } |
57 | | - $db->commit(); |
58 | | - $db->freeResult( $res ); |
59 | | - $blockStart += $BATCH_SIZE; |
60 | | - $blockEnd += $BATCH_SIZE; |
61 | | - wfWaitForSlaves( 5 ); |
62 | | - } |
63 | | - file_put_contents( last_pos_file(), $end ); |
64 | | - echo "fr_rev_timestamp columns update complete ... {$count} rows [{$changed} changed]\n"; |
65 | | -} |
66 | | - |
67 | | -function last_pos_file() { |
68 | | - return dirname( __FILE__ ) . "/popRevTimestampLast-" . wfWikiID(); |
69 | | -} |
Index: trunk/extensions/FlaggedRevs/maintenance/updateQueryCache.inc |
— | — | @@ -1,17 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -if( php_sapi_name() != 'cli' ) { |
5 | | - print( 'Invalid entry' ); |
6 | | - die( 1 ); |
7 | | -} |
8 | | - |
9 | | -function update_flaggedrevs_querycache() { |
10 | | - print sprintf( '%-30s ', 'UnreviewedPages' ); |
11 | | - |
12 | | - $time1 = microtime( true ); |
13 | | - UnreviewedPages::updateQueryCache(); |
14 | | - $time2 = microtime( true ); |
15 | | - |
16 | | - $ellapsed = ( $time2 - $time1 ); |
17 | | - print sprintf( "completed in %.2fs\n", $ellapsed ); |
18 | | -} |
Index: trunk/extensions/FlaggedRevs/maintenance/fixBug28348.inc |
— | — | @@ -1,64 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -function update_images_bug_28348( $start = null ) { |
5 | | - echo "Correcting fi_img_timestamp column in flaggedimages\n"; |
6 | | - |
7 | | - $BATCH_SIZE = 1000; |
8 | | - |
9 | | - $db = wfGetDB( DB_MASTER ); |
10 | | - |
11 | | - if( $start === null ) { |
12 | | - $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __FUNCTION__ ); |
13 | | - } |
14 | | - $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, __FUNCTION__ ); |
15 | | - if( is_null( $start ) || is_null( $end ) ) { |
16 | | - echo "...flaggedimages table seems to be empty.\n"; |
17 | | - return; |
18 | | - } |
19 | | - # Do remaining chunk |
20 | | - $end += $BATCH_SIZE - 1; |
21 | | - $blockStart = $start; |
22 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
23 | | - |
24 | | - $count = $changed = 0; |
25 | | - while( $blockEnd <= $end ) { |
26 | | - echo "...doing fi_rev_id from $blockStart to $blockEnd\n"; |
27 | | - $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd"; |
28 | | - $res = $db->select( 'flaggedimages', '*', $cond, __FUNCTION__ ); |
29 | | - |
30 | | - $db->begin(); |
31 | | - # Go through and clean up missing items, as well as correct fr_quality... |
32 | | - foreach( $res as $row ) { |
33 | | - $count++; |
34 | | - $fi_img_timestamp = trim( $row->fi_img_timestamp ); // clear pad garbage |
35 | | - if ( !$fi_img_timestamp ) { |
36 | | - continue; // nothing to check |
37 | | - } |
38 | | - $time = wfTimestamp( TS_MW, $fi_img_timestamp ); |
39 | | - $sha1 = $row->fi_img_sha1; |
40 | | - # Check if the specified file exists... |
41 | | - $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); |
42 | | - if ( !$file ) { // doesn't exist? |
43 | | - $time = wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $time ) + 1 ); |
44 | | - # Check if the fi_img_timestamp value is off by 1 second... |
45 | | - $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); |
46 | | - if ( $file ) { |
47 | | - echo "fixed file {$row->fi_name} reference in rev ID {$row->fi_rev_id}\n"; |
48 | | - # Fix the fi_img_timestamp value... |
49 | | - $db->update( 'flaggedimages', |
50 | | - array( 'fi_img_timestamp' => $db->timestamp( $time ) ), |
51 | | - array( 'fi_rev_id' => $row->fi_rev_id, 'fi_name' => $row->fi_name ), |
52 | | - __METHOD__ |
53 | | - ); |
54 | | - $changed++; |
55 | | - } |
56 | | - } |
57 | | - } |
58 | | - $db->commit(); |
59 | | - $db->freeResult( $res ); |
60 | | - $blockStart += $BATCH_SIZE; |
61 | | - $blockEnd += $BATCH_SIZE; |
62 | | - wfWaitForSlaves( 5 ); |
63 | | - } |
64 | | - echo "fi_img_timestamp column fixes complete ... {$count} rows [{$changed} changed]\n"; |
65 | | -} |
Index: trunk/extensions/FlaggedRevs/maintenance/pruneRevData.inc |
— | — | @@ -1,116 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -function prune_flaggedrevs( $start = null, $prune = false ) { |
5 | | - if( $prune ) { |
6 | | - echo "Pruning old flagged revision inclusion data...\n"; |
7 | | - } else { |
8 | | - echo "Running dry-run of old flagged revision inclusion data pruning...\n"; |
9 | | - } |
10 | | - |
11 | | - $BATCH_SIZE = 500; |
12 | | - |
13 | | - $db = wfGetDB( DB_MASTER ); |
14 | | - |
15 | | - if( $start === null ) { |
16 | | - $start = $db->selectField( 'flaggedpages', 'MIN(fp_page_id)', false, __FUNCTION__ ); |
17 | | - } |
18 | | - $end = $db->selectField( 'flaggedpages', 'MAX(fp_page_id)', false, __FUNCTION__ ); |
19 | | - if( is_null( $start ) || is_null( $end ) ) { |
20 | | - echo "...flaggedpages table seems to be empty.\n"; |
21 | | - return; |
22 | | - } |
23 | | - $end += $BATCH_SIZE - 1; # Do remaining chunk |
24 | | - $blockStart = $start; |
25 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
26 | | - |
27 | | - $tDeleted = $fDeleted = 0; // tallies |
28 | | - |
29 | | - $newerRevs = 50; |
30 | | - $cutoff = $db->timestamp( time() - 3600 ); |
31 | | - while( $blockEnd <= $end ) { |
32 | | - echo "...doing fp_page_id from $blockStart to $blockEnd\n"; |
33 | | - $cond = "fp_page_id BETWEEN $blockStart AND $blockEnd"; |
34 | | - $res = $db->select( 'flaggedpages', 'fp_page_id', $cond, __FUNCTION__ ); |
35 | | - $batchCount = 0; // rows deleted without slave lag check |
36 | | - // Go through a chunk of flagged pages... |
37 | | - foreach( $res as $row ) { |
38 | | - // Get the newest X ($newerRevs) flagged revs for this page |
39 | | - $sres = $db->select( 'flaggedrevs', |
40 | | - 'fr_rev_id', |
41 | | - array( 'fr_page_id' => $row->fp_page_id ), |
42 | | - __METHOD__, |
43 | | - array( 'ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => $newerRevs ) |
44 | | - ); |
45 | | - // See if there are older revs that can be pruned... |
46 | | - if( $db->numRows( $sres ) == $newerRevs ) { |
47 | | - // Get the oldest of the top X revisions |
48 | | - $sres->seek( $newerRevs - 1 ); |
49 | | - $lrow = $db->fetchObject( $sres ); |
50 | | - $oldestId = (int)$lrow->fr_rev_id; // oldest revision Id |
51 | | - // Get revs not in the top X that were not reviewed recently |
52 | | - $db->freeResult( $sres ); |
53 | | - $sres = $db->select( 'flaggedrevs', |
54 | | - 'fr_rev_id', |
55 | | - array( |
56 | | - 'fr_page_id' => $row->fp_page_id, |
57 | | - 'fr_rev_id < '.$oldestId, // not in the newest X |
58 | | - 'fr_timestamp < '.$db->addQuotes( $cutoff ) // not reviewed recently |
59 | | - ), |
60 | | - __METHOD__, |
61 | | - // Sanity check (start with the oldest) |
62 | | - array( 'ORDER BY' => 'fr_rev_id ASC', 'LIMIT' => 5000 ) |
63 | | - ); |
64 | | - // Build an array of these rev Ids |
65 | | - $revsClearIncludes = array(); |
66 | | - foreach( $sres as $srow ) { |
67 | | - $revsClearIncludes[] = $srow->fr_rev_id; |
68 | | - } |
69 | | - $batchCount += count($revsClearIncludes); // # of revs to prune |
70 | | - $db->freeResult( $sres ); |
71 | | - // Write run: clear the include data for these old revs |
72 | | - if( $prune ) { |
73 | | - $db->begin(); |
74 | | - $db->delete( 'flaggedtemplates', |
75 | | - array('ft_rev_id' => $revsClearIncludes), |
76 | | - __METHOD__ |
77 | | - ); |
78 | | - $tDeleted += $db->affectedRows(); |
79 | | - $db->delete( 'flaggedimages', |
80 | | - array('fi_rev_id' => $revsClearIncludes), |
81 | | - __METHOD__ |
82 | | - ); |
83 | | - $fDeleted += $db->affectedRows(); |
84 | | - $db->commit(); |
85 | | - // Dry run: say how many includes rows would have been cleared |
86 | | - } else if( count($revsClearIncludes) ) { |
87 | | - $tDeleted += $db->selectField( 'flaggedtemplates', |
88 | | - 'COUNT(*)', |
89 | | - array('ft_rev_id' => $revsClearIncludes), |
90 | | - __METHOD__ |
91 | | - ); |
92 | | - $fDeleted += $db->selectField( 'flaggedimages', |
93 | | - 'COUNT(*)', |
94 | | - array('fi_rev_id' => $revsClearIncludes), |
95 | | - __METHOD__ |
96 | | - ); |
97 | | - } |
98 | | - // Check slave lag... |
99 | | - if( $batchCount >= $BATCH_SIZE ) { |
100 | | - $batchCount = 0; |
101 | | - wfWaitForSlaves( 5 ); |
102 | | - } |
103 | | - } else { |
104 | | - $db->freeResult( $sres ); |
105 | | - } |
106 | | - } |
107 | | - $db->freeResult( $res ); |
108 | | - $blockStart += $BATCH_SIZE; |
109 | | - $blockEnd += $BATCH_SIZE; |
110 | | - } |
111 | | - if( $prune ) { |
112 | | - echo "...flagged revision inclusion prunning complete ...\n"; |
113 | | - } else { |
114 | | - echo "...flagged revision inclusion prune test complete ...\n"; |
115 | | - } |
116 | | - echo "Rows: \tflaggedtemplates:$tDeleted\t\tflaggedimages:$fDeleted\n"; |
117 | | -} |
Index: trunk/extensions/FlaggedRevs/maintenance/updateStats.inc |
— | — | @@ -1,17 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -if ( php_sapi_name() != 'cli' ) { |
5 | | - print( 'Invalid entry' ); |
6 | | - die( 1 ); |
7 | | -} |
8 | | - |
9 | | -function update_flaggedrevs_stats() { |
10 | | - print sprintf( '%-30s ', 'ValidationStatistics' ); |
11 | | - |
12 | | - $time1 = microtime( true ); |
13 | | - FlaggedRevsStats::updateCache(); |
14 | | - $time2 = microtime( true ); |
15 | | - |
16 | | - $ellapsed = ( $time2 - $time1 ); |
17 | | - print sprintf( "completed in %.2fs\n", $ellapsed ); |
18 | | -} |
Index: trunk/extensions/FlaggedRevs/maintenance/updateTracking.inc |
— | — | @@ -1,212 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -function update_flaggedrevs( $start = null ) { |
5 | | - echo "Populating and correcting flaggedrevs columns\n"; |
6 | | - |
7 | | - $BATCH_SIZE = 1000; |
8 | | - |
9 | | - $db = wfGetDB( DB_MASTER ); |
10 | | - |
11 | | - if ( $start === null ) { |
12 | | - $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ ); |
13 | | - } |
14 | | - $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__ ); |
15 | | - if ( is_null( $start ) || is_null( $end ) ) { |
16 | | - echo "...revision table seems to be empty.\n"; |
17 | | - return; |
18 | | - } |
19 | | - # Do remaining chunk |
20 | | - $end += $BATCH_SIZE - 1; |
21 | | - $blockStart = $start; |
22 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
23 | | - $count = 0; |
24 | | - $changed = 0; |
25 | | - while ( $blockEnd <= $end ) { |
26 | | - echo "...doing fr_rev_id from $blockStart to $blockEnd\n"; |
27 | | - $cond = "rev_id BETWEEN $blockStart AND $blockEnd |
28 | | - AND fr_page_id = rev_page AND fr_rev_id = rev_id AND page_id = rev_page"; |
29 | | - $res = $db->select( |
30 | | - array('revision','flaggedrevs','page'), |
31 | | - array('fr_rev_id','fr_tags','fr_quality','page_namespace','page_title', |
32 | | - 'fr_img_name','fr_img_timestamp','fr_img_sha1','rev_page'), |
33 | | - $cond, __FUNCTION__ |
34 | | - ); |
35 | | - $db->begin(); |
36 | | - # Go through and clean up missing items, as well as correct fr_quality... |
37 | | - foreach ( $res as $row ) { |
38 | | - $tags = FlaggedRevision::expandRevisionTags( $row->fr_tags ); |
39 | | - # Quality rating levels may have changed due to config tweaks... |
40 | | - $quality = FlaggedRevs::getQualityTier( $tags, 0 /* sanity */ ); |
41 | | - |
42 | | - $file = $row->fr_img_name; |
43 | | - $fileTime = $row->fr_img_timestamp; |
44 | | - $fileSha1 = $row->fr_img_sha1; |
45 | | - # Check for file version to see if it's stored the old way... |
46 | | - if ( $row->page_namespace == NS_FILE && !$file ) { |
47 | | - $irow = $db->selectRow( 'flaggedimages', |
48 | | - array( 'fi_img_timestamp', 'fi_img_sha1' ), |
49 | | - array( 'fi_rev_id' => $row->fr_rev_id, 'fi_name' => $row->page_title ), |
50 | | - __METHOD__ ); |
51 | | - $fileTime = $irow ? $irow->fi_img_timestamp : null; |
52 | | - $fileSha1 = $irow ? $irow->fi_img_sha1 : null; |
53 | | - $file = $irow ? $row->page_title : null; |
54 | | - # Fill in from current if broken |
55 | | - if ( !$irow ) { |
56 | | - $crow = $db->selectRow( 'image', |
57 | | - array( 'img_timestamp', 'img_sha1' ), |
58 | | - array( 'img_name' => $row->page_title ), |
59 | | - __METHOD__ ); |
60 | | - $fileTime = $crow ? $crow->img_timestamp : null; |
61 | | - $fileSha1 = $crow ? $crow->img_sha1 : null; |
62 | | - $file = $crow ? $row->page_title : null; |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - # Check if anything needs updating |
67 | | - if ( $quality != $row->fr_quality |
68 | | - || $file != $row->fr_img_name |
69 | | - || $fileSha1 != $row->fr_img_sha1 |
70 | | - || $fileTime != $row->fr_img_timestamp ) |
71 | | - { |
72 | | - # Update the row... |
73 | | - $db->update( 'flaggedrevs', |
74 | | - array( |
75 | | - 'fr_quality' => $quality, |
76 | | - 'fr_img_name' => $file, |
77 | | - 'fr_img_sha1' => $fileSha1, |
78 | | - 'fr_img_timestamp' => $fileTime |
79 | | - ), |
80 | | - array( 'fr_rev_id' => $row->fr_rev_id, 'fr_page_id' => $row->rev_page ), |
81 | | - __FUNCTION__ |
82 | | - ); |
83 | | - $changed++; |
84 | | - } |
85 | | - $count++; |
86 | | - } |
87 | | - $db->commit(); |
88 | | - $db->freeResult( $res ); |
89 | | - $blockStart += $BATCH_SIZE; |
90 | | - $blockEnd += $BATCH_SIZE; |
91 | | - wfWaitForSlaves( 5 ); |
92 | | - } |
93 | | - echo "fr_quality and fr_img_* columns update complete ... {$count} rows [{$changed} changed]\n"; |
94 | | -} |
95 | | - |
96 | | -function update_flaggedpages( $start = null ) { |
97 | | - echo "Populating and correcting flaggedpages/flaggedpage_config columns\n"; |
98 | | - |
99 | | - $BATCH_SIZE = 300; |
100 | | - |
101 | | - $db = wfGetDB( DB_MASTER ); |
102 | | - |
103 | | - if ( $start === null ) { |
104 | | - $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
105 | | - } |
106 | | - $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ ); |
107 | | - if ( is_null( $start ) || is_null( $end ) ) { |
108 | | - echo "...flaggedpages table seems to be empty.\n"; |
109 | | - return; |
110 | | - } |
111 | | - # Do remaining chunk |
112 | | - $end += $BATCH_SIZE - 1; |
113 | | - $blockStart = $start; |
114 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
115 | | - $count = $deleted = $fixed = 0; |
116 | | - while ( $blockEnd <= $end ) { |
117 | | - echo "...doing page_id from $blockStart to $blockEnd\n"; |
118 | | - $cond = "page_id BETWEEN $blockStart AND $blockEnd"; |
119 | | - $res = $db->select( 'page', array('page_id','page_namespace','page_title','page_latest'), |
120 | | - $cond, __FUNCTION__ ); |
121 | | - # Go through and update the de-normalized references... |
122 | | - $db->begin(); |
123 | | - foreach ( $res as $row ) { |
124 | | - $title = Title::newFromRow( $row ); |
125 | | - $article = new FlaggableWikiPage( $title ); |
126 | | - $oldFrev = FlaggedRevision::newFromStable( $title, FR_MASTER ); |
127 | | - $frev = FlaggedRevision::determineStable( $title, FR_MASTER ); |
128 | | - # Update fp_stable, fp_quality, and fp_reviewed |
129 | | - if ( $frev ) { |
130 | | - $article->updateStableVersion( $frev, $row->page_latest ); |
131 | | - $changed = ( !$oldFrev || $oldFrev->getRevId() != $frev->getRevId() ); |
132 | | - # Somethings broke? Delete the row... |
133 | | - } else { |
134 | | - $article->clearStableVersion(); |
135 | | - if ( $db->affectedRows() > 0 ) $deleted++; |
136 | | - $changed = (bool)$oldFrev; |
137 | | - } |
138 | | - # Get the latest revision |
139 | | - $revRow = $db->selectRow( 'revision', '*', |
140 | | - array('rev_page' => $row->page_id), __FUNCTION__, |
141 | | - array('ORDER BY' => 'rev_timestamp DESC') ); |
142 | | - # Correct page_latest if needed (import/files made plenty of bad rows) |
143 | | - if ( $revRow ) { |
144 | | - $revision = new Revision( $revRow ); |
145 | | - if ( $article->updateIfNewerOn( $db, $revision ) ) { |
146 | | - $fixed++; |
147 | | - } |
148 | | - } |
149 | | - if ( $changed ) { |
150 | | - # Lazily rebuild dependancies on next parse (we invalidate below) |
151 | | - FlaggedRevs::clearStableOnlyDeps( $title ); |
152 | | - $title->invalidateCache(); |
153 | | - } |
154 | | - $count++; |
155 | | - } |
156 | | - $db->freeResult( $res ); |
157 | | - # Remove manual config settings that simply restate the site defaults |
158 | | - $db->delete( 'flaggedpage_config', |
159 | | - array( "fpc_page_id BETWEEN $blockStart AND $blockEnd", |
160 | | - 'fpc_override' => intval( FlaggedRevs::isStableShownByDefault() ), |
161 | | - 'fpc_level' => '' |
162 | | - ), |
163 | | - __FUNCTION__ |
164 | | - ); |
165 | | - $deleted = $deleted + $db->affectedRows(); |
166 | | - $db->commit(); |
167 | | - $blockStart += $BATCH_SIZE; |
168 | | - $blockEnd += $BATCH_SIZE; |
169 | | - wfWaitForSlaves( 5 ); |
170 | | - } |
171 | | - echo "flaggedpage columns update complete ... {$count} rows [{$fixed} fixed] [{$deleted} deleted]\n"; |
172 | | -} |
173 | | - |
174 | | -function update_flaggedimages( $start = null ) { |
175 | | - echo "Cleaning up flaggedimages columns\n"; |
176 | | - |
177 | | - $BATCH_SIZE = 1000; |
178 | | - |
179 | | - $db = wfGetDB( DB_MASTER ); |
180 | | - |
181 | | - if ( $start === null ) { |
182 | | - $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __FUNCTION__ ); |
183 | | - } |
184 | | - $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, __FUNCTION__ ); |
185 | | - if ( is_null( $start ) || is_null( $end ) ) { |
186 | | - echo "...flaggedimages table seems to be empty.\n"; |
187 | | - return; |
188 | | - } |
189 | | - # Do remaining chunk |
190 | | - $end += $BATCH_SIZE - 1; |
191 | | - $blockStart = $start; |
192 | | - $blockEnd = $start + $BATCH_SIZE - 1; |
193 | | - $nulled = 0; |
194 | | - while ( $blockEnd <= $end ) { |
195 | | - echo "...doing fi_rev_id from $blockStart to $blockEnd\n"; |
196 | | - $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd"; |
197 | | - $db->begin(); |
198 | | - # Remove padding garbage and such...turn to NULL instead |
199 | | - $db->update( 'flaggedimages', |
200 | | - array( 'fi_img_timestamp' => null ), |
201 | | - array( $cond, "fi_img_timestamp = '' OR LOCATE( '\\0', fi_img_timestamp )" ), |
202 | | - __FUNCTION__ |
203 | | - ); |
204 | | - if ( $db->affectedRows() > 0 ) { |
205 | | - $nulled += $db->affectedRows(); |
206 | | - } |
207 | | - $db->commit(); |
208 | | - $blockStart += $BATCH_SIZE; |
209 | | - $blockEnd += $BATCH_SIZE; |
210 | | - wfWaitForSlaves( 5 ); |
211 | | - } |
212 | | - echo "flaggedimages columns update complete ... [{$nulled} fixed]\n"; |
213 | | -} |
Index: trunk/extensions/FlaggedRevs/maintenance/populateRevTimestamp.php |
— | — | @@ -1,39 +1,101 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * @ingroup Maintenance |
| 5 | + */ |
4 | 6 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
5 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
| 7 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 8 | } else { |
7 | | - $IP = dirname(__FILE__).'/../../..'; |
| 9 | + $IP = dirname(__FILE__).'/../../..'; |
8 | 10 | } |
9 | 11 | |
10 | | -$options = array( 'help', 'startrev' ); |
11 | | -require "$IP/maintenance/commandLine.inc"; |
12 | | -require dirname(__FILE__) . '/populateRevTimestamp.inc'; |
| 12 | +require_once( "$IP/maintenance/Maintenance.php" ); |
13 | 13 | |
14 | | -if ( isset($options['help']) ) { |
15 | | - echo <<<TEXT |
16 | | -Purpose: |
17 | | - Populates fr_rev_timestamp column in the flaggedrevs table. |
18 | | -Usage: |
19 | | - php populateRevTimestamp.php --help |
20 | | - php populateRevTimestamp.php [--startrev <ID>] |
| 14 | +class PopulateFRRevTimestamp extends Maintenance { |
21 | 15 | |
22 | | - --help : This help message |
23 | | - --<ID> : The ID of the starting rev or 'prev' (from last run) |
| 16 | + public function __construct() { |
| 17 | + $this->mDescription = 'Populates fr_rev_timestamp column in the flaggedrevs table.'; |
| 18 | + $this->addOption( 'startrev', 'The ID of the starting rev', false, true ); |
| 19 | + $this->setBatchSize( 1000 ); |
| 20 | + } |
24 | 21 | |
25 | | -TEXT; |
26 | | - exit(0); |
27 | | -} |
| 22 | + public function execute() { |
| 23 | + $startRev = $this->getOption( 'startrev' ); |
| 24 | + if ( $startRev !== null ) { |
| 25 | + if ( $startRev === 'prev' ) { |
| 26 | + $startRev = (int)file_get_contents( $this->last_pos_file() ); |
| 27 | + } else { |
| 28 | + $startRev = (int)$startRev; |
| 29 | + } |
| 30 | + } |
| 31 | + $this->populate_fr_rev_timestamp( $startRev ); |
| 32 | + } |
28 | 33 | |
29 | | -error_reporting( E_ALL ); |
| 34 | + protected function populate_fr_rev_timestamp( $start = null ) { |
| 35 | + $this->output( "Populating and correcting flaggedrevs columns from $start\n" ); |
30 | 36 | |
31 | | -$startRev = null; |
32 | | -if ( isset( $options['startrev'] ) ) { |
33 | | - if ( $options['startrev'] === 'prev' ) { |
34 | | - $startRev = (int)file_get_contents( last_pos_file() ); |
35 | | - } else { |
36 | | - $startRev = (int)$options['startrev']; |
| 37 | + $db = wfGetDB( DB_MASTER ); |
| 38 | + |
| 39 | + if ( $start === null ) { |
| 40 | + $start = $db->selectField( 'flaggedrevs', 'MIN(fr_rev_id)', false, __METHOD__ ); |
| 41 | + } |
| 42 | + $end = $db->selectField( 'flaggedrevs', 'MAX(fr_rev_id)', false, __METHOD__ ); |
| 43 | + if ( is_null( $start ) || is_null( $end ) ) { |
| 44 | + $this->output( "...flaggedrevs table seems to be empty.\n" ); |
| 45 | + return; |
| 46 | + } |
| 47 | + # Do remaining chunk |
| 48 | + $end += $this->mBatchSize - 1; |
| 49 | + $blockStart = $start; |
| 50 | + $blockEnd = $start + $this->mBatchSize - 1; |
| 51 | + $count = 0; |
| 52 | + $changed = 0; |
| 53 | + while ( $blockEnd <= $end ) { |
| 54 | + $this->output( "...doing fr_rev_id from $blockStart to $blockEnd\n" ); |
| 55 | + $cond = "fr_rev_id BETWEEN $blockStart AND $blockEnd AND fr_rev_timestamp = ''"; |
| 56 | + $res = $db->select( |
| 57 | + array( 'flaggedrevs', 'revision', 'archive' ), |
| 58 | + array( 'fr_rev_id', 'rev_timestamp', 'ar_timestamp' ), |
| 59 | + $cond, |
| 60 | + __METHOD__, |
| 61 | + array(), |
| 62 | + array( 'revision' => array( 'LEFT JOIN', 'rev_id = fr_rev_id' ), |
| 63 | + 'archive' => array( 'LEFT JOIN', 'ar_rev_id = fr_rev_id' ) ) // non-unique but OK |
| 64 | + ); |
| 65 | + $db->begin(); |
| 66 | + # Go through and clean up missing items, as well as correct fr_quality... |
| 67 | + foreach ( $res as $row ) { |
| 68 | + $timestamp = ''; |
| 69 | + if ( $row->rev_timestamp ) { |
| 70 | + $timestamp = $row->rev_timestamp; |
| 71 | + } elseif ( $row->ar_timestamp ) { |
| 72 | + $timestamp = $row->ar_timestamp; |
| 73 | + } |
| 74 | + if ( $timestamp != '' ) { |
| 75 | + # Update the row... |
| 76 | + $db->update( 'flaggedrevs', |
| 77 | + array( 'fr_rev_timestamp' => $timestamp ), |
| 78 | + array( 'fr_rev_id' => $row->fr_rev_id ), |
| 79 | + __METHOD__ |
| 80 | + ); |
| 81 | + $changed++; |
| 82 | + } |
| 83 | + $count++; |
| 84 | + } |
| 85 | + $db->commit(); |
| 86 | + $db->freeResult( $res ); |
| 87 | + $blockStart += $this->mBatchSize; |
| 88 | + $blockEnd += $this->mBatchSize; |
| 89 | + wfWaitForSlaves( 5 ); |
| 90 | + } |
| 91 | + file_put_contents( $this->last_pos_file(), $end ); |
| 92 | + $this->output( "fr_rev_timestamp columns update complete ..." . |
| 93 | + " {$count} rows [{$changed} changed]\n" ); |
37 | 94 | } |
| 95 | + |
| 96 | + protected function last_pos_file() { |
| 97 | + return dirname( __FILE__ ) . "/popRevTimestampLast-" . wfWikiID(); |
| 98 | + } |
38 | 99 | } |
39 | 100 | |
40 | | -populate_fr_rev_timestamp( $startRev ); |
| 101 | +$maintClass = "PopulateFRRevTimestamp"; |
| 102 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/extensions/FlaggedRevs/maintenance/flagToSemiProtect.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | } |
32 | 32 | |
33 | 33 | echo "Protecter username: \"".$wgUser->getName()."\"\n"; |
34 | | -echo "Running in 5 seconds...\n"; |
| 34 | +echo "Running in 5 seconds...Press ctrl-c to abort.\n"; |
35 | 35 | sleep( 5 ); |
36 | 36 | |
37 | 37 | if ( isset( $args[1] ) ) { |
Index: trunk/extensions/FlaggedRevs/maintenance/updateQueryCache.php |
— | — | @@ -1,13 +1,33 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * @ingroup Maintenance |
| 5 | + */ |
4 | 6 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
5 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
| 7 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 8 | } else { |
7 | | - $IP = dirname(__FILE__).'/../../..'; |
| 9 | + $IP = dirname(__FILE__).'/../../..'; |
8 | 10 | } |
9 | | -require "$IP/maintenance/commandLine.inc"; |
10 | | -require dirname(__FILE__) . '/updateQueryCache.inc'; |
11 | 11 | |
12 | | -error_reporting( E_ALL ); |
| 12 | +require_once( "$IP/maintenance/Maintenance.php" ); |
13 | 13 | |
14 | | -update_flaggedrevs_querycache(); |
| 14 | +class UpdateFlaggedRevsQueryCache extends Maintenance { |
| 15 | + |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "Update special page query cache table"; |
| 19 | + } |
| 20 | + |
| 21 | + public function execute() { |
| 22 | + print sprintf( '%-30s ', 'UnreviewedPages' ); |
| 23 | + |
| 24 | + $time1 = microtime( true ); |
| 25 | + UnreviewedPages::updateQueryCache(); |
| 26 | + $time2 = microtime( true ); |
| 27 | + |
| 28 | + $ellapsed = ( $time2 - $time1 ); |
| 29 | + print sprintf( "completed in %.2fs\n", $ellapsed ); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +$maintClass = "UpdateFlaggedRevsQueryCache"; |
| 34 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/extensions/FlaggedRevs/maintenance/fixBug28348.php |
— | — | @@ -1,34 +1,89 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * @ingroup Maintenance |
| 5 | + */ |
4 | 6 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
5 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
| 7 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 8 | } else { |
7 | | - $IP = dirname(__FILE__).'/../../..'; |
| 9 | + $IP = dirname(__FILE__).'/../../..'; |
8 | 10 | } |
9 | 11 | |
10 | | -$options = array( 'help', 'startrev' ); |
11 | | -require "$IP/maintenance/commandLine.inc"; |
12 | | -require dirname(__FILE__) . '/fixBug28348.inc'; |
| 12 | +require_once( "$IP/maintenance/Maintenance.php" ); |
13 | 13 | |
14 | | -if ( isset($options['help']) ) { |
15 | | - echo <<<TEXT |
16 | | -Purpose: |
17 | | - Correct bad fi_img_timestamp rows due to bug 28348 |
18 | | -Usage: |
19 | | - php updateLinks.php --help |
20 | | - php updateLinks.php [--startrev <ID>] |
| 14 | +class FixBug28348 extends Maintenance { |
21 | 15 | |
22 | | - --help : This help message |
23 | | - --<ID> : The ID of the starting rev |
24 | | - --<CALL> : One of (revs) |
| 16 | + public function __construct() { |
| 17 | + $this->mDescription = "Correct bad fi_img_timestamp rows due to bug 28348"; |
| 18 | + $this->addOption( 'startrev', 'The ID of the starting rev', false, true ); |
| 19 | + $this->setBatchSize( 1000 ); |
| 20 | + } |
25 | 21 | |
26 | | -TEXT; |
27 | | - exit(0); |
28 | | -} |
| 22 | + public function execute() { |
| 23 | + $startRev = $this->getOption( 'startrev' ); |
| 24 | + $this->update_images_bug_28348( $startRev ); |
| 25 | + } |
29 | 26 | |
30 | | -error_reporting( E_ALL ); |
| 27 | + protected function update_images_bug_28348( $start = null ) { |
| 28 | + $this->output( "Correcting fi_img_timestamp column in flaggedimages\n" ); |
31 | 29 | |
32 | | -$startRev = isset( $options['startrev'] ) ? |
33 | | - (int)$options['startrev'] : null; |
| 30 | + $db = wfGetDB( DB_MASTER ); |
34 | 31 | |
35 | | -update_images_bug_28348( $startRev ); |
| 32 | + if ( $start === null ) { |
| 33 | + $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __METHOD__ ); |
| 34 | + } |
| 35 | + $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, __METHOD__ ); |
| 36 | + if ( is_null( $start ) || is_null( $end ) ) { |
| 37 | + $this->output( "...flaggedimages table seems to be empty.\n" ); |
| 38 | + return; |
| 39 | + } |
| 40 | + # Do remaining chunk |
| 41 | + $end += $this->mBatchSize - 1; |
| 42 | + $blockStart = $start; |
| 43 | + $blockEnd = $start + $this->mBatchSize - 1; |
| 44 | + |
| 45 | + $count = $changed = 0; |
| 46 | + while ( $blockEnd <= $end ) { |
| 47 | + $this->output( "...doing fi_rev_id from $blockStart to $blockEnd\n" ); |
| 48 | + $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd"; |
| 49 | + $res = $db->select( 'flaggedimages', '*', $cond, __METHOD__ ); |
| 50 | + |
| 51 | + $db->begin(); |
| 52 | + # Go through and clean up missing items, as well as correct fr_quality... |
| 53 | + foreach ( $res as $row ) { |
| 54 | + $count++; |
| 55 | + $fi_img_timestamp = trim( $row->fi_img_timestamp ); // clear pad garbage |
| 56 | + if ( !$fi_img_timestamp ) { |
| 57 | + continue; // nothing to check |
| 58 | + } |
| 59 | + $time = wfTimestamp( TS_MW, $fi_img_timestamp ); |
| 60 | + $sha1 = $row->fi_img_sha1; |
| 61 | + # Check if the specified file exists... |
| 62 | + $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); |
| 63 | + if ( !$file ) { // doesn't exist? |
| 64 | + $time = wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $time ) + 1 ); |
| 65 | + # Check if the fi_img_timestamp value is off by 1 second... |
| 66 | + $file = RepoGroup::singleton()->findFileFromKey( $sha1, array( 'time' => $time ) ); |
| 67 | + if ( $file ) { |
| 68 | + $this->output( "fixed file {$row->fi_name} reference in rev ID {$row->fi_rev_id}\n" ); |
| 69 | + # Fix the fi_img_timestamp value... |
| 70 | + $db->update( 'flaggedimages', |
| 71 | + array( 'fi_img_timestamp' => $db->timestamp( $time ) ), |
| 72 | + array( 'fi_rev_id' => $row->fi_rev_id, 'fi_name' => $row->fi_name ), |
| 73 | + __METHOD__ |
| 74 | + ); |
| 75 | + $changed++; |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + $db->commit(); |
| 80 | + $db->freeResult( $res ); |
| 81 | + $blockStart += $this->mBatchSize; |
| 82 | + $blockEnd += $this->mBatchSize; |
| 83 | + wfWaitForSlaves( 5 ); |
| 84 | + } |
| 85 | + $this->output( "fi_img_timestamp column fixes complete ... {$count} rows [{$changed} changed]\n" ); |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +$maintClass = "FixBug28348"; |
| 90 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/extensions/FlaggedRevs/maintenance/pruneRevData.php |
— | — | @@ -1,37 +1,147 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * @ingroup Maintenance |
| 5 | + */ |
4 | 6 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
5 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
| 7 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 8 | } else { |
7 | | - $IP = dirname(__FILE__).'/../../..'; |
| 9 | + $IP = dirname(__FILE__).'/../../..'; |
8 | 10 | } |
9 | 11 | |
10 | | -$options = array( 'prune', 'help', 'start' ); |
11 | | -require "$IP/maintenance/commandLine.inc"; |
12 | | -require dirname(__FILE__) . '/pruneRevData.inc'; |
| 12 | +require_once( "$IP/maintenance/Maintenance.php" ); |
13 | 13 | |
14 | | -if( isset($options['help']) ) { |
15 | | - echo <<<TEXT |
16 | | -Purpose: |
17 | | - This script clears template/image data for reviewed versions |
18 | | - that are 1+ month old and have 50+ newer versions in page. By |
19 | | - default, it will just output how many rows can be deleted. Use |
20 | | - the 'prune' option to actually delete them. |
21 | | -Usage: |
22 | | - php pruneData.php --help |
23 | | - php pruneData.php [--prune --start <ID> ] |
| 14 | +class PruneFRIncludeData extends Maintenance { |
24 | 15 | |
25 | | - --help : This help message |
26 | | - --prune : Actually do a live run |
27 | | - --<ID> : The ID of the starting rev |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "This script clears template/image data for reviewed versions" . |
| 19 | + "that are 1+ month old and have 50+ newer versions in page. By default," . |
| 20 | + "it will just output how many rows can be deleted. Use the 'prune' option " . |
| 21 | + "to actually delete them."; |
| 22 | + $this->addOption( 'prune', 'Actually do a live run', false ); |
| 23 | + $this->addOption( 'start', 'The ID of the starting rev', false, true ); |
| 24 | + $this->setBatchSize( 500 ); |
| 25 | + } |
28 | 26 | |
29 | | -TEXT; |
30 | | - exit(0); |
31 | | -} |
| 27 | + public function execute() { |
| 28 | + $start = $this->getOption( 'start' ); |
| 29 | + $prune = $this->getOption( 'prune' ); |
| 30 | + $this->prune_flaggedrevs( $start, $prune ); |
| 31 | + } |
32 | 32 | |
33 | | -error_reporting( E_ALL ); |
| 33 | + protected function prune_flaggedrevs( $start = null, $prune = false ) { |
| 34 | + if ( $prune ) { |
| 35 | + $this->output( "Pruning old flagged revision inclusion data...\n" ); |
| 36 | + } else { |
| 37 | + $this->output( "Running dry-run of old flagged revision inclusion data pruning...\n" ); |
| 38 | + } |
34 | 39 | |
35 | | -$start = isset($options['start']) ? $options['start'] : null; |
36 | | -$prune = isset($options['prune']) ? true : null; |
| 40 | + $db = wfGetDB( DB_MASTER ); |
37 | 41 | |
38 | | -prune_flaggedrevs($start,$prune); |
| 42 | + if ( $start === null ) { |
| 43 | + $start = $db->selectField( 'flaggedpages', 'MIN(fp_page_id)', false, __METHOD__ ); |
| 44 | + } |
| 45 | + $end = $db->selectField( 'flaggedpages', 'MAX(fp_page_id)', false, __METHOD__ ); |
| 46 | + if ( is_null( $start ) || is_null( $end ) ) { |
| 47 | + echo "...flaggedpages table seems to be empty.\n"; |
| 48 | + return; |
| 49 | + } |
| 50 | + $end += $this->mBatchSize - 1; # Do remaining chunk |
| 51 | + $blockStart = $start; |
| 52 | + $blockEnd = $start + $this->mBatchSize - 1; |
| 53 | + |
| 54 | + $tDeleted = $fDeleted = 0; // tallies |
| 55 | + |
| 56 | + $newerRevs = 50; |
| 57 | + $cutoff = $db->timestamp( time() - 3600 ); |
| 58 | + while ( $blockEnd <= $end ) { |
| 59 | + $this->output( "...doing fp_page_id from $blockStart to $blockEnd\n" ); |
| 60 | + $cond = "fp_page_id BETWEEN $blockStart AND $blockEnd"; |
| 61 | + $res = $db->select( 'flaggedpages', 'fp_page_id', $cond, __METHOD__ ); |
| 62 | + $batchCount = 0; // rows deleted without slave lag check |
| 63 | + // Go through a chunk of flagged pages... |
| 64 | + foreach ( $res as $row ) { |
| 65 | + // Get the newest X ($newerRevs) flagged revs for this page |
| 66 | + $sres = $db->select( 'flaggedrevs', |
| 67 | + 'fr_rev_id', |
| 68 | + array( 'fr_page_id' => $row->fp_page_id ), |
| 69 | + __METHOD__, |
| 70 | + array( 'ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => $newerRevs ) |
| 71 | + ); |
| 72 | + // See if there are older revs that can be pruned... |
| 73 | + if ( $db->numRows( $sres ) == $newerRevs ) { |
| 74 | + // Get the oldest of the top X revisions |
| 75 | + $sres->seek( $newerRevs - 1 ); |
| 76 | + $lrow = $db->fetchObject( $sres ); |
| 77 | + $oldestId = (int)$lrow->fr_rev_id; // oldest revision Id |
| 78 | + // Get revs not in the top X that were not reviewed recently |
| 79 | + $db->freeResult( $sres ); |
| 80 | + $sres = $db->select( 'flaggedrevs', |
| 81 | + 'fr_rev_id', |
| 82 | + array( |
| 83 | + 'fr_page_id' => $row->fp_page_id, |
| 84 | + 'fr_rev_id < '.$oldestId, // not in the newest X |
| 85 | + 'fr_timestamp < '.$db->addQuotes( $cutoff ) // not reviewed recently |
| 86 | + ), |
| 87 | + __METHOD__, |
| 88 | + // Sanity check (start with the oldest) |
| 89 | + array( 'ORDER BY' => 'fr_rev_id ASC', 'LIMIT' => 5000 ) |
| 90 | + ); |
| 91 | + // Build an array of these rev Ids |
| 92 | + $revsClearIncludes = array(); |
| 93 | + foreach ( $sres as $srow ) { |
| 94 | + $revsClearIncludes[] = $srow->fr_rev_id; |
| 95 | + } |
| 96 | + $batchCount += count( $revsClearIncludes ); // # of revs to prune |
| 97 | + $db->freeResult( $sres ); |
| 98 | + // Write run: clear the include data for these old revs |
| 99 | + if ( $prune ) { |
| 100 | + $db->begin(); |
| 101 | + $db->delete( 'flaggedtemplates', |
| 102 | + array('ft_rev_id' => $revsClearIncludes), |
| 103 | + __METHOD__ |
| 104 | + ); |
| 105 | + $tDeleted += $db->affectedRows(); |
| 106 | + $db->delete( 'flaggedimages', |
| 107 | + array('fi_rev_id' => $revsClearIncludes), |
| 108 | + __METHOD__ |
| 109 | + ); |
| 110 | + $fDeleted += $db->affectedRows(); |
| 111 | + $db->commit(); |
| 112 | + // Dry run: say how many includes rows would have been cleared |
| 113 | + } elseif ( count( $revsClearIncludes ) ) { |
| 114 | + $tDeleted += $db->selectField( 'flaggedtemplates', |
| 115 | + 'COUNT(*)', |
| 116 | + array('ft_rev_id' => $revsClearIncludes), |
| 117 | + __METHOD__ |
| 118 | + ); |
| 119 | + $fDeleted += $db->selectField( 'flaggedimages', |
| 120 | + 'COUNT(*)', |
| 121 | + array('fi_rev_id' => $revsClearIncludes), |
| 122 | + __METHOD__ |
| 123 | + ); |
| 124 | + } |
| 125 | + // Check slave lag... |
| 126 | + if ( $batchCount >= $this->mBatchSize ) { |
| 127 | + $batchCount = 0; |
| 128 | + wfWaitForSlaves( 5 ); |
| 129 | + } |
| 130 | + } else { |
| 131 | + $db->freeResult( $sres ); |
| 132 | + } |
| 133 | + } |
| 134 | + $db->freeResult( $res ); |
| 135 | + $blockStart += $this->mBatchSize; |
| 136 | + $blockEnd += $this->mBatchSize; |
| 137 | + } |
| 138 | + if ( $prune ) { |
| 139 | + $this->output( "Flagged revision inclusion prunning complete ...\n" ); |
| 140 | + } else { |
| 141 | + $this->output( "Flagged revision inclusion prune test complete ...\n" ); |
| 142 | + } |
| 143 | + $this->output( "Rows: \tflaggedtemplates:$tDeleted\t\tflaggedimages:$fDeleted\n" ); |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +$maintClass = "PruneFRIncludeData"; |
| 148 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/extensions/FlaggedRevs/maintenance/updateAutoPromote.php |
— | — | @@ -1,12 +1,92 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * @ingroup Maintenance |
| 5 | + */ |
4 | 6 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
5 | 7 | $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 8 | } else { |
7 | 9 | $IP = dirname(__FILE__).'/../../..'; |
8 | 10 | } |
9 | | -require "$IP/maintenance/commandLine.inc"; |
10 | | -require dirname(__FILE__) . '/updateAutoPromote.inc'; |
11 | 11 | |
12 | | -update_autopromote(); |
| 12 | +require_once( "$IP/maintenance/Maintenance.php" ); |
13 | 13 | |
| 14 | +class UpdateFRAutoPromote extends Maintenance { |
| 15 | + |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "Update autopromote table"; |
| 19 | + $this->setBatchSize( 50 ); |
| 20 | + } |
| 21 | + |
| 22 | + public function execute() { |
| 23 | + global $wgContentNamespaces, $wgFlaggedRevsAutopromote; |
| 24 | + $this->output( "Populating and updating flaggedrevs_promote table\n" ); |
| 25 | + |
| 26 | + $dbr = wfGetDB( DB_SLAVE ); |
| 27 | + $dbw = wfGetDB( DB_MASTER ); |
| 28 | + $start = $dbr->selectField( 'user', 'MIN(user_id)', false, __METHOD__ ); |
| 29 | + $end = $dbr->selectField( 'user', 'MAX(user_id)', false, __METHOD__ ); |
| 30 | + if ( is_null( $start ) || is_null( $end ) ){ |
| 31 | + $this->output( "...user table seems to be empty.\n" ); |
| 32 | + return; |
| 33 | + } |
| 34 | + $count = 0; |
| 35 | + $changed = 0; |
| 36 | + for ( $blockStart = $start; $blockStart <= $end; $blockStart += $this->mBatchSize ) { |
| 37 | + $blockEnd = min( $end, $blockStart + $this->mBatchSize - 1 ); |
| 38 | + $this->output( "...doing user_id from $blockStart to $blockEnd\n" ); |
| 39 | + $cond = "user_id BETWEEN $blockStart AND $blockEnd\n"; |
| 40 | + $res = $dbr->select( 'user', '*', $cond, __METHOD__ ); |
| 41 | + # Go through and clean up missing items, as well as correct fr_quality... |
| 42 | + foreach ( $res as $row ) { |
| 43 | + $dbw->begin(); |
| 44 | + $user = User::newFromRow( $row ); |
| 45 | + $p = FRUserCounters::getUserParams( $user->getId(), FR_FOR_UPDATE ); |
| 46 | + $oldp = $p; |
| 47 | + # Get edit comments used |
| 48 | + $sres = $dbr->select( 'revision', '1', |
| 49 | + array( 'rev_user' => $user->getID(), |
| 50 | + "rev_comment NOT LIKE '/*%*/'" ), // manual comments only |
| 51 | + __METHOD__, |
| 52 | + array( 'LIMIT' => max($wgFlaggedRevsAutopromote['editComments'],500) ) |
| 53 | + ); |
| 54 | + $p['editComments'] = $dbr->numRows( $sres ); |
| 55 | + # Get content page edits |
| 56 | + $sres = $dbr->select( array('revision','page'), '1', |
| 57 | + array( 'rev_user' => $user->getID(), |
| 58 | + 'page_id = rev_page', |
| 59 | + 'page_namespace' => $wgContentNamespaces ), |
| 60 | + __METHOD__, |
| 61 | + array( 'LIMIT' => max($wgFlaggedRevsAutopromote['totalContentEdits'],500) ) |
| 62 | + ); |
| 63 | + $p['totalContentEdits'] = $dbr->numRows( $sres ); |
| 64 | + # Get unique content pages edited |
| 65 | + $sres = $dbr->select( array('revision','page'), 'DISTINCT(rev_page)', |
| 66 | + array( 'rev_user' => $user->getID(), |
| 67 | + 'page_id = rev_page', |
| 68 | + 'page_namespace' => $wgContentNamespaces ), |
| 69 | + __METHOD__, |
| 70 | + array( 'LIMIT' => max($wgFlaggedRevsAutopromote['uniqueContentPages'],50) ) |
| 71 | + ); |
| 72 | + $p['uniqueContentPages'] = array(); |
| 73 | + foreach ( $sres as $row ) { |
| 74 | + $p['uniqueContentPages'][] = (int)$row->rev_page; |
| 75 | + } |
| 76 | + # Save the new params... |
| 77 | + if ( $oldp != $p ) { |
| 78 | + FRUserCounters::saveUserParams( $user->getId(), $p ); |
| 79 | + $changed++; |
| 80 | + } |
| 81 | + |
| 82 | + $count++; |
| 83 | + $dbw->commit(); |
| 84 | + } |
| 85 | + wfWaitForSlaves( 5 ); |
| 86 | + } |
| 87 | + $this->output( "flaggedrevs_promote table update complete ..." . |
| 88 | + " {$count} rows [{$changed} changed or added]\n" ); |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +$maintClass = "UpdateFRAutoPromote"; |
| 93 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/extensions/FlaggedRevs/maintenance/updateStats.php |
— | — | @@ -1,13 +1,33 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * @ingroup Maintenance |
| 5 | + */ |
4 | 6 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
5 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
| 7 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 8 | } else { |
7 | | - $IP = dirname(__FILE__).'/../../..'; |
| 9 | + $IP = dirname(__FILE__).'/../../..'; |
8 | 10 | } |
9 | | -require "$IP/maintenance/commandLine.inc"; |
10 | | -require dirname(__FILE__) . '/updateStats.inc'; |
11 | 11 | |
12 | | -error_reporting( E_ALL ); |
| 12 | +require_once( "$IP/maintenance/Maintenance.php" ); |
13 | 13 | |
14 | | -update_flaggedrevs_stats(); |
| 14 | +class UpdateFlaggedRevsStats extends Maintenance { |
| 15 | + |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "Update FlaggedRevs statistics table"; |
| 19 | + } |
| 20 | + |
| 21 | + public function execute() { |
| 22 | + print sprintf( '%-30s ', 'ValidationStatistics' ); |
| 23 | + |
| 24 | + $time1 = microtime( true ); |
| 25 | + FlaggedRevsStats::updateCache(); |
| 26 | + $time2 = microtime( true ); |
| 27 | + |
| 28 | + $ellapsed = ( $time2 - $time1 ); |
| 29 | + print sprintf( "completed in %.2fs\n", $ellapsed ); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +$maintClass = "UpdateFlaggedRevsStats"; |
| 34 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/extensions/FlaggedRevs/maintenance/updateTracking.php |
— | — | @@ -1,61 +1,268 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | +/** |
| 4 | + * @ingroup Maintenance |
| 5 | + */ |
4 | 6 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
5 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
| 7 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
6 | 8 | } else { |
7 | | - $IP = dirname(__FILE__).'/../../..'; |
| 9 | + $IP = dirname(__FILE__).'/../../..'; |
8 | 10 | } |
9 | 11 | |
10 | | -$options = array( 'updateonly', 'help', 'startrev', 'startpage' ); |
11 | | -require "$IP/maintenance/commandLine.inc"; |
12 | | -require dirname(__FILE__) . '/updateTracking.inc'; |
| 12 | +require_once( "$IP/maintenance/Maintenance.php" ); |
13 | 13 | |
14 | | -if ( isset($options['help']) ) { |
15 | | - echo <<<TEXT |
16 | | -Purpose: |
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. |
20 | | -Usage: |
21 | | - php updateTracking.php --help |
22 | | - php updateTracking.php [--startpage <ID> | --startrev <ID> | --updateonly <CALL> ] |
| 14 | +class UpdateFRTracking extends Maintenance { |
23 | 15 | |
24 | | - --help : This help message |
25 | | - --<ID> : The ID of the starting rev/page |
26 | | - --<CALL> : One of (revs, pages, images) |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "Correct the page data in the flaggedrevs tracking tables. " . |
| 19 | + "Update the quality tier of revisions based on their rating tags. " . |
| 20 | + "Migrate flagged revision file version data to proper table."; |
| 21 | + $this->addOption( 'startpage', 'Page ID to start on', false, true ); |
| 22 | + $this->addOption( 'startrev', 'Rev ID to start on', false, true ); |
| 23 | + $this->addOption( 'updateonly', 'One of (revs, pages, images)', false, true ); |
| 24 | + } |
27 | 25 | |
28 | | -TEXT; |
29 | | - exit(0); |
30 | | -} |
| 26 | + public function execute() { |
| 27 | + $startPage = $this->getOption( 'startpage' ); |
| 28 | + $startRev = $this->getOption( 'startrev' ); |
| 29 | + $updateonly = $this->getOption( 'updateonly' ); |
| 30 | + if ( $updateonly ) { |
| 31 | + switch ( $updateonly ) { |
| 32 | + case 'revs': |
| 33 | + $this->update_flaggedrevs( $startRev ); |
| 34 | + break; |
| 35 | + case 'pages': |
| 36 | + $this->update_flaggedpages( $startPage ); |
| 37 | + break; |
| 38 | + case 'images': |
| 39 | + $this->update_flaggedimages( $startRev ); |
| 40 | + break; |
| 41 | + default: |
| 42 | + echo "Invalidate operation specified.\n"; |
| 43 | + } |
| 44 | + } else { |
| 45 | + $this->update_flaggedrevs( $startRev ); |
| 46 | + $this->update_flaggedpages( $startPage ); |
| 47 | + $this->update_flaggedimages( $startRev ); |
| 48 | + } |
| 49 | + } |
31 | 50 | |
32 | | -error_reporting( E_ALL ); |
| 51 | + protected function update_flaggedrevs( $start = null ) { |
| 52 | + $this->output( "Populating and correcting flaggedrevs columns\n" ); |
33 | 53 | |
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; |
| 54 | + $BATCH_SIZE = 1000; |
40 | 55 | |
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 | | - case 'images': |
50 | | - update_flaggedimages( $startRev ); |
51 | | - break; |
52 | | - default: |
53 | | - echo "Invalidate operation specified.\n"; |
| 56 | + $db = wfGetDB( DB_MASTER ); |
| 57 | + |
| 58 | + if ( $start === null ) { |
| 59 | + $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __METHOD__ ); |
| 60 | + } |
| 61 | + $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ ); |
| 62 | + if ( is_null( $start ) || is_null( $end ) ) { |
| 63 | + $this->output( "...revision table seems to be empty.\n" ); |
| 64 | + return; |
| 65 | + } |
| 66 | + # Do remaining chunk |
| 67 | + $end += $BATCH_SIZE - 1; |
| 68 | + $blockStart = $start; |
| 69 | + $blockEnd = $start + $BATCH_SIZE - 1; |
| 70 | + $count = 0; |
| 71 | + $changed = 0; |
| 72 | + while ( $blockEnd <= $end ) { |
| 73 | + $this->output( "...doing fr_rev_id from $blockStart to $blockEnd\n" ); |
| 74 | + $cond = "rev_id BETWEEN $blockStart AND $blockEnd |
| 75 | + AND fr_page_id = rev_page AND fr_rev_id = rev_id AND page_id = rev_page"; |
| 76 | + $res = $db->select( |
| 77 | + array( 'revision', 'flaggedrevs', 'page' ), |
| 78 | + array( 'fr_rev_id', 'fr_tags', 'fr_quality', 'page_namespace', 'page_title', |
| 79 | + 'fr_img_name', 'fr_img_timestamp', 'fr_img_sha1', 'rev_page'), |
| 80 | + $cond, |
| 81 | + __METHOD__ |
| 82 | + ); |
| 83 | + $db->begin(); |
| 84 | + # Go through and clean up missing items, as well as correct fr_quality... |
| 85 | + foreach ( $res as $row ) { |
| 86 | + $tags = FlaggedRevision::expandRevisionTags( $row->fr_tags ); |
| 87 | + # Quality rating levels may have changed due to config tweaks... |
| 88 | + $quality = FlaggedRevs::getQualityTier( $tags, 0 /* sanity */ ); |
| 89 | + |
| 90 | + $file = $row->fr_img_name; |
| 91 | + $fileTime = $row->fr_img_timestamp; |
| 92 | + $fileSha1 = $row->fr_img_sha1; |
| 93 | + # Check for file version to see if it's stored the old way... |
| 94 | + if ( $row->page_namespace == NS_FILE && !$file ) { |
| 95 | + $irow = $db->selectRow( 'flaggedimages', |
| 96 | + array( 'fi_img_timestamp', 'fi_img_sha1' ), |
| 97 | + array( 'fi_rev_id' => $row->fr_rev_id, 'fi_name' => $row->page_title ), |
| 98 | + __METHOD__ ); |
| 99 | + $fileTime = $irow ? $irow->fi_img_timestamp : null; |
| 100 | + $fileSha1 = $irow ? $irow->fi_img_sha1 : null; |
| 101 | + $file = $irow ? $row->page_title : null; |
| 102 | + # Fill in from current if broken |
| 103 | + if ( !$irow ) { |
| 104 | + $crow = $db->selectRow( 'image', |
| 105 | + array( 'img_timestamp', 'img_sha1' ), |
| 106 | + array( 'img_name' => $row->page_title ), |
| 107 | + __METHOD__ ); |
| 108 | + $fileTime = $crow ? $crow->img_timestamp : null; |
| 109 | + $fileSha1 = $crow ? $crow->img_sha1 : null; |
| 110 | + $file = $crow ? $row->page_title : null; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + # Check if anything needs updating |
| 115 | + if ( $quality != $row->fr_quality |
| 116 | + || $file != $row->fr_img_name |
| 117 | + || $fileSha1 != $row->fr_img_sha1 |
| 118 | + || $fileTime != $row->fr_img_timestamp ) |
| 119 | + { |
| 120 | + # Update the row... |
| 121 | + $db->update( 'flaggedrevs', |
| 122 | + array( |
| 123 | + 'fr_quality' => $quality, |
| 124 | + 'fr_img_name' => $file, |
| 125 | + 'fr_img_sha1' => $fileSha1, |
| 126 | + 'fr_img_timestamp' => $fileTime |
| 127 | + ), |
| 128 | + array( 'fr_rev_id' => $row->fr_rev_id, 'fr_page_id' => $row->rev_page ), |
| 129 | + __METHOD__ |
| 130 | + ); |
| 131 | + $changed++; |
| 132 | + } |
| 133 | + $count++; |
| 134 | + } |
| 135 | + $db->commit(); |
| 136 | + $db->freeResult( $res ); |
| 137 | + $blockStart += $BATCH_SIZE; |
| 138 | + $blockEnd += $BATCH_SIZE; |
| 139 | + wfWaitForSlaves( 5 ); |
| 140 | + } |
| 141 | + $this->output( "fr_quality and fr_img_* columns update complete ..." . |
| 142 | + " {$count} rows [{$changed} changed]\n" ); |
54 | 143 | } |
55 | | - exit( 0 ); |
56 | | -} |
| 144 | + |
| 145 | + protected function update_flaggedpages( $start = null ) { |
| 146 | + $this->output( "Populating and correcting flaggedpages/flaggedpage_config columns\n" ); |
57 | 147 | |
58 | | -update_flaggedrevs( $startRev ); |
| 148 | + $BATCH_SIZE = 300; |
59 | 149 | |
60 | | -update_flaggedpages( $startPage ); |
| 150 | + $db = wfGetDB( DB_MASTER ); |
61 | 151 | |
62 | | -update_flaggedimages( $startRev ); |
| 152 | + if ( $start === null ) { |
| 153 | + $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ ); |
| 154 | + } |
| 155 | + $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ ); |
| 156 | + if ( is_null( $start ) || is_null( $end ) ) { |
| 157 | + $this->output( "...flaggedpages table seems to be empty.\n" ); |
| 158 | + return; |
| 159 | + } |
| 160 | + # Do remaining chunk |
| 161 | + $end += $BATCH_SIZE - 1; |
| 162 | + $blockStart = $start; |
| 163 | + $blockEnd = $start + $BATCH_SIZE - 1; |
| 164 | + $count = $deleted = $fixed = 0; |
| 165 | + while ( $blockEnd <= $end ) { |
| 166 | + $this->output( "...doing page_id from $blockStart to $blockEnd\n" ); |
| 167 | + $cond = "page_id BETWEEN $blockStart AND $blockEnd"; |
| 168 | + $res = $db->select( 'page', |
| 169 | + array( 'page_id', 'page_namespace', 'page_title', 'page_latest' ), |
| 170 | + $cond, __METHOD__ ); |
| 171 | + # Go through and update the de-normalized references... |
| 172 | + $db->begin(); |
| 173 | + foreach ( $res as $row ) { |
| 174 | + $title = Title::newFromRow( $row ); |
| 175 | + $article = new FlaggableWikiPage( $title ); |
| 176 | + $oldFrev = FlaggedRevision::newFromStable( $title, FR_MASTER ); |
| 177 | + $frev = FlaggedRevision::determineStable( $title, FR_MASTER ); |
| 178 | + # Update fp_stable, fp_quality, and fp_reviewed |
| 179 | + if ( $frev ) { |
| 180 | + $article->updateStableVersion( $frev, $row->page_latest ); |
| 181 | + $changed = ( !$oldFrev || $oldFrev->getRevId() != $frev->getRevId() ); |
| 182 | + # Somethings broke? Delete the row... |
| 183 | + } else { |
| 184 | + $article->clearStableVersion(); |
| 185 | + if ( $db->affectedRows() > 0 ) $deleted++; |
| 186 | + $changed = (bool)$oldFrev; |
| 187 | + } |
| 188 | + # Get the latest revision |
| 189 | + $revRow = $db->selectRow( 'revision', '*', |
| 190 | + array( 'rev_page' => $row->page_id ), |
| 191 | + __METHOD__, |
| 192 | + array( 'ORDER BY' => 'rev_timestamp DESC' ) ); |
| 193 | + # Correct page_latest if needed (import/files made plenty of bad rows) |
| 194 | + if ( $revRow ) { |
| 195 | + $revision = new Revision( $revRow ); |
| 196 | + if ( $article->updateIfNewerOn( $db, $revision ) ) { |
| 197 | + $fixed++; |
| 198 | + } |
| 199 | + } |
| 200 | + if ( $changed ) { |
| 201 | + # Lazily rebuild dependancies on next parse (we invalidate below) |
| 202 | + FlaggedRevs::clearStableOnlyDeps( $title ); |
| 203 | + $title->invalidateCache(); |
| 204 | + } |
| 205 | + $count++; |
| 206 | + } |
| 207 | + $db->freeResult( $res ); |
| 208 | + # Remove manual config settings that simply restate the site defaults |
| 209 | + $db->delete( 'flaggedpage_config', |
| 210 | + array( "fpc_page_id BETWEEN $blockStart AND $blockEnd", |
| 211 | + 'fpc_override' => intval( FlaggedRevs::isStableShownByDefault() ), |
| 212 | + 'fpc_level' => '' |
| 213 | + ), |
| 214 | + __METHOD__ |
| 215 | + ); |
| 216 | + $deleted = $deleted + $db->affectedRows(); |
| 217 | + $db->commit(); |
| 218 | + $blockStart += $BATCH_SIZE; |
| 219 | + $blockEnd += $BATCH_SIZE; |
| 220 | + wfWaitForSlaves( 5 ); |
| 221 | + } |
| 222 | + $this->output( "flaggedpage columns update complete ..." . |
| 223 | + " {$count} rows [{$fixed} fixed] [{$deleted} deleted]\n" ); |
| 224 | + } |
| 225 | + |
| 226 | + protected function update_flaggedimages( $start = null ) { |
| 227 | + $this->output( "Cleaning up flaggedimages columns\n" ); |
| 228 | + |
| 229 | + $BATCH_SIZE = 1000; |
| 230 | + |
| 231 | + $db = wfGetDB( DB_MASTER ); |
| 232 | + |
| 233 | + if ( $start === null ) { |
| 234 | + $start = $db->selectField( 'flaggedimages', 'MIN(fi_rev_id)', false, __METHOD__ ); |
| 235 | + } |
| 236 | + $end = $db->selectField( 'flaggedimages', 'MAX(fi_rev_id)', false, __METHOD__ ); |
| 237 | + if ( is_null( $start ) || is_null( $end ) ) { |
| 238 | + $this->output( "...flaggedimages table seems to be empty.\n" ); |
| 239 | + return; |
| 240 | + } |
| 241 | + # Do remaining chunk |
| 242 | + $end += $BATCH_SIZE - 1; |
| 243 | + $blockStart = $start; |
| 244 | + $blockEnd = $start + $BATCH_SIZE - 1; |
| 245 | + $nulled = 0; |
| 246 | + while ( $blockEnd <= $end ) { |
| 247 | + $this->output( "...doing fi_rev_id from $blockStart to $blockEnd\n" ); |
| 248 | + $cond = "fi_rev_id BETWEEN $blockStart AND $blockEnd"; |
| 249 | + $db->begin(); |
| 250 | + # Remove padding garbage and such...turn to NULL instead |
| 251 | + $db->update( 'flaggedimages', |
| 252 | + array( 'fi_img_timestamp' => null ), |
| 253 | + array( $cond, "fi_img_timestamp = '' OR LOCATE( '\\0', fi_img_timestamp )" ), |
| 254 | + __METHOD__ |
| 255 | + ); |
| 256 | + if ( $db->affectedRows() > 0 ) { |
| 257 | + $nulled += $db->affectedRows(); |
| 258 | + } |
| 259 | + $db->commit(); |
| 260 | + $blockStart += $BATCH_SIZE; |
| 261 | + $blockEnd += $BATCH_SIZE; |
| 262 | + wfWaitForSlaves( 5 ); |
| 263 | + } |
| 264 | + $this->output( "flaggedimages columns update complete ... [{$nulled} fixed]\n" ); |
| 265 | + } |
| 266 | +} |
| 267 | + |
| 268 | +$maintClass = "UpdateFRTracking"; |
| 269 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
Index: trunk/extensions/FlaggedRevs/maintenance/cachePendingRevs.php |
— | — | @@ -6,14 +6,15 @@ |
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( getenv( 'MW_INSTALL_PATH' ) ) { |
10 | | - $IP = getenv( 'MW_INSTALL_PATH' ); |
| 10 | + $IP = getenv( 'MW_INSTALL_PATH' ); |
11 | 11 | } else { |
12 | | - $IP = dirname(__FILE__).'/../../..'; |
| 12 | + $IP = dirname(__FILE__).'/../../..'; |
13 | 13 | } |
14 | 14 | |
15 | 15 | require_once( "$IP/maintenance/Maintenance.php" ); |
16 | 16 | |
17 | 17 | class CachePendingRevs extends Maintenance { |
| 18 | + |
18 | 19 | public function __construct() { |
19 | 20 | parent::__construct(); |
20 | 21 | $this->mDescription = "Cache pending revision data"; |