dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some love to UserDupes
[lhc/web/wiklou.git]
/
maintenance
/
userDupes.inc
diff --git
a/maintenance/userDupes.inc
b/maintenance/userDupes.inc
index
44a1aab
..
f759c13
100644
(file)
--- a/
maintenance/userDupes.inc
+++ b/
maintenance/userDupes.inc
@@
-3,7
+3,7
@@
* Helper class for update.php.
*
* Copyright © 2005 Brion Vibber <brion@pobox.com>
* Helper class for update.php.
*
* Copyright © 2005 Brion Vibber <brion@pobox.com>
- * http://www.mediawiki.org/
+ * http
s
://www.mediawiki.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@
-24,6
+24,8
@@
* @ingroup Maintenance
*/
* @ingroup Maintenance
*/
+use Wikimedia\Rdbms\IMaintainableDatabase;
+
/**
* Look for duplicate user table entries and optionally prune them.
*
/**
* Look for duplicate user table entries and optionally prune them.
*
@@
-33,20
+35,28
@@
* @ingroup Maintenance
*/
class UserDupes {
* @ingroup Maintenance
*/
class UserDupes {
+ /**
+ * @var IMaintainableDatabase
+ */
private $db;
private $reassigned;
private $trimmed;
private $failed;
private $outputCallback;
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;
}
/**
* Output some text via the output callback provided
$this->db = $database;
$this->outputCallback = $outputCallback;
}
/**
* Output some text via the output callback provided
- * @param
$str String
Text to print
+ * @param
string $str
Text to print
*/
private function out( $str ) {
call_user_func( $this->outputCallback, $str );
*/
private function out( $str ) {
call_user_func( $this->outputCallback, $str );
@@
-57,10
+67,11
@@
class UserDupes {
* user_name index applied.
* @return bool
*/
* 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" );
$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 false;
}
return false;
}
@@
-81,7
+92,7
@@
class UserDupes {
*
* @return bool
*/
*
* @return bool
*/
- function clearDupes() {
+
public
function clearDupes() {
return $this->checkDupes( true );
}
return $this->checkDupes( true );
}
@@
-95,13
+106,14
@@
class UserDupes {
* not requested. (If doing resolution, edits may be reassigned.)
* Status information will be echo'd to stdout.
*
* not requested. (If doing resolution, edits may be reassigned.)
* Status information will be echo'd to stdout.
*
- * @param
$doDelete bool: p
ass true to actually remove things
- *
from the database; false to just check.
+ * @param
bool $doDelete P
ass true to actually remove things
+ * from the database; false to just check.
* @return bool
*/
* @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";
if ( $this->hasUniqueIndex() ) {
echo wfWikiID() . " already has a unique index on its user table.\n";
+
return true;
}
return true;
}
@@
-125,7
+137,8
@@
class UserDupes {
if ( $this->reassigned > 0 ) {
if ( $doDelete ) {
if ( $this->reassigned > 0 ) {
if ( $doDelete ) {
- $this->out( "$this->reassigned duplicate accounts had edits reassigned to a canonical record id.\n" );
+ $this->out( "$this->reassigned duplicate accounts had edits "
+ . "reassigned to a canonical record id.\n" );
} else {
$this->out( "$this->reassigned duplicate accounts need to have edits reassigned.\n" );
}
} else {
$this->out( "$this->reassigned duplicate accounts need to have edits reassigned.\n" );
}
@@
-133,66
+146,70
@@
class UserDupes {
if ( $this->trimmed > 0 ) {
if ( $doDelete ) {
if ( $this->trimmed > 0 ) {
if ( $doDelete ) {
- $this->out( "$this->trimmed duplicate user records were deleted from " . wfWikiID() . ".\n" );
+ $this->out( "$this->trimmed duplicate user records were deleted from "
+ . wfWikiID() . ".\n" );
} else {
} else {
- $this->out( "$this->trimmed duplicate user accounts were found on " . wfWikiID() . " which can be removed safely.\n" );
+ $this->out( "$this->trimmed duplicate user accounts were found on "
+ . wfWikiID() . " which can be removed safely.\n" );
}
}
if ( $this->failed > 0 ) {
$this->out( "Something terribly awry; $this->failed duplicate accounts were not removed.\n" );
}
}
if ( $this->failed > 0 ) {
$this->out( "Something terribly awry; $this->failed duplicate accounts were not removed.\n" );
+
return false;
}
if ( $this->trimmed == 0 || $doDelete ) {
$this->out( "It is now safe to apply the unique index on user_name.\n" );
return false;
}
if ( $this->trimmed == 0 || $doDelete ) {
$this->out( "It is now safe to apply the unique index on user_name.\n" );
+
return true;
} else {
$this->out( "Run this script again with the --fix option to automatically delete them.\n" );
return true;
} else {
$this->out( "Run this script again with the --fix option to automatically delete them.\n" );
+
return false;
}
}
/**
* We don't want anybody to mess with our stuff...
return false;
}
}
/**
* We don't want anybody to mess with our stuff...
- * @access private
*/
*/
- function lock() {
- $set =
array( 'user', 'revision' )
;
- $names = array_map(
array( $this, 'lockTable' )
, $set );
+
private
function lock() {
+ $set =
[ 'user', 'revision' ]
;
+ $names = array_map(
[ $this, 'lockTable' ]
, $set );
$tables = implode( ',', $names );
$this->db->query( "LOCK TABLES $tables", __METHOD__ );
}
$tables = implode( ',', $names );
$this->db->query( "LOCK TABLES $tables", __METHOD__ );
}
- function lockTable( $table ) {
+
private
function lockTable( $table ) {
return $this->db->tableName( $table ) . ' WRITE';
}
/**
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
$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
$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 =
array()
;
+ $list =
[]
;
foreach ( $result as $row ) {
$list[] = $row->user_name;
}
foreach ( $result as $row ) {
$list[] = $row->user_name;
}
+
return $list;
}
return $list;
}
@@
-200,14
+217,13
@@
class UserDupes {
* Examine user records for the given name. Try to see which record
* will be the one that actually gets used, then check remaining records
* for edits. If the dupes have no edits, we can safely remove them.
* Examine user records for the given name. Try to see which record
* will be the one that actually gets used, then check remaining records
* for edits. If the dupes have no edits, we can safely remove them.
- * @param $name string
- * @param $doDelete bool
- * @access private
+ * @param string $name
+ * @param bool $doDelete
*/
*/
- function examine( $name, $doDelete ) {
+
private
function examine( $name, $doDelete ) {
$result = $this->db->select( 'user',
$result = $this->db->select( 'user',
-
array( 'user_id' )
,
-
array( 'user_name' => $name )
,
+
[ 'user_id' ]
,
+
[ 'user_name' => $name ]
,
__METHOD__ );
$firstRow = $this->db->fetchObject( $result );
__METHOD__ );
$firstRow = $this->db->fetchObject( $result );
@@
-249,41
+265,37
@@
class UserDupes {
* Count the number of edits attributed to this user.
* Does not currently check log table or other things
* where it might show up...
* Count the number of edits attributed to this user.
* Does not currently check log table or other things
* where it might show up...
- * @param
$userid int
+ * @param
int $userid
* @return int
* @return int
- * @access private
*/
*/
- function editCount( $userid ) {
+
private
function editCount( $userid ) {
return intval( $this->db->selectField(
'revision',
'COUNT(*)',
return intval( $this->db->selectField(
'revision',
'COUNT(*)',
-
array( 'rev_user' => $userid )
,
+
[ 'rev_user' => $userid ]
,
__METHOD__ ) );
}
/**
__METHOD__ ) );
}
/**
- * @param $from int
- * @param $to int
- * @access private
+ * @param int $from
+ * @param int $to
*/
*/
- function reassignEdits( $from, $to ) {
+
private
function reassignEdits( $from, $to ) {
$this->out( 'reassigning... ' );
$this->db->update( 'revision',
$this->out( 'reassigning... ' );
$this->db->update( 'revision',
-
array( 'rev_user' => $to )
,
-
array( 'rev_user' => $from )
,
+
[ 'rev_user' => $to ]
,
+
[ 'rev_user' => $from ]
,
__METHOD__ );
$this->out( "ok. " );
}
/**
* Remove a user account line.
__METHOD__ );
$this->out( "ok. " );
}
/**
* Remove a user account line.
- * @param $userid int
- * @access private
+ * @param int $userid
*/
*/
- function trimAccount( $userid ) {
+
private
function trimAccount( $userid ) {
$this->out( "deleting..." );
$this->out( "deleting..." );
- $this->db->delete( 'user',
array( 'user_id' => $userid )
, __METHOD__ );
+ $this->db->delete( 'user',
[ 'user_id' => $userid ]
, __METHOD__ );
$this->out( " ok" );
}
$this->out( " ok" );
}
-
}
}