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;
47 printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
49 wfTimestamp( TS_DB, intval( $now ) ),
52 wfTimestamp( TS_DB, intval( $eta ) ),
55 $this->processed / $delta,
56 $updateRate * 100.0 );
60 function runTable( $table, $where, $callback ) {
61 $fname = 'CapsCleanup::buildTable';
63 $count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
64 $this->init( $count, $table );
65 $this->log( "Processing $table..." );
67 $tableName = $this->dbr->tableName( $table );
68 $sql = "SELECT * FROM $tableName $where";
69 $result = $this->dbr->query( $sql, $fname );
71 while( $row = $this->dbr->fetchObject( $result ) ) {
72 $updated = call_user_func( $callback, $row );
74 $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
75 $this->dbr->freeResult( $result );
78 function hexChar( $matches ) {
79 return sprintf( "\\x%02x", ord( $matches[1] ) );
82 abstract function processPage( $row );