summaryrefslogtreecommitdiff
path: root/maintenance/fixUserRegistration.php
blob: eb5b7f7df317cafc083deabb8946220c6096a7e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
 * Fix the user_registration field.
 * In particular, for values which are NULL, set them to the date of the first edit
 *
 * @file
 * @ingroup Maintenance
 */

require_once( 'commandLine.inc' );

$fname = 'fixUserRegistration.php';

$dbr = wfGetDB( DB_SLAVE );
$dbw = wfGetDB( DB_MASTER );

// Get user IDs which need fixing
$res = $dbr->select( 'user', 'user_id', 'user_registration IS NULL', $fname );

while ( $row = $dbr->fetchObject( $res ) ) {
	$id = $row->user_id;
	// Get first edit time
	$timestamp = $dbr->selectField( 'revision', 'MIN(rev_timestamp)', array( 'rev_user' => $id ), $fname );
	// Update
	if ( !empty( $timestamp ) ) {
		$dbw->update( 'user', array( 'user_registration' => $timestamp ), array( 'user_id' => $id ), $fname );
		print "$id $timestamp\n";
	} else {
		print "$id NULL\n";
	}
}
print "\n";