26 require_once __DIR__ .
'/Maintenance.php';
38 'callback' =>
'processRow',
47 parent::__construct();
48 $this->
addOption(
'dry-run',
'Perform a dry run' );
49 $this->
addOption(
'reporting-interval',
'How often to print status line' );
54 $this->reportInterval = $this->
getOption(
'reporting-interval', $this->reportInterval );
56 $this->dryrun = $this->
hasOption(
'dry-run' );
58 if ( $this->dryrun ) {
59 $this->
output(
"Checking for bad titles...\n" );
61 $this->
output(
"Checking and fixing bad titles...\n" );
64 $this->
runTable( $this->defaultParams );
71 $this->startTime = microtime(
true );
81 if ( $this->processed % $this->reportInterval != 0 ) {
87 $now = microtime(
true );
89 $estimatedTotalTime = $delta / $portion;
90 $eta = $this->startTime + $estimatedTotalTime;
93 sprintf(
"%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
94 WikiMap::getCurrentWikiDbDomain()->getId(),
101 $this->processed / $delta,
114 if ( array_diff( array_keys( $params ),
115 [
'table',
'conds',
'index',
'callback' ] )
117 $this->
fatalError( __METHOD__ .
': Missing parameter ' . implode(
', ', $params ) );
120 $table = $params[
'table'];
124 $this->
output(
"Processing $table...\n" );
126 $index = (array)$params[
'index'];
129 'ORDER BY' => implode(
',', $index ),
132 $callback = [ $this, $params[
'callback'] ];
135 $conds = array_merge( $params[
'conds'], $indexConds );
137 if ( !
$res->numRows() ) {
142 foreach (
$res as $row ) {
143 call_user_func( $callback, $row );
146 if (
$res->numRows() < $this->getBatchSize() ) {
153 foreach ( $index as $field ) {
155 $conds[ $field ] = $row->$field;
157 $indexConds = [
$dbr->buildComparison(
'>', $conds ) ];
160 $this->
output(
"Finished $table... $this->updated of $this->processed rows updated\n" );
168 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...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getBatchSize()
Returns batch size.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Generic class to cleanup a database table.
execute()
Do the actual work.
__construct()
Default constructor.