106 $this->checkIfUserExists =
true;
109 $this->checkIfUserExists =
$options[
'checkIfUserExists'];
113 $this->debugPrefix =
$options[
'debugPrefix'];
121 $this->tablesJob = [];
123 if ( self::actorMigrationWriteOld() ) {
127 $this->tablesJob[
'revision'] = [
128 self::NAME_COL =>
'rev_user_text',
129 self::UID_COL =>
'rev_user',
130 self::TIME_COL =>
'rev_timestamp',
131 'uniqueKey' =>
'rev_id'
133 $this->tablesJob[
'archive'] = [
134 self::NAME_COL =>
'ar_user_text',
135 self::UID_COL =>
'ar_user',
136 self::TIME_COL =>
'ar_timestamp',
137 'uniqueKey' =>
'ar_id'
139 $this->tablesJob[
'logging'] = [
140 self::NAME_COL =>
'log_user_text',
141 self::UID_COL =>
'log_user',
142 self::TIME_COL =>
'log_timestamp',
143 'uniqueKey' =>
'log_id'
145 $this->tablesJob[
'image'] = [
146 self::NAME_COL =>
'img_user_text',
147 self::UID_COL =>
'img_user',
148 self::TIME_COL =>
'img_timestamp',
149 'uniqueKey' =>
'img_name'
151 $this->tablesJob[
'oldimage'] = [
152 self::NAME_COL =>
'oi_user_text',
153 self::UID_COL =>
'oi_user',
154 self::TIME_COL =>
'oi_timestamp'
156 $this->tablesJob[
'filearchive'] = [
157 self::NAME_COL =>
'fa_user_text',
158 self::UID_COL =>
'fa_user',
159 self::TIME_COL =>
'fa_timestamp',
160 'uniqueKey' =>
'fa_id'
163 $this->
tables[
'revision'] = [
'rev_user_text',
'rev_user' ];
164 $this->
tables[
'archive'] = [
'ar_user_text',
'ar_user' ];
165 $this->
tables[
'logging'] = [
'log_user_text',
'log_user' ];
166 $this->
tables[
'image'] = [
'img_user_text',
'img_user' ];
167 $this->
tables[
'oldimage'] = [
'oi_user_text',
'oi_user' ];
168 $this->
tables[
'filearchive'] = [
'fa_user_text',
'fa_user' ];
173 $this->tablesJob[
'recentchanges'] = [
'rc_user_text',
'rc_user',
'rc_timestamp' ];
175 $this->
tables[
'recentchanges'] = [
'rc_user_text',
'rc_user' ];
179 Hooks::run(
'RenameUserSQL', [ $this ] );
183 if ( $this->debugPrefix ) {
184 $msg =
"{$this->debugPrefix}: $msg";
200 $atomicId = $dbw->startAtomic( __METHOD__, $dbw::ATOMIC_CANCELABLE );
202 Hooks::run(
'RenameUserPreRename', [ $this->uid, $this->old, $this->
new ] );
205 if ( $this->checkIfUserExists && !self::lockUserAndGetId( $this->old ) ) {
206 $this->
debug(
"User {$this->old} does not exist, bailing out" );
207 $dbw->cancelAtomic( __METHOD__, $atomicId );
214 $this->
debug(
"Starting rename of {$this->old} to {$this->new}" );
215 $dbw->update(
'user',
216 [
'user_name' => $this->
new,
'user_touched' => $dbw->timestamp() ],
217 [
'user_name' => $this->old,
'user_id' => $this->uid ],
220 if ( self::actorMigrationWriteNew() ) {
221 $dbw->update(
'actor',
222 [
'actor_name' => $this->
new ],
223 [
'actor_name' => $this->old,
'actor_user' => $this->uid ],
232 $user->load( User::READ_LATEST );
233 SessionManager::singleton()->invalidateSessionsForUser( $user );
236 $user->invalidateCache();
239 $dbw->update(
'ipblocks',
240 [
'ipb_address' => $this->
new ],
241 [
'ipb_user' => $this->uid,
'ipb_address' => $this->old ],
247 $oldTitle = Title::makeTitle( NS_USER, $this->old );
248 $newTitle = Title::makeTitle( NS_USER, $this->
new );
249 $this->
debug(
"Updating logging table for {$this->old} to {$this->new}" );
253 $dbw->update(
'logging',
254 [
'log_title' => $newTitle->getDBkey() ],
255 [
'log_type' => $logTypesOnUser,
256 'log_namespace' => NS_USER,
262 foreach ( $this->
tables as $table => $fieldSet ) {
264 $dbw->update( $table,
265 [ $nameCol => $this->
new ],
266 [ $nameCol => $this->old, $userCol => $this->uid ],
280 foreach ( $this->tablesJob as $table =>
$params ) {
285 $res = $dbw->select( $table,
287 [ $userTextC => $this->old, $userIDC => $this->uid ],
289 [
'ORDER BY' =>
"$timestampC ASC" ]
293 $jobParams[
'table'] = $table;
301 $jobParams[
'minTimestamp'] =
'0';
302 $jobParams[
'maxTimestamp'] =
'0';
303 $jobParams[
'count'] = 0;
306 $jobParams[
'uniqueKey'] =
$params[
'uniqueKey'];
311 $row = $dbw->fetchObject(
$res );
313 # If there are any job rows left, add it to the queue as one job
314 if ( $jobParams[
'count'] > 0 ) {
319 # Since the ORDER BY is ASC, set the min timestamp with first row
320 if ( $jobParams[
'count'] === 0 ) {
321 $jobParams[
'minTimestamp'] = $row->$timestampC;
323 # Keep updating the last timestamp, so it should be correct
324 # when the last item is added.
325 $jobParams[
'maxTimestamp'] = $row->$timestampC;
327 $jobParams[
'count']++;
328 # Once a job has $wgUpdateRowsPerJob rows, add it to the queue
331 $jobParams[
'minTimestamp'] =
'0';
332 $jobParams[
'maxTimestamp'] =
'0';
333 $jobParams[
'count'] = 0;
340 $logEntry->setPerformer( $this->renamer );
342 $logEntry->setComment( $this->reason );
343 $logEntry->setParameters( [
344 '4::olduser' => $this->old,
345 '5::newuser' => $this->
new,
346 '6::edits' => $contribs
348 $logid = $logEntry->insert();
350 foreach ( $jobs as
$job ) {
357 $count = count( $jobs );
359 JobQueueGroup::singleton()->push( $jobs );
360 $this->
debug(
"Queued $count jobs for {$this->old} to {$this->new}" );
364 $dbw->endAtomic( __METHOD__ );
368 $dbw->onTransactionIdle(
function () use ( $that, $dbw, $logEntry, $logid,
$fname ) {
369 $dbw->startAtomic(
$fname );
372 $user->load( User::READ_LATEST );
374 $user->saveSettings();
375 Hooks::run(
'RenameUserComplete', [ $that->uid, $that->old, $that->new ] );
377 $logEntry->publish( $logid );
378 $dbw->endAtomic(
$fname );
381 $this->
debug(
"Finished rename for {$this->old} to {$this->new}" );
394 [
'user_name' => $name ],
414 if ( defined(
'ActorMigration::MIGRATION_STAGE_SCHEMA_COMPAT' ) ) {
436 if ( defined(
'ActorMigration::MIGRATION_STAGE_SCHEMA_COMPAT' ) ) {
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
$wgUpdateRowsPerJob
Number of rows to update per job.
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
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.
wfQueriesMustScale()
Should low-performance queries be disabled?
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
static factory( $command, $params=[])
Create the appropriate object to handle a specific job.
Class for creating new log entries and inserting them into the database.
Class which performs the actual renaming of users.
array $tablesJob
tables => fields to be updated in a deferred job
array $tables
The tables => fields to be updated.
string $old
The old username.
static actorMigrationWriteOld()
Indicate whether we should still write old user fields.
User $renamer
User object of the user performing the rename, for logging purposes.
static lockUserAndGetId( $name)
string $reason
Reason to be used in the log entry.
static actorMigrationWriteNew()
Indicate whether we should write new actor fields.
string $debugPrefix
A prefix to use in all debug log messages.
rename()
Do the rename operation.
const CONTRIB_JOB
Users with more than this number of edits will have their rename operation deferred via the job queue...
bool $checkIfUserExists
Flag that can be set to false, in case another process has already started the updates and the old us...
string $new
The new username.
__construct( $old, $new, $uid, User $renamer, $options=[])
Constructor.
static getLogTypesOnUser()
List log type for which the target is a user Thus if the given target is in NS_MAIN we can alter it t...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromId( $id)
Static factory method for creation from a given user ID.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
const SCHEMA_COMPAT_WRITE_OLD
const SCHEMA_COMPAT_WRITE_NEW
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))
In both all secondary updates will be triggered handle like object that caches derived data representing a and can trigger updates of cached copies of that e g in the links tables
if(count( $args)< 1) $job