r102432 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102431‎ | r102432 | r102433 >
Date:19:54, 8 November 2011
Author:aaron
Status:ok
Tags:
Comment:
Finished r102422 script:
* Fixed $res var collision
* Corrected reporting of $rowsFixedForBlock
* Replaced $fixedBlockees with an isIPAddress() check to skip non-broken/already-handled rows
* Added the UPDATE statement
Modified paths:
  • /branches/wmf/1.18wmf1/maintenance/fixBug32198.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/maintenance/fixBug32198.php
@@ -15,8 +15,6 @@
1616 die( "Must run on metawiki.\n" ); // sanity
1717 }
1818
19 - $fixedBlockees = array();
20 -
2119 $db = wfGetDB( DB_SLAVE );
2220 $res = $db->select( 'logging', '*',
2321 array(
@@ -40,44 +38,39 @@
4139 // Given the ORDER BY clause in the logging table query, we can make sure
4240 // that the last admin to change the block status of a user "owns" it via
4341 // ipb_by_text. If we hit changes to the block status for the same user again
44 - // we will have already set $fixedBlockees and will skip it.
45 - if ( isset( $fixedBlockees[$blockeeName] ) ) {
46 - $blocksFixed++; // blocking admin name already set
47 - $this->output( "Skipped a block of `{$blockeeName}`, block was later overridden.\n" );
48 - continue;
49 - }
 42+ // we will have already set ipb_by_text to a non-IP so it would be skipped.
5043 $blockee = new CentralAuthUser( $blockeeName ); // the bad user
5144
5245 $blockerName = $row->log_user_text; // the blocking admin
5346
54 - $rowsFixedForBlock = 0;
5547 // Search block log on all wikis with local accounts for this user...
56 - foreach ( $blockee->listAttached() as $wiki ) {
 48+ foreach ( $blockee->listAttached() as $wiki ) { // assumes user was not unattached
5749 $wikiDB = wfGetDB( DB_MASTER, array(), $wiki ); // DB used by $wiki
58 - // Dry run
59 - $res = $wikiDB->select( 'ipblocks', '*',
 50+ $sRes = $wikiDB->select( 'ipblocks', '*',
6051 array(
6152 'ipb_address' => $blockeeName,
6253 'ipb_by' => 0,
6354 'ipb_timestamp > ' . $wikiDB->addQuotes( $wikiDB->timestamp( $epoch ) ) ),
6455 __METHOD__
6556 );
66 - $rowsFixedForBlock = $res->numRows();
67 - /*
68 - $wikiDB->update( 'ipblocks',
69 - array( 'ipb_by_text' => $blockerName ),
70 - array(
71 - 'ipb_address' => $blockeeName,
72 - 'ipb_by' => 0,
73 - 'ipb_timestamp > ' . $wikiDB->addQuotes( $wikiDB->timestamp( $epoch ) ) ),
74 - __METHOD__
75 - );
76 - */
77 - unset( $wikiDB ); // outer loop is fast so this is just for fun :)
78 - }
7957
80 - if ( $res->numRows() ) { // normally 1 row
81 - $this->output( "Fixed $rowsFixedForBlock row(s) for `{$blockeeName}` on $wiki.\n" );
 58+ $rowsFixedForBlock = 0; // per wiki
 59+ foreach ( $sRes as $row ) {
 60+ if ( IP::isIPAddress( $row->ipb_by_text ) ) { // broken row
 61+ $wikiDB->update( 'ipblocks',
 62+ array( 'ipb_by_text' => $blockerName ),
 63+ array( 'ipb_id' => $row->ipb_id, 'ipb_by' => 0 ), // ipb_by for sanity
 64+ __METHOD__
 65+ );
 66+ $rowsFixedForBlock++;
 67+ }
 68+ }
 69+
 70+ if ( $rowsFixedForBlock > 0 ) { // should be 1 row
 71+ $this->output( "$rowsFixedForBlock row(s) for `{$blockeeName}` on $wiki.\n" );
 72+ }
 73+
 74+ unset( $wikiDB ); // outer loop is fast, here for sanity
8275 }
8376
8477 $blocksFixed++;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r102422Added bug 32198 scriptsaaron19:00, 8 November 2011

Status & tagging log