]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/fixUserRegistration.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.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  * @file
7  * @ingroup Maintenance
8  */
9
10 require_once( 'commandLine.inc' );
11
12 $fname = 'fixUserRegistration.php';
13
14 $dbr = wfGetDB( DB_SLAVE );
15 $dbw = wfGetDB( DB_MASTER );
16
17 // Get user IDs which need fixing
18 $res = $dbr->select( 'user', 'user_id', 'user_registration IS NULL', $fname );
19
20 while ( $row = $dbr->fetchObject( $res ) ) {
21         $id = $row->user_id;
22         // Get first edit time
23         $timestamp = $dbr->selectField( 'revision', 'MIN(rev_timestamp)', array( 'rev_user' => $id ), $fname );
24         // Update
25         if ( !empty( $timestamp ) ) {
26                 $dbw->update( 'user', array( 'user_registration' => $timestamp ), array( 'user_id' => $id ), $fname );
27                 print "$id $timestamp\n";
28         } else {
29                 print "$id NULL\n";
30         }
31 }
32 print "\n";
33
34