* 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 ),
__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;
}
/**
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.
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