* (bug 6023) Fixed mismatch of 0/NULL for wl_notificationtimestamp; now notification
[lhc/web/wiklou.git] / maintenance / userDupes.inc
index ad8e9b6..f66051d 100644 (file)
@@ -14,7 +14,7 @@
 #
 # You should have received a copy of the GNU General Public License along
 # with this program; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 # http://www.gnu.org/copyleft/gpl.html
 
 /**
@@ -25,11 +25,11 @@ class UserDupes {
        var $reassigned;
        var $trimmed;
        var $failed;
-       
+
        function UserDupes( &$database ) {
                $this->db =& $database;
        }
-       
+
        /**
         * Check if this database's user table has already had a unique
         * user_name index applied.
@@ -42,13 +42,13 @@ class UserDupes {
                        echo "WARNING: doesn't seem to have user_name index at all!\n";
                        return false;
                }
-               
+
                # Confusingly, 'Non_unique' is 0 for *unique* indexes,
                # and 1 for *non-unique* indexes. Pass the crack, MySQL,
                # it's obviously some good stuff!
                return ( $info->Non_unique == 0 );
        }
-       
+
        /**
         * Checks the database for duplicate user account records
         * and remove them in preparation for application of a unique
@@ -63,7 +63,7 @@ class UserDupes {
        function clearDupes() {
                return $this->checkDupes( true );
        }
-       
+
        /**
         * Checks the database for duplicate user account records
         * in preparation for application of a unique index on the
@@ -80,18 +80,18 @@ class UserDupes {
         */
        function checkDupes( $doDelete = false ) {
                global $wgDBname;
-               
+
                if( $this->hasUniqueIndex() ) {
                        echo "$wgDBname already has a unique index on its user table.\n";
                        return true;
                }
-               
+
                $this->lock();
-               
+
                echo "Checking for duplicate accounts...\n";
                $dupes = $this->getDupes();
                $count = count( $dupes );
-               
+
                echo "Found $count accounts with duplicate records on $wgDBname.\n";
                $this->trimmed    = 0;
                $this->reassigned = 0;
@@ -99,11 +99,11 @@ class UserDupes {
                foreach( $dupes as $name ) {
                        $this->examine( $name, $doDelete );
                }
-               
+
                $this->unlock();
-               
+
                echo "\n";
-               
+
                if( $this->reassigned > 0 ) {
                        if( $doDelete ) {
                                echo "$this->reassigned duplicate accounts had edits reassigned to a canonical record id.\n";
@@ -111,7 +111,7 @@ class UserDupes {
                                echo "$this->reassigned duplicate accounts need to have edits reassigned.\n";
                        }
                }
-               
+
                if( $this->trimmed > 0 ) {
                        if( $doDelete ) {
                                echo "$this->trimmed duplicate user records were deleted from $wgDBname.\n";
@@ -119,12 +119,12 @@ class UserDupes {
                                echo "$this->trimmed duplicate user accounts were found on $wgDBname which can be removed safely.\n";
                        }
                }
-               
+
                if( $this->failed > 0 ) {
                        echo "Something terribly awry; $this->failed duplicate accounts were not removed.\n";
                        return false;
                }
-               
+
                if( $this->trimmed == 0 || $doDelete ) {
                        echo "It is now safe to apply the unique index on user_name.\n";
                        return true;
@@ -133,7 +133,7 @@ class UserDupes {
                        return false;
                }
        }
-       
+
        /**
         * We don't want anybody to mess with our stuff...
         * @access private
@@ -147,14 +147,14 @@ class UserDupes {
                }
                $names = array_map( array( $this, 'lockTable' ), $set );
                $tables = implode( ',', $names );
-               
+
                $result = $this->db->query( "LOCK TABLES $tables", $fname );
        }
-       
+
        function lockTable( $table ) {
                return $this->db->tableName( $table ) . ' WRITE';
        }
-       
+
        /**
         * @return bool
         * @access private
@@ -162,7 +162,7 @@ class UserDupes {
        function newSchema() {
                return class_exists( 'Revision' );
        }
-       
+
        /**
         * @access private
         */
@@ -170,7 +170,7 @@ class UserDupes {
                $fname = 'UserDupes::unlock';
                $result = $this->db->query( "UNLOCK TABLES", $fname );
        }
-       
+
        /**
         * Grab usernames for which multiple records are present in the database.
         * @return array
@@ -184,16 +184,16 @@ class UserDupes {
                            FROM $user
                        GROUP BY user_name
                          HAVING n > 1", $fname );
-               
+
                $list = array();
                while( $row = $this->db->fetchObject( $result ) ) {
                        $list[] = $row->user_name;
                }
                $this->db->freeResult( $result );
-               
+
                return $list;
        }
-       
+
        /**
         * Examine user records for the given name. Try to see which record
         * will be the one that actually gets used, then check remaining records
@@ -208,11 +208,11 @@ class UserDupes {
                        array( 'user_id' ),
                        array( 'user_name' => $name ),
                        $fname );
-               
+
                $firstRow = $this->db->fetchObject( $result );
                $firstId  = $firstRow->user_id;
                echo "Record that will be used for '$name' is user_id=$firstId\n";
-               
+
                while( $row = $this->db->fetchObject( $result ) ) {
                        $dupeId = $row->user_id;
                        echo "... dupe id $dupeId: ";
@@ -244,7 +244,7 @@ class UserDupes {
                }
                $this->db->freeResult( $result );
        }
-       
+
        /**
         * Count the number of edits attributed to this user.
         * Does not currently check log table or other things
@@ -261,7 +261,7 @@ class UserDupes {
                                $this->editCountOn( 'old', 'old_user', $userid );
                }
        }
-       
+
        /**
         * Count the number of hits on a given table for this account.
         * @param string $table
@@ -278,7 +278,7 @@ class UserDupes {
                        array( $field => $userid ),
                        $fname ) );
        }
-       
+
        /**
         * @param int $from
         * @param int $to
@@ -292,7 +292,7 @@ class UserDupes {
                        $this->reassignEditsOn( $table, $field, $from, $to );
                }
        }
-       
+
        /**
         * @param string $table
         * @param string $field
@@ -309,7 +309,7 @@ class UserDupes {
                        $fname );
                echo "ok. ";
        }
-       
+
        /**
         * Remove a user account line.
         * @param int $userid
@@ -321,7 +321,7 @@ class UserDupes {
                $this->db->delete( 'user', array( 'user_id' => $userid ), $fname );
                echo " ok";
        }
-       
+
 }