Index: trunk/phase3/maintenance/cleanupWatchlist.php |
— | — | @@ -29,82 +29,18 @@ |
30 | 30 | * @ingroup Maintenance |
31 | 31 | */ |
32 | 32 | |
33 | | -$options = array( 'fix' ); |
34 | | - |
35 | 33 | require_once( 'commandLine.inc' ); |
36 | | -require_once( 'FiveUpgrade.inc' ); |
| 34 | +require_once( 'CleanupTable.inc' ); |
37 | 35 | |
38 | 36 | /** |
39 | 37 | * @ingroup Maintenance |
40 | 38 | */ |
41 | | -class WatchlistCleanup extends FiveUpgrade { |
42 | | - function WatchlistCleanup( $dryrun = false ) { |
43 | | - parent::FiveUpgrade(); |
44 | | - |
45 | | - $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait |
46 | | - $this->dryrun = $dryrun; |
| 39 | +class WatchlistCleanup extends TableCleanup { |
| 40 | + function __construct( $dryrun = false ) { |
| 41 | + parent::__construct( 'watchlist', $dryrun ); |
47 | 42 | } |
48 | 43 | |
49 | | - function cleanup() { |
50 | | - $this->runTable( 'watchlist', |
51 | | - '', |
52 | | - array( &$this, 'processEntry' ) ); |
53 | | - } |
54 | | - |
55 | | - function init( $count, $table ) { |
56 | | - $this->processed = 0; |
57 | | - $this->updated = 0; |
58 | | - $this->count = $count; |
59 | | - $this->startTime = wfTime(); |
60 | | - $this->table = $table; |
61 | | - } |
62 | | - |
63 | | - function progress( $updated ) { |
64 | | - $this->updated += $updated; |
65 | | - $this->processed++; |
66 | | - if( $this->processed % 100 != 0 ) { |
67 | | - return; |
68 | | - } |
69 | | - $portion = $this->processed / $this->count; |
70 | | - $updateRate = $this->updated / $this->processed; |
71 | | - |
72 | | - $now = wfTime(); |
73 | | - $delta = $now - $this->startTime; |
74 | | - $estimatedTotalTime = $delta / $portion; |
75 | | - $eta = $this->startTime + $estimatedTotalTime; |
76 | | - |
77 | | - printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n", |
78 | | - wfWikiID(), |
79 | | - wfTimestamp( TS_DB, intval( $now ) ), |
80 | | - $portion * 100.0, |
81 | | - $this->table, |
82 | | - wfTimestamp( TS_DB, intval( $eta ) ), |
83 | | - $this->processed, |
84 | | - $this->count, |
85 | | - $this->processed / $delta, |
86 | | - $updateRate * 100.0 ); |
87 | | - flush(); |
88 | | - } |
89 | | - |
90 | | - function runTable( $table, $where, $callback ) { |
91 | | - $fname = 'WatchlistCleanup::runTable'; |
92 | | - |
93 | | - $count = $this->dbw->selectField( $table, 'count(*)', '', $fname ); |
94 | | - $this->init( $count, 'watchlist' ); |
95 | | - $this->log( "Processing $table..." ); |
96 | | - |
97 | | - $tableName = $this->dbr->tableName( $table ); |
98 | | - $sql = "SELECT * FROM $tableName $where"; |
99 | | - $result = $this->dbr->query( $sql, $fname ); |
100 | | - |
101 | | - while( $row = $this->dbr->fetchObject( $result ) ) { |
102 | | - call_user_func( $callback, $row ); |
103 | | - } |
104 | | - $this->log( "Finished $table... $this->updated of $this->processed rows updated" ); |
105 | | - $this->dbr->freeResult( $result ); |
106 | | - } |
107 | | - |
108 | | - function processEntry( $row ) { |
| 44 | + function processPage( $row ) { |
109 | 45 | $current = Title::makeTitle( $row->wl_namespace, $row->wl_title ); |
110 | 46 | $display = $current->getPrefixedText(); |
111 | 47 | |
— | — | @@ -122,13 +58,13 @@ |
123 | 59 | } |
124 | 60 | |
125 | 61 | function removeWatch( $row ) { |
126 | | - if( !$this->dryrun) { |
| 62 | + if( !$this->dryrun ) { |
127 | 63 | $dbw = wfGetDB( DB_MASTER ); |
128 | 64 | $dbw->delete( 'watchlist', array( |
129 | 65 | 'wl_user' => $row->wl_user, |
130 | 66 | 'wl_namespace' => $row->wl_namespace, |
131 | 67 | 'wl_title' => $row->wl_title ), |
132 | | - 'WatchlistCleanup::removeWatch' ); |
| 68 | + __METHOD__ ); |
133 | 69 | $this->log( '- removed' ); |
134 | 70 | } |
135 | 71 | } |
Index: trunk/phase3/maintenance/cleanupTable.inc |
— | — | @@ -61,21 +61,19 @@ |
62 | 62 | } |
63 | 63 | |
64 | 64 | function runTable( $table, $where, $callback ) { |
65 | | - $fname = 'CapsCleanup::buildTable'; |
66 | | - |
67 | | - $count = $this->dbw->selectField( $table, 'count(*)', '', $fname ); |
| 65 | + $count = $this->dbw->selectField( $table, 'count(*)', '', __METHOD__ ); |
68 | 66 | $this->init( $count, $table ); |
69 | 67 | $this->log( "Processing $table..." ); |
70 | 68 | |
71 | 69 | $tableName = $this->dbr->tableName( $table ); |
72 | 70 | $sql = "SELECT * FROM $tableName $where"; |
73 | | - $result = $this->dbr->query( $sql, $fname ); |
| 71 | + $result = $this->dbr->query( $sql, __METHOD__ ); |
74 | 72 | |
75 | | - while( $row = $this->dbr->fetchObject( $result ) ) { |
| 73 | + foreach( $result as $row ) { |
76 | 74 | call_user_func( $callback, $row ); |
77 | 75 | } |
78 | 76 | $this->log( "Finished $table... $this->updated of $this->processed rows updated" ); |
79 | | - $this->dbr->freeResult( $result ); |
| 77 | + $result->free(); |
80 | 78 | } |
81 | 79 | |
82 | 80 | function hexChar( $matches ) { |
Index: trunk/phase3/maintenance/cleanupCaps.php |
— | — | @@ -29,20 +29,17 @@ |
30 | 30 | * @ingroup maintenance |
31 | 31 | */ |
32 | 32 | |
33 | | -$options = array( 'dry-run' ); |
| 33 | +$optionsWithArgs = array( 'namespace' ); |
34 | 34 | |
35 | 35 | require_once( 'commandLine.inc' ); |
36 | | -require_once( 'FiveUpgrade.inc' ); |
| 36 | +require_once( 'CleanupTable.inc' ); |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @ingroup Maintenance |
40 | 40 | */ |
41 | | -class CapsCleanup extends FiveUpgrade { |
42 | | - function CapsCleanup( $dryrun = false, $namespace=0 ) { |
43 | | - parent::FiveUpgrade(); |
44 | | - |
45 | | - $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait |
46 | | - $this->dryrun = $dryrun; |
| 41 | +class CapsCleanup extends TableCleanup { |
| 42 | + function __construct( $dryrun = false, $namespace = 0 ) { |
| 43 | + parent::__construct( 'page', $dryrun ); |
47 | 44 | $this->namespace = intval( $namespace ); |
48 | 45 | } |
49 | 46 | |
— | — | @@ -53,62 +50,11 @@ |
54 | 51 | return false; |
55 | 52 | } |
56 | 53 | |
57 | | - $this->runTable( 'page', 'WHERE page_namespace=' . $this->namespace, |
| 54 | + $this->runTable( $this->targetTable, |
| 55 | + 'WHERE page_namespace=' . $this->namespace, |
58 | 56 | array( &$this, 'processPage' ) ); |
59 | 57 | } |
60 | 58 | |
61 | | - function init( $count, $table ) { |
62 | | - $this->processed = 0; |
63 | | - $this->updated = 0; |
64 | | - $this->count = $count; |
65 | | - $this->startTime = wfTime(); |
66 | | - $this->table = $table; |
67 | | - } |
68 | | - |
69 | | - function progress( $updated ) { |
70 | | - $this->updated += $updated; |
71 | | - $this->processed++; |
72 | | - if( $this->processed % 100 != 0 ) { |
73 | | - return; |
74 | | - } |
75 | | - $portion = $this->processed / $this->count; |
76 | | - $updateRate = $this->updated / $this->processed; |
77 | | - |
78 | | - $now = wfTime(); |
79 | | - $delta = $now - $this->startTime; |
80 | | - $estimatedTotalTime = $delta / $portion; |
81 | | - $eta = $this->startTime + $estimatedTotalTime; |
82 | | - |
83 | | - printf( "%s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n", |
84 | | - wfTimestamp( TS_DB, intval( $now ) ), |
85 | | - $portion * 100.0, |
86 | | - $this->table, |
87 | | - wfTimestamp( TS_DB, intval( $eta ) ), |
88 | | - $this->processed, |
89 | | - $this->count, |
90 | | - $this->processed / $delta, |
91 | | - $updateRate * 100.0 ); |
92 | | - flush(); |
93 | | - } |
94 | | - |
95 | | - function runTable( $table, $where, $callback ) { |
96 | | - $fname = 'CapsCleanup::buildTable'; |
97 | | - |
98 | | - $count = $this->dbw->selectField( $table, 'count(*)', '', $fname ); |
99 | | - $this->init( $count, 'page' ); |
100 | | - $this->log( "Processing $table..." ); |
101 | | - |
102 | | - $tableName = $this->dbr->tableName( $table ); |
103 | | - $sql = "SELECT * FROM $tableName $where"; |
104 | | - $result = $this->dbr->query( $sql, $fname ); |
105 | | - |
106 | | - while( $row = $this->dbr->fetchObject( $result ) ) { |
107 | | - call_user_func( $callback, $row ); |
108 | | - } |
109 | | - $this->log( "Finished $table... $this->updated of $this->processed rows updated" ); |
110 | | - $this->dbr->freeResult( $result ); |
111 | | - } |
112 | | - |
113 | 59 | function processPage( $row ) { |
114 | 60 | global $wgContLang; |
115 | 61 | |