3 require_once( 'FiveUpgrade.inc' );
5 abstract class TableCleanup extends FiveUpgrade {
6 function __construct( $table, $dryrun = false ) {
9 $this->targetTable = $table;
10 $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait
11 $this->dryrun = $dryrun;
16 echo "Checking for bad titles...\n";
18 echo "Checking and fixing bad titles...\n";
20 $this->runTable( $this->targetTable,
21 '', //'WHERE page_namespace=0',
22 array( $this, 'processPage' ) );
25 function init( $count, $table ) {
28 $this->count = $count;
29 $this->startTime = wfTime();
30 $this->table = $table;
33 function progress( $updated ) {
34 $this->updated += $updated;
36 if( $this->processed % 100 != 0 ) {
39 $portion = $this->processed / $this->count;
40 $updateRate = $this->updated / $this->processed;
43 $delta = $now - $this->startTime;
44 $estimatedTotalTime = $delta / $portion;
45 $eta = $this->startTime + $estimatedTotalTime;
48 printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
50 wfTimestamp( TS_DB, intval( $now ) ),
53 wfTimestamp( TS_DB, intval( $eta ) ),
56 $this->processed / $delta,
57 $updateRate * 100.0 );
61 function runTable( $table, $where, $callback ) {
62 $fname = 'CapsCleanup::buildTable';
64 $count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
65 $this->init( $count, $table );
66 $this->log( "Processing $table..." );
68 $tableName = $this->dbr->tableName( $table );
69 $sql = "SELECT * FROM $tableName $where";
70 $result = $this->dbr->query( $sql, $fname );
72 while( $row = $this->dbr->fetchObject( $result ) ) {
73 $updated = call_user_func( $callback, $row );
75 $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
76 $this->dbr->freeResult( $result );
79 function hexChar( $matches ) {
80 return sprintf( "\\x%02x", ord( $matches[1] ) );
83 abstract function processPage( $row );