Index: trunk/phase3/maintenance/rebuildFileCache.php |
— | — | @@ -26,29 +26,42 @@ |
27 | 27 | public function __construct() { |
28 | 28 | parent::__construct(); |
29 | 29 | $this->mDescription = "Build file cache for content pages"; |
30 | | - $this->addArg( 'start', 'Page_id to start from', true ); |
31 | | - $this->addArg( 'overwrite', 'Refresh page cache', false ); |
| 30 | + $this->addOption( 'start', 'Page_id to start from', false, true ); |
| 31 | + $this->addOption( 'end', 'Page_id to end on', false, true ); |
| 32 | + $this->addOption( 'overwrite', 'Refresh page cache' ); |
32 | 33 | $this->setBatchSize( 100 ); |
33 | 34 | } |
34 | 35 | |
35 | 36 | public function execute() { |
36 | | - global $wgUseFileCache, $wgDisableCounters, $wgContentNamespaces, $wgRequestTime; |
| 37 | + global $wgUseFileCache, $wgReadOnly, $wgContentNamespaces, $wgRequestTime; |
37 | 38 | global $wgTitle, $wgOut; |
38 | 39 | if ( !$wgUseFileCache ) { |
39 | 40 | $this->error( "Nothing to do -- \$wgUseFileCache is disabled.", true ); |
40 | 41 | } |
41 | | - $wgDisableCounters = true; |
42 | | - $start = $this->getArg( 0, "0" ); |
| 42 | + $wgReadOnly = 'Building cache'; // avoid DB writes (like enotif/counters) |
| 43 | + |
| 44 | + $start = $this->getOption( 'start', "0" ); |
43 | 45 | if ( !ctype_digit( $start ) ) { |
44 | 46 | $this->error( "Invalid value for start parameter.", true ); |
45 | 47 | } |
46 | 48 | $start = intval( $start ); |
47 | | - $overwrite = $this->hasArg( 1 ) && $this->getArg( 1 ) === 'overwrite'; |
| 49 | + |
| 50 | + $end = $this->getOption( 'end', "0" ); |
| 51 | + if ( !ctype_digit( $end ) ) { |
| 52 | + $this->error( "Invalid value for end parameter.", true ); |
| 53 | + } |
| 54 | + $end = intval( $end ); |
| 55 | + |
48 | 56 | $this->output( "Building content page file cache from page {$start}!\n" ); |
49 | 57 | |
50 | 58 | $dbr = wfGetDB( DB_SLAVE ); |
51 | | - $start = $start > 0 ? $start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
52 | | - $end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ ); |
| 59 | + $overwrite = $this->getOption( 'overwrite', false ); |
| 60 | + $start = ( $start > 0 ) |
| 61 | + ? $start |
| 62 | + : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ ); |
| 63 | + $end = ( $end > 0 ) |
| 64 | + ? $end |
| 65 | + : $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ ); |
53 | 66 | if ( !$start ) { |
54 | 67 | $this->error( "Nothing to do.", true ); |
55 | 68 | } |
— | — | @@ -69,6 +82,8 @@ |
70 | 83 | "page_id BETWEEN $blockStart AND $blockEnd" ), |
71 | 84 | array( 'ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY' ) |
72 | 85 | ); |
| 86 | + |
| 87 | + $dbw->begin(); // for any changes |
73 | 88 | foreach ( $res as $row ) { |
74 | 89 | $rebuilt = false; |
75 | 90 | $wgRequestTime = wfTime(); # bug 22852 |
— | — | @@ -100,18 +115,19 @@ |
101 | 116 | wfRestoreWarnings(); |
102 | 117 | $wgUseFileCache = true; |
103 | 118 | ob_end_clean(); // clear buffer |
104 | | - if ( $rebuilt ) |
| 119 | + if ( $rebuilt ) { |
105 | 120 | $this->output( "Re-cached page {$row->page_id}\n" ); |
106 | | - else |
| 121 | + } else { |
107 | 122 | $this->output( "Cached page {$row->page_id}\n" ); |
| 123 | + } |
108 | 124 | } else { |
109 | 125 | $this->output( "Page {$row->page_id} not cacheable\n" ); |
110 | 126 | } |
111 | | - $dbw->commit(); // commit any changes |
112 | 127 | } |
| 128 | + $dbw->commit(); // commit any changes (just for sanity) |
| 129 | + |
113 | 130 | $blockStart += $this->mBatchSize; |
114 | 131 | $blockEnd += $this->mBatchSize; |
115 | | - wfWaitForSlaves(); |
116 | 132 | } |
117 | 133 | $this->output( "Done!\n" ); |
118 | 134 | |