From eec3a6dab9ce98c0163392a544a86ea640a9f4d7 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Fri, 17 Dec 2010 15:17:13 +0000 Subject: [PATCH] * Get rid of wfOut() usage in UserDupes * $fname -> __METHOD__ * Get rid of php4 =& --- includes/installer/DatabaseUpdater.php | 2 +- includes/installer/MysqlUpdater.php | 2 +- maintenance/upgrade1_5.php | 6 +- maintenance/userDupes.inc | 84 +++++++++++++------------- 4 files changed, 50 insertions(+), 44 deletions(-) diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 5b3d6ca247..3d55e2560f 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -96,7 +96,7 @@ abstract class DatabaseUpdater { * * @param $str String: Text to output */ - protected function output( $str ) { + public function output( $str ) { if ( $this->maintenance->isQuiet() ) { return; } diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index f5031aff72..01bb7f24f8 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -518,7 +518,7 @@ class MysqlUpdater extends DatabaseUpdater { } protected function doUserUniqueUpdate() { - $duper = new UserDupes( $this->db ); + $duper = new UserDupes( $this->db, array( $this, 'output' ) ); if ( $duper->hasUniqueIndex() ) { $this->output( "...already have unique user_name index.\n" ); return; diff --git a/maintenance/upgrade1_5.php b/maintenance/upgrade1_5.php index 15868b80a4..45fbd21cc8 100644 --- a/maintenance/upgrade1_5.php +++ b/maintenance/upgrade1_5.php @@ -632,9 +632,13 @@ CREATE TABLE $pagelinks ( $this->log( 'Done with links.' ); } + function userDupeCallback( $str ) { + echo $str; + } + function upgradeUser() { // Apply unique index, if necessary: - $duper = new UserDupes( $this->dbw ); + $duper = new UserDupes( $this->dbw, array( $this, 'userDupeCallback' ) ); if ( $duper->hasUniqueIndex() ) { $this->log( "Already have unique user_name index." ); } else { diff --git a/maintenance/userDupes.inc b/maintenance/userDupes.inc index 0b4af7f53c..49fd309a88 100644 --- a/maintenance/userDupes.inc +++ b/maintenance/userDupes.inc @@ -33,9 +33,19 @@ class UserDupes { var $reassigned; var $trimmed; var $failed; + private $outputCallback; - function UserDupes( &$database ) { - $this->db =& $database; + function __construct( &$database, $outputCallback ) { + $this->db = $database; + $this->outputCallback = $outputCallback; + } + + /** + * Output some text via the output callback provided + * @param $str String Text to print + */ + private function out( $str ) { + call_user_func( $this->outputCallback, $str ); } /** @@ -44,10 +54,9 @@ class UserDupes { * @return bool */ function hasUniqueIndex() { - $fname = 'UserDupes::hasUniqueIndex'; - $info = $this->db->indexInfo( 'user', 'user_name', $fname ); + $info = $this->db->indexInfo( 'user', 'user_name', __METHOD__ ); if ( !$info ) { - wfOut( "WARNING: doesn't seem to have user_name index at all!\n" ); + $this->out( "WARNING: doesn't seem to have user_name index at all!\n" ); return false; } @@ -94,11 +103,11 @@ class UserDupes { $this->lock(); - wfOut( "Checking for duplicate accounts...\n" ); + $this->out( "Checking for duplicate accounts...\n" ); $dupes = $this->getDupes(); $count = count( $dupes ); - wfOut( "Found $count accounts with duplicate records on " . wfWikiID() . ".\n" ); + $this->out( "Found $count accounts with duplicate records on " . wfWikiID() . ".\n" ); $this->trimmed = 0; $this->reassigned = 0; $this->failed = 0; @@ -108,34 +117,34 @@ class UserDupes { $this->unlock(); - wfOut( "\n" ); + $this->out( "\n" ); if ( $this->reassigned > 0 ) { if ( $doDelete ) { - wfOut( "$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 { - wfOut( "$this->reassigned duplicate accounts need to have edits reassigned.\n" ); + $this->out( "$this->reassigned duplicate accounts need to have edits reassigned.\n" ); } } if ( $this->trimmed > 0 ) { if ( $doDelete ) { - wfOut( "$this->trimmed duplicate user records were deleted from " . wfWikiID() . ".\n" ); + $this->out( "$this->trimmed duplicate user records were deleted from " . wfWikiID() . ".\n" ); } else { - wfOut( "$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 ) { - wfOut( "Something terribly awry; $this->failed duplicate accounts were not removed.\n" ); + $this->out( "Something terribly awry; $this->failed duplicate accounts were not removed.\n" ); return false; } if ( $this->trimmed == 0 || $doDelete ) { - wfOut( "It is now safe to apply the unique index on user_name.\n" ); + $this->out( "It is now safe to apply the unique index on user_name.\n" ); return true; } else { - wfOut( "Run this script again with the --fix option to automatically delete them.\n" ); + $this->out( "Run this script again with the --fix option to automatically delete them.\n" ); return false; } } @@ -145,7 +154,6 @@ class UserDupes { * @access private */ function lock() { - $fname = 'UserDupes::lock'; if ( $this->newSchema() ) { $set = array( 'user', 'revision' ); } else { @@ -154,7 +162,7 @@ class UserDupes { $names = array_map( array( $this, 'lockTable' ), $set ); $tables = implode( ',', $names ); - $this->db->query( "LOCK TABLES $tables", $fname ); + $this->db->query( "LOCK TABLES $tables", __METHOD__ ); } function lockTable( $table ) { @@ -173,8 +181,7 @@ class UserDupes { * @access private */ function unlock() { - $fname = 'UserDupes::unlock'; - $this->db->query( "UNLOCK TABLES", $fname ); + $this->db->query( "UNLOCK TABLES", __METHOD__ ); } /** @@ -183,13 +190,12 @@ class UserDupes { * @access private */ function getDupes() { - $fname = 'UserDupes::listDupes'; $user = $this->db->tableName( 'user' ); $result = $this->db->query( "SELECT user_name,COUNT(*) AS n FROM $user GROUP BY user_name - HAVING n > 1", $fname ); + HAVING n > 1", __METHOD__ ); $list = array(); foreach ( $result as $row ) { @@ -207,44 +213,43 @@ class UserDupes { * @access private */ function examine( $name, $doDelete ) { - $fname = 'UserDupes::listDupes'; $result = $this->db->select( 'user', array( 'user_id' ), array( 'user_name' => $name ), - $fname ); + __METHOD__ ); $firstRow = $this->db->fetchObject( $result ); $firstId = $firstRow->user_id; - wfOut( "Record that will be used for '$name' is user_id=$firstId\n" ); + $this->out( "Record that will be used for '$name' is user_id=$firstId\n" ); foreach ( $result as $row ) { $dupeId = $row->user_id; - wfOut( "... dupe id $dupeId: " ); + $this->out( "... dupe id $dupeId: " ); $edits = $this->editCount( $dupeId ); if ( $edits > 0 ) { $this->reassigned++; - wfOut( "has $edits edits! " ); + $this->out( "has $edits edits! " ); if ( $doDelete ) { $this->reassignEdits( $dupeId, $firstId ); $newEdits = $this->editCount( $dupeId ); if ( $newEdits == 0 ) { - wfOut( "confirmed cleaned. " ); + $this->out( "confirmed cleaned. " ); } else { $this->failed++; - wfOut( "WARNING! $newEdits remaining edits for $dupeId; NOT deleting user.\n" ); + $this->out( "WARNING! $newEdits remaining edits for $dupeId; NOT deleting user.\n" ); continue; } } else { - wfOut( "(will need to reassign edits on fix)" ); + $this->out( "(will need to reassign edits on fix)" ); } } else { - wfOut( "ok, no edits. " ); + $this->out( "ok, no edits. " ); } $this->trimmed++; if ( $doDelete ) { $this->trimAccount( $dupeId ); } - wfOut( "\n" ); + $this->out( "\n" ); } } @@ -274,12 +279,11 @@ class UserDupes { * @access private */ function editCountOn( $table, $field, $userid ) { - $fname = 'UserDupes::editCountOn'; return intval( $this->db->selectField( $table, 'COUNT(*)', array( $field => $userid ), - $fname ) ); + __METHOD__ ) ); } /** @@ -304,13 +308,12 @@ class UserDupes { * @access private */ function reassignEditsOn( $table, $field, $from, $to ) { - $fname = 'UserDupes::reassignEditsOn'; - wfOut( "reassigning on $table... " ); + $this->out( "reassigning on $table... " ); $this->db->update( $table, array( $field => $to ), array( $field => $from ), - $fname ); - wfOut( "ok. " ); + __METHOD__ ); + $this->out( "ok. " ); } /** @@ -319,10 +322,9 @@ class UserDupes { * @access private */ function trimAccount( $userid ) { - $fname = 'UserDupes::trimAccount'; - wfOut( "deleting..." ); - $this->db->delete( 'user', array( 'user_id' => $userid ), $fname ); - wfOut( " ok" ); + $this->out( "deleting..." ); + $this->db->delete( 'user', array( 'user_id' => $userid ), __METHOD__ ); + $this->out( " ok" ); } } -- 2.20.1