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 array $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
48 public function run() {
49 $oldName = $this->params['oldname'];
50 $newName = $this->params['newname'];
51 $uid = $this->params['uid'];
52 $performerUid = $this->params['performer'];
53 $reason = $this->params['reason'];
54 $movePages = $this->params['movePages'] ?? true;
55 $suppressRedirect = $this->params['suppressRedirect'] ?? false;
56
57 $user = $this->userFactory->newFromId( $uid );
58 $performer = $this->userFactory->newFromId( $performerUid );
59 $logger = LoggerFactory::getInstance( 'RenameUser' );
60
61 // Check if this wiki has the same shared user database as the trigger wiki.
62 if ( !$this->userFactory->isUserTableShared() ) {
63 return true;
64 }
65 if ( $user->getName() !== $newName ) {
66 $logger->info(
67 "User to be renamed from $oldName to $newName does not have the expected name, skipping"
68 );
69 return true;
70 }
71
72 // Do the rename
73 $rename = $this->renameUserFactory->newDerivedRenameUser(
74 $performer,
75 $uid,
76 $oldName,
77 $newName,
78 $reason,
79 [
80 'movePages' => $movePages,
81 'suppressRedirect' => $suppressRedirect
82 ]
83 );
84 $status = $rename->renameLocal();
85 if ( !$status->isGood() ) {
86 $logger->error(
87 "Cannot finish derived local user rename from $oldName to $newName: $status"
88 );
89 }
90
91 return $status->isOK();
92 }
93}
Describe and execute a background job.
Definition Job.php:28
array $params
Array of job parameters.
Definition Job.php:33
Create PSR-3 logger objects.
Custom job to perform user rename on wiki family using shared tables or virtual domains.
run()
Run the job.If this method returns false or completes exceptionally, the job runner will retry execut...
__construct(Title $title, array $params, RenameUserFactory $renameUserFactory, UserFactory $userFactory)
Represents a title within MediaWiki.
Definition Title.php:69
Create User objects.