af8a68c2b0013f36e35e2cec99f09a795f8bf63e
[lhc/web/wiklou.git] / maintenance / fixUserRegistration.php
1 <?php
2 /**
3 * Fix the user_registration field.
4 * In particular, for values which are NULL, set them to the date of the first edit
5 */
6
7 require_once( 'commandLine.inc' );
8
9 $fname = 'fixUserRegistration.php';
10
11 $dbr =& wfGetDB( DB_SLAVE );
12 $dbw =& wfGetDB( DB_MASTER );
13
14 // Get user IDs which need fixing
15 $res = $dbr->select( 'user', 'user_id', 'user_registration IS NULL', $fname );
16
17 while ( $row = $dbr->fetchObject( $res ) ) {
18 $id = $row->user_id;
19 // Get first edit time
20 $timestamp = $dbr->selectField( 'revision', 'MIN(rev_timestamp)', array( 'rev_user' => $id ), $fname );
21 // Update
22 if ( !empty( $timestamp ) ) {
23 $dbw->update( 'user', array( 'user_registration' => $timestamp ), array( 'user_id' => $id ), $fname );
24 print "$id $timestamp\n";
25 } else {
26 print "$id NULL\n";
27 }
28 }
29 print "\n";
30
31 ?>