Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/160872
Change subject: Handle merging blocks a bit better ...................................................................... Handle merging blocks a bit better Bug: 39470 Change-Id: I86c3cfe7565eeddbaf9dabe8bab6e21899e30e77 --- M MergeUser.php 1 file changed, 54 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UserMerge refs/changes/72/160872/1 diff --git a/MergeUser.php b/MergeUser.php index 2e58ac3..13e6956 100644 --- a/MergeUser.php +++ b/MergeUser.php @@ -79,6 +79,59 @@ } } + private function mergeBlocks( DatabaseBase $dbw ) { + // Pull blocks directly from master + $rows = $dbw->select( + 'ipblocks', + array( Block::selectFields() ), + array( + $dbw->makeList( array( + 'ipb_user = ' . $dbw->addQuotes( $this->oldUser->getId() ), + 'ipb_user = ' . $dbw->addQuotes( $this->newUser->getId() ), + ), LIST_OR ) + ) + ); + + $newBlock = false; + $oldBlock = false; + foreach ( $rows as $row ) { + if ( $row->ipb_user === $this->oldUser->getId() ) { + $oldBlock = $row; + } elseif ( $row->ipb_user === $this->newUser->getId() ) { + $newBlock = $row; + } + } + + if ( !$newBlock && !$oldBlock ) { + // No one is blocked, yaaay + return; + } elseif ( $newBlock && !$oldBlock ) { + // Only the new user is blocked, so nothing to do. + return; + } elseif ( $oldBlock && !$newBlock ) { + // Just move the old block to the new username + $dbw->update( + 'ipblocks', + array( 'ipb_user' => $this->newUser->getId() ), + array( 'ipb_id' => $oldBlock->ipb_id ), + __METHOD__ + ); + return; + } + + // Okay, lets pick the "strongest" block, and re-apply it to + // the new user. + $oldBlockObj = Block::newFromRow( $oldBlock ); + $newBlockObj = Block::newFromRow( $newBlock ); + + $winner = Block::chooseBlock( array( $oldBlockObj, $newBlockObj ), array() ); + if ( $winner->getId() !== $newBlockObj->getId() ) { + $winner->setTarget( $this->newUser ); + $winner->insert( $dbw ); + $oldBlockObj->delete(); + } + } + /** * Function to merge database references from one user to another user * @@ -97,7 +150,6 @@ array( 'oldimage', 'oi_user', 'oi_user_text' ), array( 'recentchanges', 'rc_user', 'rc_user_text' ), array( 'logging', 'log_user' ), - array( 'ipblocks', 'ipb_user', 'ipb_address' ), array( 'ipblocks', 'ipb_by', 'ipb_by_text' ), array( 'watchlist', 'wl_user' ), array( 'user_groups', 'ug_user', 'options' => array( 'IGNORE' ) ), @@ -110,6 +162,7 @@ $dbw = wfGetDB( DB_MASTER ); $this->deduplicateWatchlistEntries(); + $this->mergeBlocks( $dbw ); foreach ( $updateFields as $fieldInfo ) { $options = isset( $fieldInfo['options'] ) ? $fieldInfo['options'] : array(); -- To view, visit https://gerrit.wikimedia.org/r/160872 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I86c3cfe7565eeddbaf9dabe8bab6e21899e30e77 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UserMerge Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits