Index: trunk/extensions/FlaggedRevs/maintenance/purgeReviewablePages.inc |
— | — | @@ -1,18 +1,20 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -function purge_reviewable_pages( $db ) { |
| 4 | +function list_reviewable_pages( $db, $fileHandle ) { |
5 | 5 | global $wgFlaggedRevsNamespaces, $wgUseSquid, $wgUseFileCache; |
6 | | - echo "Purging squid cache for all reviewable pages...\n"; |
7 | | - if ( !$wgUseSquid || !$wgUseFileCache ) { |
8 | | - echo "Squid/file cache not enabled...nothing to purge.\n"; |
| 6 | + echo "Building list of all reviewable pages to purge ...\n"; |
| 7 | + if ( !$wgUseSquid && !$wgUseFileCache ) { |
| 8 | + echo "Squid/file cache not enabled ... nothing to purge.\n"; |
| 9 | + return; |
9 | 10 | } elseif ( empty( $wgFlaggedRevsNamespaces ) ) { |
10 | | - echo "There are no reviewable namespaces...nothing to purge.\n"; |
| 11 | + echo "There are no reviewable namespaces ... nothing to purge.\n"; |
| 12 | + return; |
11 | 13 | } |
12 | 14 | $BATCH_SIZE = 500; |
13 | 15 | $start = $db->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
14 | 16 | $end = $db->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ ); |
15 | 17 | if ( is_null( $start ) || is_null( $end ) ) { |
16 | | - echo "...page table seems to be empty.\n"; |
| 18 | + echo "... page table seems to be empty.\n"; |
17 | 19 | return; |
18 | 20 | } |
19 | 21 | # Do remaining chunk |
— | — | @@ -21,7 +23,7 @@ |
22 | 24 | $blockEnd = $start + $BATCH_SIZE - 1; |
23 | 25 | $count = 0; |
24 | 26 | while ( $blockEnd <= $end ) { |
25 | | - echo "...doing page_id from $blockStart to $blockEnd\n"; |
| 27 | + echo "... doing page_id from $blockStart to $blockEnd\n"; |
26 | 28 | $res = $db->select( 'page', '*', |
27 | 29 | array( |
28 | 30 | "page_id BETWEEN $blockStart AND $blockEnd", |
— | — | @@ -33,15 +35,43 @@ |
34 | 36 | $title = Title::newFromRow( $row ); |
35 | 37 | $fa = FlaggedArticle::getTitleInstance( $title ); |
36 | 38 | if ( $fa->isReviewable( FR_MASTER ) ) { |
37 | | - $title->purgeSquid(); // send PURGE |
38 | | - HTMLFileCache::clearFileCache( $title ); // purge poor-mans's squid |
| 39 | + # Need to purge this page - add to list |
| 40 | + fwrite( $fileHandle, $title->getPrefixedDBKey() . "\n" ); |
39 | 41 | $count++; |
40 | 42 | } |
41 | 43 | } |
42 | 44 | $db->freeResult( $res ); |
43 | 45 | $blockStart += $BATCH_SIZE - 1; |
44 | 46 | $blockEnd += $BATCH_SIZE - 1; |
45 | | - wfWaitForSlaves( 5 ); |
| 47 | + wfWaitForSlaves( 5 ); // not really needed |
46 | 48 | } |
47 | | - echo "Squid/file cache purge of all reviewable pages complete ... {$count} pages\n"; |
| 49 | + echo "List of reviewable pages to purge complete ... {$count} pages\n"; |
48 | 50 | } |
| 51 | + |
| 52 | +function purge_reviewable_pages( $db, $fileHandle ) { |
| 53 | + global $wgUseSquid, $wgUseFileCache; |
| 54 | + echo "Purging squid cache for list of pages to purge ...\n"; |
| 55 | + if ( !$wgUseSquid && !$wgUseFileCache ) { |
| 56 | + echo "Squid/file cache not enabled ... nothing to purge.\n"; |
| 57 | + return; |
| 58 | + } |
| 59 | + $BATCH_SIZE = 500; |
| 60 | + $count = 0; |
| 61 | + while ( !feof( $fileHandle ) ) { |
| 62 | + $dbKey = trim( fgets( $fileHandle ) ); |
| 63 | + if ( $dbKey == '' ) continue; // last line? |
| 64 | + $title = Title::newFromDBkey( $dbKey ); |
| 65 | + if ( $title ) { |
| 66 | + $title->purgeSquid(); // send PURGE |
| 67 | + HTMLFileCache::clearFileCache( $title ); // purge poor-mans's squid |
| 68 | + $count++; |
| 69 | + echo "... $dbKey\n"; |
| 70 | + if ( $count % $BATCH_SIZE ) { |
| 71 | + wfWaitForSlaves( 5 ); // not really needed |
| 72 | + } |
| 73 | + } else { |
| 74 | + echo "Invalid title - cannot purge: $dbKey\n"; |
| 75 | + } |
| 76 | + } |
| 77 | + echo "Squid/file cache purge of page list complete ... {$count} pages\n"; |
| 78 | +} |
Index: trunk/extensions/FlaggedRevs/maintenance/purgeReviewablePages.php |
— | — | @@ -8,20 +8,48 @@ |
9 | 9 | require "$IP/maintenance/commandLine.inc"; |
10 | 10 | require dirname(__FILE__) . '/purgeReviewablePages.inc'; |
11 | 11 | |
12 | | -if( isset( $options['help'] ) ) { |
| 12 | +$makeList = isset( $options['makelist'] ); |
| 13 | +$purgeList = isset( $options['purgelist'] ); |
| 14 | + |
| 15 | +if ( isset( $options['help'] ) || ( !$makeList && !$purgeList ) ) { |
13 | 16 | echo <<<TEXT |
14 | 17 | Purpose: |
15 | | - Purge squid/file cache for all reviewable pages |
| 18 | + Use to purge squid/file cache for all reviewable pages |
16 | 19 | Usage: |
17 | 20 | php purgeReviewablePages.php --help |
| 21 | + php purgeReviewablePages.php --makelist |
| 22 | + php purgeReviewablePages.php --purgelist |
18 | 23 | |
19 | | - --help : This help message |
| 24 | + --help : This help message |
| 25 | + --makelist : Build the list of reviewable pages to pagesToPurge.list |
| 26 | + --purgelist : Purge the list of pages in pagesToPurge.list |
20 | 27 | |
21 | 28 | TEXT; |
22 | | - exit(0); |
| 29 | + exit( 0 ); |
23 | 30 | } |
24 | 31 | |
25 | 32 | error_reporting( E_ALL ); |
26 | 33 | |
27 | | -$db = wfGetDB( DB_MASTER ); |
28 | | -purge_reviewable_pages( $db ); |
| 34 | +$fileName = "pagesToPurge.list"; |
| 35 | + |
| 36 | +if ( $makeList ) { |
| 37 | + $db = wfGetDB( DB_MASTER ); |
| 38 | + $fileHandle = fopen( $fileName, 'w+' ); |
| 39 | + if ( !$fileHandle ) { |
| 40 | + echo "Can't open file to create purge list.\n"; |
| 41 | + exit( -1 ); |
| 42 | + } |
| 43 | + list_reviewable_pages( $db, $fileHandle ); |
| 44 | + fclose( $fileHandle ); |
| 45 | +} |
| 46 | + |
| 47 | +if ( $purgeList ) { |
| 48 | + $db = wfGetDB( DB_MASTER ); |
| 49 | + $fileHandle = fopen( $fileName, 'r' ); |
| 50 | + if ( !$fileHandle ) { |
| 51 | + echo "Can't open file to read purge list.\n"; |
| 52 | + exit( -1 ); |
| 53 | + } |
| 54 | + purge_reviewable_pages( $db, $fileHandle ); |
| 55 | + fclose( $fileHandle ); |
| 56 | +} |