* @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;
}
* 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" );
*
* @return bool
*/
- function clearDupes() {
+ public function clearDupes() {
return $this->checkDupes( true );
}
* 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";
/**
* 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 );
$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
* 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 ],
* 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(*)',
/**
* @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 ],
/**
* 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" );