Merge "Make autoblocks update with the parent block"
[lhc/web/wiklou.git] / includes / Block.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.