3 require_once( 'FiveUpgrade.inc' );
8 abstract class TableCleanup extends FiveUpgrade {
9 function __construct( $table, $dryrun = false ) {
10 parent::__construct();
12 $this->targetTable = $table;
13 $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait
14 $this->dryrun = $dryrun;
19 echo "Checking for bad titles...\n";
21 echo "Checking and fixing bad titles...\n";
23 $this->runTable( $this->targetTable,
24 '', //'WHERE page_namespace=0',
25 array( $this, 'processPage' ) );
28 function init( $count, $table ) {
31 $this->count = $count;
32 $this->startTime = wfTime();
33 $this->table = $table;
36 function progress( $updated ) {
37 $this->updated += $updated;
39 if( $this->processed % 100 != 0 ) {
42 $portion = $this->processed / $this->count;
43 $updateRate = $this->updated / $this->processed;
46 $delta = $now - $this->startTime;
47 $estimatedTotalTime = $delta / $portion;
48 $eta = $this->startTime + $estimatedTotalTime;
50 printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
52 wfTimestamp( TS_DB, intval( $now ) ),
55 wfTimestamp( TS_DB, intval( $eta ) ),
58 $this->processed / $delta,
59 $updateRate * 100.0 );
63 function runTable( $table, $where, $callback ) {
64 $fname = 'CapsCleanup::buildTable';
66 $count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
67 $this->init( $count, $table );
68 $this->log( "Processing $table..." );
70 $tableName = $this->dbr->tableName( $table );
71 $sql = "SELECT * FROM $tableName $where";
72 $result = $this->dbr->query( $sql, $fname );
74 while( $row = $this->dbr->fetchObject( $result ) ) {
75 call_user_func( $callback, $row );
77 $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
78 $this->dbr->freeResult( $result );
81 function hexChar( $matches ) {
82 return sprintf( "\\x%02x", ord( $matches[1] ) );
85 abstract function processPage( $row );