28require_once __DIR__ .
'/Maintenance.php';
42 'callback' =>
'processRow',
57 parent::__construct();
58 $this->
addOption(
'dry-run',
'Perform a dry run' );
59 $this->
addOption(
'reporting-interval',
'How often to print status line' );
64 $this->reportInterval = $this->
getOption(
'reporting-interval', $this->reportInterval );
66 $this->dryrun = $this->
hasOption(
'dry-run' );
68 if ( $this->dryrun ) {
69 $this->
output(
"Checking for bad titles...\n" );
71 $this->
output(
"Checking and fixing bad titles...\n" );
74 $this->
runTable( $this->defaultParams );
81 $this->startTime = microtime(
true );
91 if ( $this->processed % $this->reportInterval != 0 ) {
97 $now = microtime(
true );
99 $estimatedTotalTime = $delta / $portion;
100 $eta = $this->startTime + $estimatedTotalTime;
103 sprintf(
"%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
104 WikiMap::getCurrentWikiDbDomain()->getId(),
111 $this->processed / $delta,
124 if ( array_diff( array_keys( $params ),
125 [
'table',
'conds',
'index',
'callback' ] )
127 $this->
fatalError( __METHOD__ .
': Missing parameter ' . implode(
', ', $params ) );
130 $table = $params[
'table'];
132 $count = $dbr->newSelectQueryBuilder()
134 ->caller( __METHOD__ )
135 ->estimateRowCount();
137 $this->
output(
"Processing $table...\n" );
139 $index = (array)$params[
'index'];
141 $callback = [ $this, $params[
'callback'] ];
144 $conds = array_merge( $params[
'conds'], $indexConds );
145 $res = $dbr->newSelectQueryBuilder()
149 ->orderBy( implode(
',', $index ) )
151 ->caller( __METHOD__ )->fetchResultSet();
152 if ( !$res->numRows() ) {
157 foreach ( $res as $row ) {
161 if ( $res->numRows() < $this->getBatchSize() ) {
168 foreach ( $index as $field ) {
170 $conds[ $field ] = $row->$field;
172 $indexConds = [ $dbr->buildComparison(
'>', $conds ) ];
175 $this->
output(
"Finished $table... $this->updated of $this->processed rows updated\n" );
183 return sprintf(
"\\x%02x", ord(
$matches[1] ) );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
Generic class to cleanup a database table.
execute()
Do the actual work.
__construct()
Default constructor.