45 public function run() {
49 $table = $this->params[
'table'];
50 $column = $this->params[
'column'];
54 if ( in_array(
"$table.$column", self::$actorMigratedColumns,
true ) ) {
57 "Ignoring job {$this->toString()}, column $table.$column "
58 .
"actor migration stage lacks WRITE_OLD\n"
66 if ( !$dbw->tableExists( $table, __METHOD__ ) ) {
68 "Ignoring job {$this->toString()}, table $table does not exist\n"
71 } elseif ( !$dbw->fieldExists( $table, $column, __METHOD__ ) ) {
73 "Ignoring job {$this->toString()}, column $table.$column does not exist\n"
78 $oldname = $this->params[
'oldname'];
79 $newname = $this->params[
'newname'];
80 $count = $this->params[
'count'];
81 if ( isset( $this->params[
'userID'] ) ) {
82 $userID = $this->params[
'userID'];
83 $uidColumn = $this->params[
'uidColumn'];
88 if ( isset( $this->params[
'timestampColumn'] ) ) {
89 $timestampColumn = $this->params[
'timestampColumn'];
90 $minTimestamp = $this->params[
'minTimestamp'];
91 $maxTimestamp = $this->params[
'maxTimestamp'];
93 $timestampColumn =
null;
97 $uniqueKey = $this->params[
'uniqueKey'] ??
null;
98 $keyId = $this->params[
'keyId'] ??
null;
99 $logId = $this->params[
'logId'] ??
null;
102 # Block until the transaction that inserted this job commits.
103 # The atomic section is for sanity as FOR UPDATE does not lock in auto-commit mode
105 $dbw->startAtomic( __METHOD__ );
106 $committed = $dbw->selectField(
'logging',
108 [
'log_id' => $logId ],
112 $dbw->endAtomic( __METHOD__ );
113 # If the transaction inserting this job was rolled back, detect that
114 if ( $committed ===
false ) {
115 throw new LogicException(
'Cannot run job if the account rename failed.' );
119 # Flush any state snapshot data (and release the lock above)
120 $dbw->commit( __METHOD__,
'flush' );
122 # Conditions like "*_user_text = 'x'
123 $conds = [ $column => $oldname ];
124 # If user ID given, add that to condition to avoid rename collisions
125 if ( $userID !== null ) {
126 $conds[$uidColumn] = $userID;
128 # Bound by timestamp if given
129 if ( $timestampColumn !== null ) {
130 $conds[] = "$timestampColumn >= " . $dbw->addQuotes( $minTimestamp );
131 $conds[] = "$timestampColumn <= " . $dbw->addQuotes( $maxTimestamp );
132 # Bound by unique key if given (B/C)
133 } elseif ( $uniqueKey !== null && $keyId !== null ) {
134 $conds[$uniqueKey] = $keyId;
136 throw new InvalidArgumentException( 'Expected ID batch or time range' );
140 # Actually update the rows for this job...
141 if ( $uniqueKey !== null ) {
142 # Select the rows to update by PRIMARY KEY
143 $ids = $dbw->selectFieldValues( $table, $uniqueKey, $conds, __METHOD__ );
144 # Update these rows by PRIMARY KEY to avoid slave lag
145 foreach ( array_chunk( $ids, $wgUpdateRowsPerQuery ) as $batch ) {
146 $dbw->commit( __METHOD__, 'flush' );
149 $dbw->update( $table,
150 [ $column => $newname ],
151 [ $column => $oldname, $uniqueKey => $batch ],
154 $affectedCount += $dbw->affectedRows();
157 # Update the chunk of rows directly
158 $dbw->update( $table,
159 [ $column => $newname ],
163 $affectedCount += $dbw->affectedRows();
166 # Special case: revisions may be deleted while renaming...
167 if ( $affectedCount < $count && $table === 'revision' && $timestampColumn !== null ) {
168 # If some revisions were not renamed, they may have been deleted.
169 # Do a pass on the archive table to get these straglers...
170 $ids = $dbw->selectFieldValues(
174 'ar_user_text' => $oldname,
175 'ar_user' => $userID,
176 // No user,rev_id index, so use timestamp to bound
177 // the rows. This can use the user,timestamp index.
178 "ar_timestamp >= '$minTimestamp'",
179 "ar_timestamp <= '$maxTimestamp'"
183 foreach ( array_chunk( $ids, $wgUpdateRowsPerQuery ) as $batch ) {
184 $dbw->commit( __METHOD__, 'flush' );
189 [ 'ar_user_text' => $newname ],
190 [ 'ar_user_text' => $oldname, 'ar_id' => $batch ],
195 # Special case: revisions may be restored while renaming...
196 if ( $affectedCount < $count && $table === 'archive' && $timestampColumn !== null ) {
197 # If some revisions were not renamed, they may have been restored.
198 # Do a pass on the revision table to get these straglers...
199 $ids = $dbw->selectFieldValues(
203 'rev_user_text' => $oldname,
204 'rev_user' => $userID,
205 // No user,rev_id index, so use timestamp to bound
206 // the rows. This can use the user,timestamp index.
207 "rev_timestamp >= '$minTimestamp'",
208 "rev_timestamp <= '$maxTimestamp'"
212 foreach ( array_chunk( $ids, $wgUpdateRowsPerQuery ) as $batch ) {
213 $dbw->commit( __METHOD__, 'flush' );
218 [ 'rev_user_text' => $newname ],
219 [ 'rev_user_text' => $oldname, 'rev_id' => $batch ],