Localisation updates for core messages from Betawiki (2008-05-05 23:21 CEST)
[lhc/web/wiklou.git] / maintenance / cleanupTable.inc
1 <?php
2
3 require_once( 'FiveUpgrade.inc' );
4
5 abstract class TableCleanup extends FiveUpgrade {
6 function __construct( $table, $dryrun = false ) {
7 parent::__construct();
8
9 $this->targetTable = $table;
10 $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait
11 $this->dryrun = $dryrun;
12 }
13
14 function cleanup() {
15 if( $this->dryrun ) {
16 echo "Checking for bad titles...\n";
17 } else {
18 echo "Checking and fixing bad titles...\n";
19 }
20 $this->runTable( $this->targetTable,
21 '', //'WHERE page_namespace=0',
22 array( $this, 'processPage' ) );
23 }
24
25 function init( $count, $table ) {
26 $this->processed = 0;
27 $this->updated = 0;
28 $this->count = $count;
29 $this->startTime = wfTime();
30 $this->table = $table;
31 }
32
33 function progress( $updated ) {
34 $this->updated += $updated;
35 $this->processed++;
36 if( $this->processed % 100 != 0 ) {
37 return;
38 }
39 $portion = $this->processed / $this->count;
40 $updateRate = $this->updated / $this->processed;
41
42 $now = wfTime();
43 $delta = $now - $this->startTime;
44 $estimatedTotalTime = $delta / $portion;
45 $eta = $this->startTime + $estimatedTotalTime;
46
47 printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
48 wfWikiID(),
49 wfTimestamp( TS_DB, intval( $now ) ),
50 $portion * 100.0,
51 $this->table,
52 wfTimestamp( TS_DB, intval( $eta ) ),
53 $this->processed,
54 $this->count,
55 $this->processed / $delta,
56 $updateRate * 100.0 );
57 flush();
58 }
59
60 function runTable( $table, $where, $callback ) {
61 $fname = 'CapsCleanup::buildTable';
62
63 $count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
64 $this->init( $count, $table );
65 $this->log( "Processing $table..." );
66
67 $tableName = $this->dbr->tableName( $table );
68 $sql = "SELECT * FROM $tableName $where";
69 $result = $this->dbr->query( $sql, $fname );
70
71 while( $row = $this->dbr->fetchObject( $result ) ) {
72 call_user_func( $callback, $row );
73 }
74 $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
75 $this->dbr->freeResult( $result );
76 }
77
78 function hexChar( $matches ) {
79 return sprintf( "\\x%02x", ord( $matches[1] ) );
80 }
81
82 abstract function processPage( $row );
83
84 }
85
86 ?>