updateRowsPerQuery = $config->get( MainConfigNames::UpdateRowsPerQuery ); $this->lbFactory = $lbFactory; } public function run() { $dbw = $this->lbFactory->getPrimaryDatabase(); $ticket = $this->lbFactory->getEmptyTransactionTicket( __METHOD__ ); $table = $this->params['table']; $column = $this->params['column']; $oldname = $this->params['oldname']; $newname = $this->params['newname']; if ( isset( $this->params['userID'] ) ) { $userID = $this->params['userID']; $uidColumn = $this->params['uidColumn']; } else { $userID = null; $uidColumn = null; } if ( isset( $this->params['timestampColumn'] ) ) { $timestampColumn = $this->params['timestampColumn']; $minTimestamp = $this->params['minTimestamp']; $maxTimestamp = $this->params['maxTimestamp']; } else { $timestampColumn = null; $minTimestamp = null; $maxTimestamp = null; } $uniqueKey = $this->params['uniqueKey'] ?? null; $keyId = $this->params['keyId'] ?? null; # Conditions like "*_user_text = 'x' $conds = [ $column => $oldname ]; # If user ID given, add that to condition to avoid rename collisions if ( $userID !== null ) { $conds[$uidColumn] = $userID; } # Bound by timestamp if given if ( $timestampColumn !== null ) { $conds[] = $dbw->expr( $timestampColumn, '>=', $minTimestamp ); $conds[] = $dbw->expr( $timestampColumn, '<=', $maxTimestamp ); # Bound by unique key if given (B/C) } elseif ( $uniqueKey !== null && $keyId !== null ) { $conds[$uniqueKey] = $keyId; } else { throw new InvalidArgumentException( 'Expected ID batch or time range' ); } # Actually update the rows for this job... if ( $uniqueKey !== null ) { // Select the rows to update by PRIMARY KEY $ids = $dbw->newSelectQueryBuilder() ->select( $uniqueKey ) ->from( $table ) ->where( $conds ) ->caller( __METHOD__ )->fetchFieldValues(); # Update these rows by PRIMARY KEY to avoid replica lag foreach ( array_chunk( $ids, $this->updateRowsPerQuery ) as $batch ) { $this->lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); $dbw->newUpdateQueryBuilder() ->update( $table ) ->set( [ $column => $newname ] ) ->where( [ $column => $oldname, $uniqueKey => $batch ] ) ->caller( __METHOD__ )->execute(); } } else { # Update the chunk of rows directly $dbw->newUpdateQueryBuilder() ->update( $table ) ->set( [ $column => $newname ] ) ->where( $conds ) ->caller( __METHOD__ )->execute(); } return true; } } /** @deprecated class alias since 1.43 */ class_alias( RenameUserJob::class, 'RenameUserJob' );