MediaWiki master
RenameUserDerivedJob.php
Go to the documentation of this file.
1<?php
2
4
10
31 private $renameUserFactory;
33 private $userFactory;
34
35 public function __construct(
37 $params,
38 RenameUserFactory $renameUserFactory,
39 UserFactory $userFactory
40 ) {
41 parent::__construct( 'renameUserDerived', $title, $params );
42
43 $this->renameUserFactory = $renameUserFactory;
44 $this->userFactory = $userFactory;
45 }
46
47 public function run() {
48 $oldName = $this->params['oldname'];
49 $newName = $this->params['newname'];
50 $uid = $this->params['uid'];
51 $performerUid = $this->params['performer'];
52 $reason = $this->params['reason'];
53 $movePages = $this->params['movePages'] ?? true;
54 $suppressRedirect = $this->params['suppressRedirect'] ?? false;
55
56 $user = $this->userFactory->newFromId( $uid );
57 $performer = $this->userFactory->newFromId( $performerUid );
58 $logger = LoggerFactory::getInstance( 'RenameUser' );
59
60 // Check if this wiki has the same shared user database as the trigger wiki.
61 if ( !$this->userFactory->isUserTableShared() ) {
62 return true;
63 }
64 if ( $user->getName() !== $newName ) {
65 $logger->info(
66 "User to be renamed from $oldName to $newName does not have the expected name, skipping"
67 );
68 return true;
69 }
70
71 // Do the rename
72 $rename = $this->renameUserFactory->newDerivedRenameUser(
73 $performer,
74 $uid,
75 $oldName,
76 $newName,
77 $reason,
78 [
79 'movePages' => $movePages,
80 'suppressRedirect' => $suppressRedirect
81 ]
82 );
83 $status = $rename->renameLocal();
84 if ( !$status->isGood() ) {
85 $logger->error(
86 "Cannot finish derived local user rename from $oldName to $newName: $status"
87 );
88 }
89
90 return $status->isOK();
91 }
92}
Describe and execute a background job.
Definition Job.php:41
array $params
Array of job parameters.
Definition Job.php:46
Create PSR-3 logger objects.
Custom job to perform user rename on wiki family using shared tables or virtual domains.
__construct(Title $title, $params, RenameUserFactory $renameUserFactory, UserFactory $userFactory)
Represents a title within MediaWiki.
Definition Title.php:78
Create User objects.