From 6040f3af90740293603c83423ae4b094880c91ae Mon Sep 17 00:00:00 2001 From: Tyler Anthony Romeo Date: Sun, 2 Jun 2013 13:36:30 -0400 Subject: [PATCH] Make autoblocks update with the parent block Change SpecialBlock so that when a block already exists, it just updates the existing block rather than deleting and inserting a new row. Also, Block::update() was changed to update existing autoblocks with the new block parameters. Bug: 48813 Change-Id: I5403f6e1d7f8f07273cd5da8068b928fdddcdfc9 --- includes/Block.php | 37 +++++++++++++++++++++++++++--- includes/specials/SpecialBlock.php | 13 +++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/includes/Block.php b/includes/Block.php index 34b89e73a3..6f52a400d6 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -488,13 +488,14 @@ class Block { * Update a block in the DB with new parameters. * The ID field needs to be loaded first. * - * @return Int number of affected rows, which should probably be 1 or something has - * gone slightly awry + * @return bool|array False on failure, array on success: ('id' => block ID, 'autoIds' => array of autoblock IDs) */ public function update() { wfDebug( "Block::update; timestamp {$this->mTimestamp}\n" ); $dbw = wfGetDB( DB_MASTER ); + $dbw->startAtomic( __METHOD__ ); + $dbw->update( 'ipblocks', $this->getDatabaseArray( $dbw ), @@ -502,7 +503,23 @@ class Block { __METHOD__ ); - return $dbw->affectedRows(); + $affected = $dbw->affectedRows(); + + $dbw->update( + 'ipblocks', + $this->getAutoblockUpdateArray(), + array( 'ipb_parent_block_id' => $this->getId() ), + __METHOD__ + ); + + $dbw->endAtomic( __METHOD__ ); + + if ( $affected ) { + $auto_ipd_ids = $this->doRetroactiveAutoblock(); + return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids ); + } + + return false; } /** @@ -545,6 +562,20 @@ class Block { return $a; } + /** + * @return Array + */ + protected function getAutoblockUpdateArray() { + return array( + 'ipb_by' => $this->getBy(), + 'ipb_by_text' => $this->getByName(), + 'ipb_reason' => $this->mReason, + 'ipb_create_account' => $this->prevents( 'createaccount' ), + 'ipb_deleted' => (int)$this->mHideName, // typecast required for SQLite + 'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ), + ); + } + /** * Retroactively autoblocks the last IP used by the user (if it is a user) * blocked by this Block. diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 3b73a37485..beb4d4cf89 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -726,8 +726,17 @@ class SpecialBlock extends FormSpecialPage { return array( 'cant-see-hidden-user' ); } - $currentBlock->delete(); - $status = $block->insert(); + $currentBlock->isHardblock( $block->isHardblock() ); + $currentBlock->prevents( 'createaccount', $block->prevents( 'createaccount' ) ); + $currentBlock->mExpiry = $block->mExpiry; + $currentBlock->isAutoblocking( $block->isAutoblocking() ); + $currentBlock->mHideName = $block->mHideName; + $currentBlock->prevents( 'sendemail', $block->prevents( 'sendemail' ) ); + $currentBlock->prevents( 'editownusertalk', $block->prevents( 'editownusertalk' ) ); + $currentBlock->mReason = $block->mReason; + + $status = $currentBlock->update(); + $logaction = 'reblock'; # Unset _deleted fields if requested -- 2.20.1