5use InvalidArgumentException;
38 private $updateRowsPerQuery;
52 $this->lbFactory = $lbFactory;
56 public function run() {
57 $dbw = $this->lbFactory->getPrimaryDatabase();
58 $ticket = $this->lbFactory->getEmptyTransactionTicket( __METHOD__ );
59 $table = $this->params[
'table'];
60 $column = $this->params[
'column'];
62 $oldname = $this->params[
'oldname'];
63 $newname = $this->params[
'newname'];
64 if ( isset( $this->params[
'userID'] ) ) {
65 $userID = $this->params[
'userID'];
66 $uidColumn = $this->params[
'uidColumn'];
71 if ( isset( $this->params[
'timestampColumn'] ) ) {
72 $timestampColumn = $this->params[
'timestampColumn'];
73 $minTimestamp = $this->params[
'minTimestamp'];
74 $maxTimestamp = $this->params[
'maxTimestamp'];
76 $timestampColumn =
null;
80 $uniqueKey = $this->params[
'uniqueKey'] ??
null;
81 $keyId = $this->params[
'keyId'] ??
null;
83 # Conditions like "*_user_text = 'x'
84 $conds = [ $column => $oldname ];
85 # If user ID given, add that to condition to avoid rename collisions
86 if ( $userID !== null ) {
87 $conds[$uidColumn] = $userID;
89 # Bound by timestamp if given
90 if ( $timestampColumn !== null ) {
91 $conds[] = $dbw->expr( $timestampColumn, '>=', $minTimestamp );
92 $conds[] = $dbw->expr( $timestampColumn, '<=', $maxTimestamp );
93 # Bound by unique key if given (B/C)
94 } elseif ( $uniqueKey !== null && $keyId !== null ) {
95 $conds[$uniqueKey] = $keyId;
97 throw new InvalidArgumentException( 'Expected ID batch or time range' );
100 # Actually update the rows for this job...
101 if ( $uniqueKey !== null ) {
102 // Select the rows to update by PRIMARY KEY
103 $ids = $dbw->newSelectQueryBuilder()
104 ->select( $uniqueKey )
107 ->caller( __METHOD__ )->fetchFieldValues();
108 # Update these rows by PRIMARY KEY to avoid replica lag
109 foreach ( array_chunk( $ids, $this->updateRowsPerQuery ) as $batch ) {
110 $this->lbFactory->commitAndWaitForReplication( __METHOD__, $ticket );
112 $dbw->newUpdateQueryBuilder()
114 ->set( [ $column => $newname ] )
115 ->where( [ $column => $oldname, $uniqueKey => $batch ] )
116 ->caller( __METHOD__ )->execute();
119 # Update the chunk of rows directly
120 $dbw->newUpdateQueryBuilder()
122 ->set( [ $column => $newname ] )
124 ->caller( __METHOD__ )->execute();
131class_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()