MediaWiki  REL1_22
fixUserRegistration.php
Go to the documentation of this file.
00001 <?php
00025 require_once __DIR__ . '/Maintenance.php';
00026 
00032 class FixUserRegistration extends Maintenance {
00033     public function __construct() {
00034         parent::__construct();
00035         $this->mDescription = "Fix the user_registration field";
00036     }
00037 
00038     public function execute() {
00039         $dbr = wfGetDB( DB_SLAVE );
00040         $dbw = wfGetDB( DB_MASTER );
00041 
00042         // Get user IDs which need fixing
00043         $res = $dbr->select( 'user', 'user_id', 'user_registration IS NULL', __METHOD__ );
00044         foreach ( $res as $row ) {
00045             $id = $row->user_id;
00046             // Get first edit time
00047             $timestamp = $dbr->selectField( 'revision', 'MIN(rev_timestamp)', array( 'rev_user' => $id ), __METHOD__ );
00048             // Update
00049             if ( !empty( $timestamp ) ) {
00050                 $dbw->update( 'user', array( 'user_registration' => $timestamp ), array( 'user_id' => $id ), __METHOD__ );
00051                 $this->output( "$id $timestamp\n" );
00052             } else {
00053                 $this->output( "$id NULL\n" );
00054             }
00055         }
00056         $this->output( "\n" );
00057     }
00058 }
00059 
00060 $maintClass = "FixUserRegistration";
00061 require_once RUN_MAINTENANCE_IF_MAIN;