Index: branches/wmf/1.18wmf1/maintenance/fixBug32198.php |
— | — | @@ -15,8 +15,6 @@ |
16 | 16 | die( "Must run on metawiki.\n" ); // sanity |
17 | 17 | } |
18 | 18 | |
19 | | - $fixedBlockees = array(); |
20 | | - |
21 | 19 | $db = wfGetDB( DB_SLAVE ); |
22 | 20 | $res = $db->select( 'logging', '*', |
23 | 21 | array( |
— | — | @@ -40,44 +38,39 @@ |
41 | 39 | // Given the ORDER BY clause in the logging table query, we can make sure |
42 | 40 | // that the last admin to change the block status of a user "owns" it via |
43 | 41 | // 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. |
50 | 43 | $blockee = new CentralAuthUser( $blockeeName ); // the bad user |
51 | 44 | |
52 | 45 | $blockerName = $row->log_user_text; // the blocking admin |
53 | 46 | |
54 | | - $rowsFixedForBlock = 0; |
55 | 47 | // 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 |
57 | 49 | $wikiDB = wfGetDB( DB_MASTER, array(), $wiki ); // DB used by $wiki |
58 | | - // Dry run |
59 | | - $res = $wikiDB->select( 'ipblocks', '*', |
| 50 | + $sRes = $wikiDB->select( 'ipblocks', '*', |
60 | 51 | array( |
61 | 52 | 'ipb_address' => $blockeeName, |
62 | 53 | 'ipb_by' => 0, |
63 | 54 | 'ipb_timestamp > ' . $wikiDB->addQuotes( $wikiDB->timestamp( $epoch ) ) ), |
64 | 55 | __METHOD__ |
65 | 56 | ); |
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 | | - } |
79 | 57 | |
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 |
82 | 75 | } |
83 | 76 | |
84 | 77 | $blocksFixed++; |