186 $dbw->startAtomic( __METHOD__ );
188 Hooks::run(
'RenameUserPreRename', [ $this->uid, $this->old, $this->
new ] );
191 if ( $this->checkIfUserExists && !self::lockUserAndGetId( $this->old ) ) {
192 $this->
debug(
"User {$this->old} does not exist, bailing out" );
199 $this->
debug(
"Starting rename of {$this->old} to {$this->new}" );
200 $dbw->update(
'user',
201 [
'user_name' => $this->
new,
'user_touched' => $dbw->timestamp() ],
202 [
'user_name' => $this->old,
'user_id' => $this->uid ],
206 $dbw->update(
'actor',
207 [
'actor_name' => $this->
new ],
208 [
'actor_name' => $this->old,
'actor_user' => $this->uid ],
217 if ( class_exists( SessionManager::class ) &&
218 is_callable( [ SessionManager::singleton(),
'invalidateSessionsForUser' ] )
220 $user->load( User::READ_LATEST );
221 SessionManager::singleton()->invalidateSessionsForUser( $user );
223 $authUser =
$wgAuth->getUserInstance( $user );
224 $authUser->resetAuthToken();
228 $user->invalidateCache();
231 $dbw->update(
'ipblocks',
232 [
'ipb_address' => $this->
new ],
233 [
'ipb_user' => $this->uid,
'ipb_address' => $this->old ],
239 $oldTitle = Title::makeTitle( NS_USER, $this->old );
240 $newTitle = Title::makeTitle( NS_USER, $this->
new );
241 $this->
debug(
"Updating logging table for {$this->old} to {$this->new}" );
245 $dbw->update(
'logging',
246 [
'log_title' => $newTitle->getDBkey() ],
247 [
'log_type' => $logTypesOnUser,
248 'log_namespace' => NS_USER,
254 foreach ( $this->tables as $table => $fieldSet ) {
255 list( $nameCol, $userCol ) = $fieldSet;
256 $dbw->update( $table,
257 [ $nameCol => $this->
new ],
258 [ $nameCol => $this->old, $userCol => $this->uid ],
272 foreach ( $this->tablesJob as $table =>
$params ) {
277 $res = $dbw->select( $table,
279 [ $userTextC => $this->old, $userIDC => $this->uid ],
281 [
'ORDER BY' =>
"$timestampC ASC" ]
285 $jobParams[
'table'] = $table;
286 $jobParams[
'column'] = $userTextC;
287 $jobParams[
'uidColumn'] = $userIDC;
288 $jobParams[
'timestampColumn'] = $timestampC;
293 $jobParams[
'minTimestamp'] =
'0';
294 $jobParams[
'maxTimestamp'] =
'0';
295 $jobParams[
'count'] = 0;
297 if ( isset(
$params[
'uniqueKey'] ) ) {
298 $jobParams[
'uniqueKey'] =
$params[
'uniqueKey'];
303 $row = $dbw->fetchObject(
$res );
305 # If there are any job rows left, add it to the queue as one job
306 if ( $jobParams[
'count'] > 0 ) {
311 # Since the ORDER BY is ASC, set the min timestamp with first row
312 if ( $jobParams[
'count'] === 0 ) {
313 $jobParams[
'minTimestamp'] = $row->$timestampC;
315 # Keep updating the last timestamp, so it should be correct
316 # when the last item is added.
317 $jobParams[
'maxTimestamp'] = $row->$timestampC;
319 $jobParams[
'count']++;
320 # Once a job has $wgUpdateRowsPerJob rows, add it to the queue
323 $jobParams[
'minTimestamp'] =
'0';
324 $jobParams[
'maxTimestamp'] =
'0';
325 $jobParams[
'count'] = 0;
328 $dbw->freeResult(
$res );
333 $logEntry->setPerformer( $this->renamer );
335 $logEntry->setComment( $this->reason );
336 $logEntry->setParameters( [
337 '4::olduser' => $this->old,
338 '5::newuser' => $this->
new,
339 '6::edits' => $contribs
341 $logid = $logEntry->insert();
343 foreach ( $jobs as
$job ) {
344 $job->params[
'logId'] = $logid;
350 $count = count( $jobs );
353 $this->
debug(
"Queued $count jobs for {$this->old} to {$this->new}" );
357 $dbw->endAtomic( __METHOD__ );
360 $dbw->onTransactionIdle(
function () use ( $that, $dbw, $logEntry, $logid ) {
361 $dbw->startAtomic( __METHOD__ );
364 $user->load( User::READ_LATEST );
366 if ( class_exists( AuthManager::class ) ) {
367 AuthManager::callLegacyAuthPlugin(
'updateExternalDB', [ $user ] );
370 $wgAuth->updateExternalDB( $user );
374 $user->saveSettings();
375 Hooks::run(
'RenameUserComplete', [ $that->uid, $that->old, $that->new ] );
377 $logEntry->publish( $logid );
378 $dbw->endAtomic( __METHOD__ );
381 $this->
debug(
"Finished rename for {$this->old} to {$this->new}" );