Script to update user_registration to an approximation, for old rows.
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 5 Jun 2006 05:21:12 +0000 (05:21 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 5 Jun 2006 05:21:12 +0000 (05:21 +0000)
maintenance/fixUserRegistration.php [new file with mode: 0644]

diff --git a/maintenance/fixUserRegistration.php b/maintenance/fixUserRegistration.php
new file mode 100644 (file)
index 0000000..af8a68c
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Fix the user_registration field.
+ * In particular, for values which are NULL, set them to the date of the first edit
+ */
+
+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";
+
+?>