51 $batchSize = $this->getBatchSize();
52 $dbw = $this->getPrimaryDB();
53 $dbr = $this->getReplicaDB();
57 if ( $from ===
null || $to ===
null ) {
58 $this->output(
"--from and --to have to be provided" . PHP_EOL );
62 $this->output(
"--from has to be smaller than --to" . PHP_EOL );
65 $batchStart = (int)$this->getOption(
'batch-start', 0 );
67 $dry = (bool)$this->getOption(
'dry' );
69 $message =
"Resetting page_random column within date range from $from to $to";
70 if ( $batchStart > 0 ) {
71 $message .=
" starting from page ID $batchStart";
73 $message .= $dry ?
". dry run" :
'.';
75 $this->output( $message . PHP_EOL );
77 $this->output(
" ...doing chunk of $batchSize from $batchStart " . PHP_EOL );
84 $queryBuilder = $dbr->newSelectQueryBuilder()
87 ->where( $dbr->expr(
'page_id',
'>', $batchStart ) )
89 ->orderBy(
'page_id' );
90 $subquery = $queryBuilder->newSubquery()
91 ->select(
'MIN(rev_timestamp)' )
93 ->where(
'rev_page=page_id' );
94 $queryBuilder->andWhere(
95 '(' . $subquery->getSQL() .
') BETWEEN ' .
96 $dbr->addQuotes( $dbr->timestamp( $from ) ) .
' AND ' . $dbr->addQuotes( $dbr->timestamp( $to ) )
99 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
101 foreach ( $res as $row ) {
104 $dbw->newUpdateQueryBuilder()
106 ->set( [
'page_random' =>
wfRandom() ] )
107 ->where( [
'page_id' => $row->page_id ] )
108 ->caller( __METHOD__ )
110 $changed += $dbw->affectedRows();
116 $batchStart = $row->page_id;
124 $this->waitForReplication();
125 }
while ( $res->numRows() === $batchSize );
126 $this->output(
"page_random reset complete ... changed $changed rows" . PHP_EOL );