Some love to UserDupes
[lhc/web/wiklou.git] / maintenance / userDupes.inc
index 9893342..f759c13 100644 (file)
@@ -24,6 +24,8 @@
  * @ingroup Maintenance
  */
 
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
 /**
  * Look for duplicate user table entries and optionally prune them.
  *
  * @ingroup Maintenance
  */
 class UserDupes {
+       /**
+        * @var IMaintainableDatabase
+        */
        private $db;
        private $reassigned;
        private $trimmed;
        private $failed;
        private $outputCallback;
 
-       function __construct( &$database, $outputCallback ) {
+       /**
+        * UserDupes constructor.
+        * @param IMaintainableDatabase &$database
+        * @param callback $outputCallback
+        */
+       public function __construct( &$database, $outputCallback ) {
                $this->db = $database;
                $this->outputCallback = $outputCallback;
        }
@@ -57,7 +67,7 @@ class UserDupes {
         * user_name index applied.
         * @return bool
         */
-       function hasUniqueIndex() {
+       public function hasUniqueIndex() {
                $info = $this->db->indexInfo( 'user', 'user_name', __METHOD__ );
                if ( !$info ) {
                        $this->out( "WARNING: doesn't seem to have user_name index at all!\n" );
@@ -82,7 +92,7 @@ class UserDupes {
         *
         * @return bool
         */
-       function clearDupes() {
+       public function clearDupes() {
                return $this->checkDupes( true );
        }
 
@@ -100,7 +110,7 @@ class UserDupes {
         *   from the database; false to just check.
         * @return bool
         */
-       function checkDupes( $doDelete = false ) {
+       private function checkDupes( $doDelete = false ) {
                if ( $this->hasUniqueIndex() ) {
                        echo wfWikiID() . " already has a unique index on its user table.\n";
 
@@ -163,9 +173,8 @@ class UserDupes {
 
        /**
         * We don't want anybody to mess with our stuff...
-        * @access private
         */
-       function lock() {
+       private function lock() {
                $set = [ 'user', 'revision' ];
                $names = array_map( [ $this, 'lockTable' ], $set );
                $tables = implode( ',', $names );
@@ -173,29 +182,28 @@ class UserDupes {
                $this->db->query( "LOCK TABLES $tables", __METHOD__ );
        }
 
-       function lockTable( $table ) {
+       private function lockTable( $table ) {
                return $this->db->tableName( $table ) . ' WRITE';
        }
 
        /**
-        * @access private
+        * @private
         */
-       function unlock() {
+       private function unlock() {
                $this->db->query( "UNLOCK TABLES", __METHOD__ );
        }
 
        /**
         * Grab usernames for which multiple records are present in the database.
         * @return array
-        * @access private
         */
-       function getDupes() {
+       private function getDupes() {
                $user = $this->db->tableName( 'user' );
                $result = $this->db->query(
                        "SELECT user_name,COUNT(*) AS n
                                FROM $user
                        GROUP BY user_name
-                         HAVING n > 1", __METHOD__ );
+                               HAVING n > 1", __METHOD__ );
 
                $list = [];
                foreach ( $result as $row ) {
@@ -211,9 +219,8 @@ class UserDupes {
         * for edits. If the dupes have no edits, we can safely remove them.
         * @param string $name
         * @param bool $doDelete
-        * @access private
         */
-       function examine( $name, $doDelete ) {
+       private function examine( $name, $doDelete ) {
                $result = $this->db->select( 'user',
                        [ 'user_id' ],
                        [ 'user_name' => $name ],
@@ -260,9 +267,8 @@ class UserDupes {
         * where it might show up...
         * @param int $userid
         * @return int
-        * @access private
         */
-       function editCount( $userid ) {
+       private function editCount( $userid ) {
                return intval( $this->db->selectField(
                        'revision',
                        'COUNT(*)',
@@ -273,9 +279,8 @@ class UserDupes {
        /**
         * @param int $from
         * @param int $to
-        * @access private
         */
-       function reassignEdits( $from, $to ) {
+       private function reassignEdits( $from, $to ) {
                $this->out( 'reassigning... ' );
                $this->db->update( 'revision',
                        [ 'rev_user' => $to ],
@@ -287,9 +292,8 @@ class UserDupes {
        /**
         * Remove a user account line.
         * @param int $userid
-        * @access private
         */
-       function trimAccount( $userid ) {
+       private function trimAccount( $userid ) {
                $this->out( "deleting..." );
                $this->db->delete( 'user', [ 'user_id' => $userid ], __METHOD__ );
                $this->out( " ok" );