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 $count = $this->dbw->selectField( $table, 'count(*)', '', __METHOD__ );
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, __METHOD__ );
72 foreach( $result as $row ) {
73 call_user_func( $callback, $row );
75 $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
79 function hexChar( $matches ) {
80 return sprintf( "\\x%02x", ord( $matches[1] ) );
83 abstract function processPage( $row );