r78531 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78530‎ | r78531 | r78532 >
Date:15:17, 17 December 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
* Get rid of wfOut() usage in UserDupes
* $fname -> __METHOD__
* Get rid of php4 =&
Modified paths:
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlUpdater.php (modified) (history)
  • /trunk/phase3/maintenance/upgrade1_5.php (modified) (history)
  • /trunk/phase3/maintenance/userDupes.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/userDupes.inc
@@ -33,21 +33,30 @@
3434 var $reassigned;
3535 var $trimmed;
3636 var $failed;
 37+ private $outputCallback;
3738
38 - function UserDupes( &$database ) {
39 - $this->db =& $database;
 39+ function __construct( &$database, $outputCallback ) {
 40+ $this->db = $database;
 41+ $this->outputCallback = $outputCallback;
4042 }
4143
4244 /**
 45+ * Output some text via the output callback provided
 46+ * @param $str String Text to print
 47+ */
 48+ private function out( $str ) {
 49+ call_user_func( $this->outputCallback, $str );
 50+ }
 51+
 52+ /**
4353 * Check if this database's user table has already had a unique
4454 * user_name index applied.
4555 * @return bool
4656 */
4757 function hasUniqueIndex() {
48 - $fname = 'UserDupes::hasUniqueIndex';
49 - $info = $this->db->indexInfo( 'user', 'user_name', $fname );
 58+ $info = $this->db->indexInfo( 'user', 'user_name', __METHOD__ );
5059 if ( !$info ) {
51 - wfOut( "WARNING: doesn't seem to have user_name index at all!\n" );
 60+ $this->out( "WARNING: doesn't seem to have user_name index at all!\n" );
5261 return false;
5362 }
5463
@@ -94,11 +103,11 @@
95104
96105 $this->lock();
97106
98 - wfOut( "Checking for duplicate accounts...\n" );
 107+ $this->out( "Checking for duplicate accounts...\n" );
99108 $dupes = $this->getDupes();
100109 $count = count( $dupes );
101110
102 - wfOut( "Found $count accounts with duplicate records on " . wfWikiID() . ".\n" );
 111+ $this->out( "Found $count accounts with duplicate records on " . wfWikiID() . ".\n" );
103112 $this->trimmed = 0;
104113 $this->reassigned = 0;
105114 $this->failed = 0;
@@ -108,34 +117,34 @@
109118
110119 $this->unlock();
111120
112 - wfOut( "\n" );
 121+ $this->out( "\n" );
113122
114123 if ( $this->reassigned > 0 ) {
115124 if ( $doDelete ) {
116 - wfOut( "$this->reassigned duplicate accounts had edits reassigned to a canonical record id.\n" );
 125+ $this->out( "$this->reassigned duplicate accounts had edits reassigned to a canonical record id.\n" );
117126 } else {
118 - wfOut( "$this->reassigned duplicate accounts need to have edits reassigned.\n" );
 127+ $this->out( "$this->reassigned duplicate accounts need to have edits reassigned.\n" );
119128 }
120129 }
121130
122131 if ( $this->trimmed > 0 ) {
123132 if ( $doDelete ) {
124 - wfOut( "$this->trimmed duplicate user records were deleted from " . wfWikiID() . ".\n" );
 133+ $this->out( "$this->trimmed duplicate user records were deleted from " . wfWikiID() . ".\n" );
125134 } else {
126 - wfOut( "$this->trimmed duplicate user accounts were found on " . wfWikiID() . " which can be removed safely.\n" );
 135+ $this->out( "$this->trimmed duplicate user accounts were found on " . wfWikiID() . " which can be removed safely.\n" );
127136 }
128137 }
129138
130139 if ( $this->failed > 0 ) {
131 - wfOut( "Something terribly awry; $this->failed duplicate accounts were not removed.\n" );
 140+ $this->out( "Something terribly awry; $this->failed duplicate accounts were not removed.\n" );
132141 return false;
133142 }
134143
135144 if ( $this->trimmed == 0 || $doDelete ) {
136 - wfOut( "It is now safe to apply the unique index on user_name.\n" );
 145+ $this->out( "It is now safe to apply the unique index on user_name.\n" );
137146 return true;
138147 } else {
139 - wfOut( "Run this script again with the --fix option to automatically delete them.\n" );
 148+ $this->out( "Run this script again with the --fix option to automatically delete them.\n" );
140149 return false;
141150 }
142151 }
@@ -145,7 +154,6 @@
146155 * @access private
147156 */
148157 function lock() {
149 - $fname = 'UserDupes::lock';
150158 if ( $this->newSchema() ) {
151159 $set = array( 'user', 'revision' );
152160 } else {
@@ -154,7 +162,7 @@
155163 $names = array_map( array( $this, 'lockTable' ), $set );
156164 $tables = implode( ',', $names );
157165
158 - $this->db->query( "LOCK TABLES $tables", $fname );
 166+ $this->db->query( "LOCK TABLES $tables", __METHOD__ );
159167 }
160168
161169 function lockTable( $table ) {
@@ -173,8 +181,7 @@
174182 * @access private
175183 */
176184 function unlock() {
177 - $fname = 'UserDupes::unlock';
178 - $this->db->query( "UNLOCK TABLES", $fname );
 185+ $this->db->query( "UNLOCK TABLES", __METHOD__ );
179186 }
180187
181188 /**
@@ -183,13 +190,12 @@
184191 * @access private
185192 */
186193 function getDupes() {
187 - $fname = 'UserDupes::listDupes';
188194 $user = $this->db->tableName( 'user' );
189195 $result = $this->db->query(
190196 "SELECT user_name,COUNT(*) AS n
191197 FROM $user
192198 GROUP BY user_name
193 - HAVING n > 1", $fname );
 199+ HAVING n > 1", __METHOD__ );
194200
195201 $list = array();
196202 foreach ( $result as $row ) {
@@ -207,44 +213,43 @@
208214 * @access private
209215 */
210216 function examine( $name, $doDelete ) {
211 - $fname = 'UserDupes::listDupes';
212217 $result = $this->db->select( 'user',
213218 array( 'user_id' ),
214219 array( 'user_name' => $name ),
215 - $fname );
 220+ __METHOD__ );
216221
217222 $firstRow = $this->db->fetchObject( $result );
218223 $firstId = $firstRow->user_id;
219 - wfOut( "Record that will be used for '$name' is user_id=$firstId\n" );
 224+ $this->out( "Record that will be used for '$name' is user_id=$firstId\n" );
220225
221226 foreach ( $result as $row ) {
222227 $dupeId = $row->user_id;
223 - wfOut( "... dupe id $dupeId: " );
 228+ $this->out( "... dupe id $dupeId: " );
224229 $edits = $this->editCount( $dupeId );
225230 if ( $edits > 0 ) {
226231 $this->reassigned++;
227 - wfOut( "has $edits edits! " );
 232+ $this->out( "has $edits edits! " );
228233 if ( $doDelete ) {
229234 $this->reassignEdits( $dupeId, $firstId );
230235 $newEdits = $this->editCount( $dupeId );
231236 if ( $newEdits == 0 ) {
232 - wfOut( "confirmed cleaned. " );
 237+ $this->out( "confirmed cleaned. " );
233238 } else {
234239 $this->failed++;
235 - wfOut( "WARNING! $newEdits remaining edits for $dupeId; NOT deleting user.\n" );
 240+ $this->out( "WARNING! $newEdits remaining edits for $dupeId; NOT deleting user.\n" );
236241 continue;
237242 }
238243 } else {
239 - wfOut( "(will need to reassign edits on fix)" );
 244+ $this->out( "(will need to reassign edits on fix)" );
240245 }
241246 } else {
242 - wfOut( "ok, no edits. " );
 247+ $this->out( "ok, no edits. " );
243248 }
244249 $this->trimmed++;
245250 if ( $doDelete ) {
246251 $this->trimAccount( $dupeId );
247252 }
248 - wfOut( "\n" );
 253+ $this->out( "\n" );
249254 }
250255 }
251256
@@ -274,12 +279,11 @@
275280 * @access private
276281 */
277282 function editCountOn( $table, $field, $userid ) {
278 - $fname = 'UserDupes::editCountOn';
279283 return intval( $this->db->selectField(
280284 $table,
281285 'COUNT(*)',
282286 array( $field => $userid ),
283 - $fname ) );
 287+ __METHOD__ ) );
284288 }
285289
286290 /**
@@ -304,13 +308,12 @@
305309 * @access private
306310 */
307311 function reassignEditsOn( $table, $field, $from, $to ) {
308 - $fname = 'UserDupes::reassignEditsOn';
309 - wfOut( "reassigning on $table... " );
 312+ $this->out( "reassigning on $table... " );
310313 $this->db->update( $table,
311314 array( $field => $to ),
312315 array( $field => $from ),
313 - $fname );
314 - wfOut( "ok. " );
 316+ __METHOD__ );
 317+ $this->out( "ok. " );
315318 }
316319
317320 /**
@@ -319,10 +322,9 @@
320323 * @access private
321324 */
322325 function trimAccount( $userid ) {
323 - $fname = 'UserDupes::trimAccount';
324 - wfOut( "deleting..." );
325 - $this->db->delete( 'user', array( 'user_id' => $userid ), $fname );
326 - wfOut( " ok" );
 326+ $this->out( "deleting..." );
 327+ $this->db->delete( 'user', array( 'user_id' => $userid ), __METHOD__ );
 328+ $this->out( " ok" );
327329 }
328330
329331 }
Index: trunk/phase3/maintenance/upgrade1_5.php
@@ -632,9 +632,13 @@
633633 $this->log( 'Done with links.' );
634634 }
635635
 636+ function userDupeCallback( $str ) {
 637+ echo $str;
 638+ }
 639+
