27require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
38 $this->
addDescription(
'Reset the page_random for articles within given date range' );
40 'From date range selector to select articles to update, ex: 20041011000000',
true,
true );
42 'To date range selector to select articles to update, ex: 20050708000000',
true,
true );
43 $this->
addOption(
'dry',
'Do not update column' );
45 'Optional: Use when you need to restart the reset process from a given page ID offset'
46 .
' in case a previous reset failed or was stopped'
59 if ( $from ===
null || $to ===
null ) {
60 $this->
output(
"--from and --to have to be provided" . PHP_EOL );
64 $this->
output(
"--from has to be smaller than --to" . PHP_EOL );
67 $batchStart = (int)$this->
getOption(
'batch-start', 0 );
71 $message =
"Resetting page_random column within date range from $from to $to";
72 if ( $batchStart > 0 ) {
73 $message .=
" starting from page ID $batchStart";
75 $message .= $dry ?
". dry run" :
'.';
77 $this->
output( $message . PHP_EOL );
79 $this->
output(
" ...doing chunk of $batchSize from $batchStart " . PHP_EOL );
86 $queryBuilder = $dbr->newSelectQueryBuilder()
89 ->where( $dbr->expr(
'page_id',
'>', $batchStart ) )
91 ->orderBy(
'page_id' );
92 $subquery = $queryBuilder->newSubquery()
93 ->select(
'MIN(rev_timestamp)' )
95 ->where(
'rev_page=page_id' );
96 $queryBuilder->andWhere(
97 '(' . $subquery->getSQL() .
') BETWEEN ' .
98 $dbr->addQuotes( $dbr->timestamp( $from ) ) .
' AND ' . $dbr->addQuotes( $dbr->timestamp( $to ) )
101 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
103 foreach ( $res as $row ) {
106 $dbw->newUpdateQueryBuilder()
108 ->set( [
'page_random' =>
wfRandom() ] )
109 ->where( [
'page_id' => $row->page_id ] )
110 ->caller( __METHOD__ )
112 $changed += $dbw->affectedRows();
118 $batchStart = $row->page_id;
127 }
while ( $res->numRows() === $batchSize );
128 $this->
output(
"page_random reset complete ... changed $changed rows" . PHP_EOL );
136require_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...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
waitForReplication()
Wait for replica DB servers to catch up.
getOption( $name, $default=null)
Get an option, or return the default.
addDescription( $text)
Set the description text.
Maintenance script that resets page_random over a time range.
execute()
Do the actual work.
__construct()
Default constructor.