MediaWiki 1.41.2
fixUserRegistration.php
Go to the documentation of this file.
1<?php
27
28require_once __DIR__ . '/Maintenance.php';
29
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Fix the user_registration field' );
39 $this->setBatchSize( 1000 );
40 }
41
42 public function execute() {
43 $dbw = $this->getDB( DB_PRIMARY );
44
45 $lastId = 0;
46 do {
47 // Get user IDs which need fixing
48 $res = $dbw->newSelectQueryBuilder()
49 ->select( 'user_id' )
50 ->from( 'user' )
51 ->where( [ 'user_id > ' . $dbw->addQuotes( $lastId ), 'user_registration' => null ] )
52 ->orderBy( 'user_id' )
53 ->limit( $this->getBatchSize() )
54 ->caller( __METHOD__ )->fetchResultSet();
55 foreach ( $res as $row ) {
56 $id = $row->user_id;
57 $lastId = $id;
58 // Get first edit time
59 $actorQuery = ActorMigration::newMigration()
60 ->getWhere( $dbw, 'rev_user', User::newFromId( $id ) );
61 $timestamp = $dbw->selectField(
62 [ 'revision' ] + $actorQuery['tables'],
63 'MIN(rev_timestamp)',
64 $actorQuery['conds'],
65 __METHOD__,
66 [],
67 $actorQuery['joins']
68 );
69 // Update
70 if ( $timestamp !== null ) {
71 $dbw->update(
72 'user',
73 [ 'user_registration' => $timestamp ],
74 [ 'user_id' => $id ],
75 __METHOD__
76 );
77 $user = User::newFromId( $id );
78 $user->invalidateCache();
79 $this->output( "Set registration for #$id to $timestamp\n" );
80 } else {
81 $this->output( "Could not find registration for #$id NULL\n" );
82 }
83 }
84 $this->output( "Waiting for replica DBs..." );
85 $this->waitForReplication();
86 $this->output( " done.\n" );
87 } while ( $res->numRows() >= $this->getBatchSize() );
88 }
89}
90
91$maintClass = FixUserRegistration::class;
92require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
Maintenance script that fixes the user_registration field.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DBs to catch up.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
internal since 1.36
Definition User.php:98
const DB_PRIMARY
Definition defines.php:28