636640 function upgradeUser() {
637641 // Apply unique index, if necessary:
638 - $duper = new UserDupes( $this->dbw );
 642+ $duper = new UserDupes( $this->dbw, array( $this, 'userDupeCallback' ) );
639643 if ( $duper->hasUniqueIndex() ) {
640644 $this->log( "Already have unique user_name index." );
641645 } else {
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -96,7 +96,7 @@
9797 *
9898 * @param $str String: Text to output
9999 */
100 - protected function output( $str ) {
 100+ public function output( $str ) {
101101 if ( $this->maintenance->isQuiet() ) {
102102 return;
103103 }
Index: trunk/phase3/includes/installer/MysqlUpdater.php
@@ -518,7 +518,7 @@
519519 }
520520
521521 protected function doUserUniqueUpdate() {
522 - $duper = new UserDupes( $this->db );
 522+ $duper = new UserDupes( $this->db, array( $this, 'output' ) );
523523 if ( $duper->hasUniqueIndex() ) {
524524 $this->output( "...already have unique user_name index.\n" );
525525 return;

Follow-up revisions

RevisionCommit summaryAuthorDate
r801901.17: MFT first batch of installer changes: r78043, r78231, r78259, r78300, r...catrope20:47, 13 January 2011

Comments

#Comment by 😂 (talk | contribs)   22:04, 12 January 2011

If this merges cleanly I'd like to see it in 1.17.

Status & tagging log