29
29
* @ingroup maintenance
32
$options = array( 'dry-run' );
32
$optionsWithArgs = array( 'namespace' );
34
34
require_once( 'commandLine.inc' );
35
require_once( 'FiveUpgrade.inc' );
35
require_once( 'cleanupTable.inc' );
38
38
* @ingroup Maintenance
40
class CapsCleanup extends FiveUpgrade {
41
function CapsCleanup( $dryrun = false, $namespace=0 ) {
42
parent::FiveUpgrade();
44
$this->maxLag = 10; # if slaves are lagged more than 10 secs, wait
45
$this->dryrun = $dryrun;
40
class CapsCleanup extends TableCleanup {
41
function __construct( $dryrun = false, $namespace = 0 ) {
42
parent::__construct( 'page', $dryrun );
46
43
$this->namespace = intval( $namespace );
56
$this->runTable( 'page', 'WHERE page_namespace=' . $this->namespace,
53
$this->runTable( $this->targetTable,
54
'WHERE page_namespace=' . $this->namespace,
57
55
array( &$this, 'processPage' ) );
60
function init( $count, $table ) {
63
$this->count = $count;
64
$this->startTime = wfTime();
65
$this->table = $table;
68
function progress( $updated ) {
69
$this->updated += $updated;
71
if( $this->processed % 100 != 0 ) {
74
$portion = $this->processed / $this->count;
75
$updateRate = $this->updated / $this->processed;
78
$delta = $now - $this->startTime;
79
$estimatedTotalTime = $delta / $portion;
80
$eta = $this->startTime + $estimatedTotalTime;
82
printf( "%s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
83
wfTimestamp( TS_DB, intval( $now ) ),
86
wfTimestamp( TS_DB, intval( $eta ) ),
89
$this->processed / $delta,
90
$updateRate * 100.0 );
94
function runTable( $table, $where, $callback ) {
95
$fname = 'CapsCleanup::buildTable';
97
$count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
98
$this->init( $count, 'page' );
99
$this->log( "Processing $table..." );
101
$tableName = $this->dbr->tableName( $table );
102
$sql = "SELECT * FROM $tableName $where";
103
$result = $this->dbr->query( $sql, $fname );
105
while( $row = $this->dbr->fetchObject( $result ) ) {
106
call_user_func( $callback, $row );
108
$this->log( "Finished $table... $this->updated of $this->processed rows updated" );
109
$this->dbr->freeResult( $result );
112
58
function processPage( $row ) {
113
59
global $wgContLang;