~ubuntu-branches/ubuntu/maverick/mediawiki/maverick

« back to all changes in this revision

Viewing changes to maintenance/cleanupCaps.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2009-06-19 01:38:50 UTC
  • mfrom: (16.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090619013850-dsn4lrxvs90ab4rx
Tags: 1:1.15.0-1
* New upstream release. 
* Upstream added support for OASIS documents.
Closes: #530328
* Refreshed quilt patches
* Bumped standards versions to 3.8.2
* Bumped compat to 7
* Pointed to GPL-2 in debian/copyright
* Added php5-sqlite to possible DB backend dependencies.
Closes: #501569
* Proofread README.Debian, upgrade is documented there.
Closes: #520121

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 * @ingroup maintenance
30
30
 */
31
31
 
32
 
$options = array( 'dry-run' );
 
32
$optionsWithArgs = array( 'namespace' );
33
33
 
34
34
require_once( 'commandLine.inc' );
35
 
require_once( 'FiveUpgrade.inc' );
 
35
require_once( 'cleanupTable.inc' );
36
36
 
37
37
/**
38
38
 * @ingroup Maintenance
39
39
 */
40
 
class CapsCleanup extends FiveUpgrade {
41
 
        function CapsCleanup( $dryrun = false, $namespace=0 ) {
42
 
                parent::FiveUpgrade();
43
 
 
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 );
47
44
        }
48
45
 
53
50
                        return false;
54
51
                }
55
52
 
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' ) );
58
56
        }
59
57
 
60
 
        function init( $count, $table ) {
61
 
                $this->processed = 0;
62
 
                $this->updated = 0;
63
 
                $this->count = $count;
64
 
                $this->startTime = wfTime();
65
 
                $this->table = $table;
66
 
        }
67
 
 
68
 
        function progress( $updated ) {
69
 
                $this->updated += $updated;
70
 
                $this->processed++;
71
 
                if( $this->processed % 100 != 0 ) {
72
 
                        return;
73
 
                }
74
 
                $portion = $this->processed / $this->count;
75
 
                $updateRate = $this->updated / $this->processed;
76
 
 
77
 
                $now = wfTime();
78
 
                $delta = $now - $this->startTime;
79
 
                $estimatedTotalTime = $delta / $portion;
80
 
                $eta = $this->startTime + $estimatedTotalTime;
81
 
 
82
 
                printf( "%s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
83
 
                        wfTimestamp( TS_DB, intval( $now ) ),
84
 
                        $portion * 100.0,
85
 
                        $this->table,
86
 
                        wfTimestamp( TS_DB, intval( $eta ) ),
87
 
                        $this->processed,
88
 
                        $this->count,
89
 
                        $this->processed / $delta,
90
 
                        $updateRate * 100.0 );
91
 
                flush();
92
 
        }
93
 
 
94
 
        function runTable( $table, $where, $callback ) {
95
 
                $fname = 'CapsCleanup::buildTable';
96
 
 
97
 
                $count = $this->dbw->selectField( $table, 'count(*)', '', $fname );
98
 
                $this->init( $count, 'page' );
99
 
                $this->log( "Processing $table..." );
100
 
 
101
 
                $tableName = $this->dbr->tableName( $table );
102
 
                $sql = "SELECT * FROM $tableName $where";
103
 
                $result = $this->dbr->query( $sql, $fname );
104
 
 
105
 
                while( $row = $this->dbr->fetchObject( $result ) ) {
106
 
                        call_user_func( $callback, $row );
107
 
                }
108
 
                $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
109
 
                $this->dbr->freeResult( $result );
110
 
        }
111
 
 
112
58
        function processPage( $row ) {
113
59
                global $wgContLang;
114
60