Merge "Make autoblocks update with the parent block"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 31 Jan 2014 18:59:09 +0000 (18:59 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 31 Jan 2014 18:59:09 +0000 (18:59 +0000)
includes/Block.php
includes/specials/SpecialBlock.php

index 3c22f9b..3575b9d 100644 (file)
@@ -435,13 +435,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 ),
@@ -449,7 +450,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;
        }
 
        /**
@@ -492,6 +509,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.
index d2ee0df..57f23d3 100644 (file)
@@ -729,8 +729,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