24 require_once __DIR__ .
'/Maintenance.php';
33 parent::__construct();
34 $this->
addDescription(
'Reset the page_random for articles within given date range' );
36 'From date range selector to select articles to update, ex: 20041011000000',
false,
true );
38 'To date range selector to select articles to update, ex: 20050708000000',
false,
true );
39 $this->
addOption(
'dry',
'Do not update column' );
41 'Optional: Use when you need to restart the reset process from a given page ID offset'
42 .
' in case a previous reset failed or was stopped'
55 if ( $from ===
null || $to ===
null ) {
56 $this->
output(
"--from and --to have to be provided" . PHP_EOL );
60 $this->
output(
"--from has to be smaller than --to" . PHP_EOL );
63 $batchStart = (int)$this->
getOption(
'batch-start', 0 );
67 $message =
"Resetting page_random column within date range from $from to $to";
68 if ( $batchStart > 0 ) {
69 $message .=
" starting from page ID $batchStart";
71 $message .= $dry ?
". dry run" :
'.';
73 $this->
output( $message . PHP_EOL );
75 $this->
output(
" ...doing chunk of $batchSize from $batchStart " . PHP_EOL );
86 '(' . $dbr->selectSQLText(
92 'BETWEEN ' . $dbr->addQuotes( $dbr->timestamp( $from ) ) .
93 ' AND ' . $dbr->addQuotes( $dbr->timestamp( $to ) ),
94 'page_id > ' . $dbr->addQuotes( $batchStart )
97 [
'LIMIT' => $batchSize,
'ORDER BY' =>
'page_id' ]
101 foreach ( $res as $row ) {
104 $dbw->update(
'page',
106 [
'page_id' => $row->page_id ],
108 $changed += $dbw->affectedRows();
114 $batchStart = $row->page_id;
123 }
while ( $res->numRows() === $batchSize );
124 $this->
output(
"page_random reset complete ... changed $changed rows" . PHP_EOL );
131 require_once RUN_MAINTENANCE_IF_MAIN;
wfRandom()
Get a random decimal value in the domain of [0, 1), in a way not likely to give duplicate values for ...
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
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.
waitForReplication()
Wait for replica DBs to catch up.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
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.
Maintenance script that resets page_random over a time range.
execute()
Do the actual work.
__construct()
Default constructor.