31 'revision.rev_user_text',
32 'archive.ar_user_text',
33 'ipblocks.ipb_by_text',
34 'image.img_user_text',
35 'oldimage.oi_user_text',
36 'filearchive.fa_user_text',
37 'recentchanges.rc_user_text',
38 'logging.log_user_text',
42 parent::__construct(
'renameUser', $title,
$params );
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 ],
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$wgUpdateRowsPerQuery
Number of rows to update per query.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Class to both describe a background job and handle jobs.
array $params
Array of job parameters.
Custom job to perform updates on tables in busier environments.
__construct(Title $title, $params=[])
static array $actorMigratedColumns
Core tables+columns that are being migrated to the actor table.
static actorMigrationWriteOld()
Indicate whether we should still write old user fields.
Represents a title within MediaWiki.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))