5use InvalidArgumentException;
38 private $updateRowsPerQuery;
52 $this->lbFactory = $lbFactory;
55 public function run() {
56 $dbw = $this->lbFactory->getPrimaryDatabase();
57 $ticket = $this->lbFactory->getEmptyTransactionTicket( __METHOD__ );
58 $table = $this->params[
'table'];
59 $column = $this->params[
'column'];
61 $oldname = $this->params[
'oldname'];
62 $newname = $this->params[
'newname'];
63 if ( isset( $this->params[
'userID'] ) ) {
64 $userID = $this->params[
'userID'];
65 $uidColumn = $this->params[
'uidColumn'];
70 if ( isset( $this->params[
'timestampColumn'] ) ) {
71 $timestampColumn = $this->params[
'timestampColumn'];
72 $minTimestamp = $this->params[
'minTimestamp'];
73 $maxTimestamp = $this->params[
'maxTimestamp'];
75 $timestampColumn =
null;
79 $uniqueKey = $this->params[
'uniqueKey'] ??
null;
80 $keyId = $this->params[
'keyId'] ??
null;
82 # Conditions like "*_user_text = 'x'
83 $conds = [ $column => $oldname ];
84 # If user ID given, add that to condition to avoid rename collisions
85 if ( $userID !== null ) {
86 $conds[$uidColumn] = $userID;
88 # Bound by timestamp if given
89 if ( $timestampColumn !== null ) {
90 $conds[] = $dbw->expr( $timestampColumn, '>=', $minTimestamp );
91 $conds[] = $dbw->expr( $timestampColumn, '<=', $maxTimestamp );
92 # Bound by unique key if given (B/C)
93 } elseif ( $uniqueKey !== null && $keyId !== null ) {
94 $conds[$uniqueKey] = $keyId;
96 throw new InvalidArgumentException( 'Expected ID batch or time range' );
99 # Actually update the rows for this job...
100 if ( $uniqueKey !== null ) {
101 // Select the rows to update by PRIMARY KEY
102 $ids = $dbw->newSelectQueryBuilder()
103 ->select( $uniqueKey )
106 ->caller( __METHOD__ )->fetchFieldValues();
107 # Update these rows by PRIMARY KEY to avoid replica lag
108 foreach ( array_chunk( $ids, $this->updateRowsPerQuery ) as $batch ) {
109 $this->lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
111 $dbw->newUpdateQueryBuilder()
113 ->set( [ $column => $newname ] )
114 ->where( [ $column => $oldname, $uniqueKey => $batch ] )
115 ->caller( __METHOD__ )->execute();
118 # Update the chunk of rows directly
119 $dbw->newUpdateQueryBuilder()
121 ->set( [ $column => $newname ] )
123 ->caller( __METHOD__ )->execute();
130class_alias( RenameUserTableJob::class, 'RenameUserJob' );
A class containing constants representing the names of configuration variables.
const UpdateRowsPerQuery
Name constant for the UpdateRowsPerQuery setting, for use with Config::get()