From 7074ce2f2f1551bea4a882ad7dabb270ae0239ca Mon Sep 17 00:00:00 2001 From: Reedy Date: Tue, 18 Jun 2019 20:41:38 +0100 Subject: [PATCH] Some love to UserDupes Change-Id: I9c0310c928a518e6f0ed13998603544fe441358e --- maintenance/userDupes.inc | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/maintenance/userDupes.inc b/maintenance/userDupes.inc index 257c6beb4d..f759c13bac 100644 --- a/maintenance/userDupes.inc +++ b/maintenance/userDupes.inc @@ -24,6 +24,8 @@ * @ingroup Maintenance */ +use Wikimedia\Rdbms\IMaintainableDatabase; + /** * Look for duplicate user table entries and optionally prune them. * @@ -33,13 +35,21 @@ * @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... - * @private */ - function lock() { + private function lock() { $set = [ 'user', 'revision' ]; $names = array_map( [ $this, 'lockTable' ], $set ); $tables = implode( ',', $names ); @@ -173,23 +182,22 @@ class UserDupes { $this->db->query( "LOCK TABLES $tables", __METHOD__ ); } - function lockTable( $table ) { + private function lockTable( $table ) { return $this->db->tableName( $table ) . ' WRITE'; } /** * @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 - * @private */ - function getDupes() { + private function getDupes() { $user = $this->db->tableName( 'user' ); $result = $this->db->query( "SELECT user_name,COUNT(*) AS n @@ -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 - * @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 - * @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 - * @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 - * @private */ - function trimAccount( $userid ) { + private function trimAccount( $userid ) { $this->out( "deleting..." ); $this->db->delete( 'user', [ 'user_id' => $userid ], __METHOD__ ); $this->out( " ok" ); -- 2.20.1