From e599306830363294f5c5e78d1f777d727c15c2ca Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 15 Apr 2008 23:34:45 +0000 Subject: [PATCH] * Allow for things that call addEntry() to pass in a DB object to make the action and logging be one transaction * Improve logging transactions for block/delete --- includes/Article.php | 17 +++++++++++++---- includes/Block.php | 8 ++++---- includes/LogPage.php | 9 +++++---- includes/SpecialBlockip.php | 24 +++++++++++++++--------- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 473d19ab61..95979f14b2 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1862,9 +1862,6 @@ class Article { # Update the protection log $log = new LogPage( 'protect' ); - - - if( $protect ) { $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description$expiry_description" ) ); } else { @@ -2274,6 +2271,7 @@ class Article { $bitfield = 'rev_deleted'; } + $dbw->begin(); // For now, shunt the revision data into the archive table. // Text is *not* removed from the text table; bulk storage // is left intact to avoid breaking block-compression or @@ -2320,6 +2318,11 @@ class Article { # Now that it's safely backed up, delete it $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__); + $ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy + if( !$ok ) { + $dbw->rollback(); + return false; + } # If using cascading deletes, we can skip some explicit deletes if ( !$dbw->cascadingDeletes() ) { @@ -2357,7 +2360,13 @@ class Article { # Log the deletion, if the page was suppressed, log it at Oversight instead $logtype = $suppress ? 'suppress' : 'delete'; $log = new LogPage( $logtype ); - $log->addEntry( 'delete', $this->mTitle, $reason ); + # Make sure logging got through + $ok = $log->addEntry( 'delete', $this->mTitle, $reason, array(), $dbw ); + if( !$ok ) { + $dbw->rollback(); + return false; + } + $dbw->commit(); return true; } diff --git a/includes/Block.php b/includes/Block.php index f740d35bb3..9a7938946f 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -358,12 +358,13 @@ class Block /** * Insert a block into the block table. - *@return Whether or not the insertion was successful. + * @param Database $dbw, optional + * @return Whether or not the insertion was successful. */ - function insert() + function insert( $dbw = NULL) { wfDebug( "Block::insert; timestamp {$this->mTimestamp}\n" ); - $dbw = wfGetDB( DB_MASTER ); + $dbw = $dbw ? $dbw : wfGetDB( DB_MASTER ); # Unset ipb_anon_only for user blocks, makes no sense if ( $this->mUser ) { @@ -410,7 +411,6 @@ class Block ), 'Block::insert', array( 'IGNORE' ) ); $affected = $dbw->affectedRows(); - $dbw->commit(); if ($affected) $this->doRetroactiveAutoblock(); diff --git a/includes/LogPage.php b/includes/LogPage.php index 041d05ce5e..e86aadf21d 100644 --- a/includes/LogPage.php +++ b/includes/LogPage.php @@ -51,13 +51,13 @@ class LogPage { $this->updateRecentChanges = $rc; } - function saveContent() { + function saveContent( $dbw ) { if( wfReadOnly() ) return false; global $wgUser, $wgLogRestrictions; $fname = 'LogPage::saveContent'; - $dbw = wfGetDB( DB_MASTER ); + $dbw = $dbw ? $dbw : wfGetDB( DB_MASTER ); $uid = $wgUser->getID(); $log_id = $dbw->nextSequenceValue( 'log_log_id_seq' ); @@ -237,8 +237,9 @@ class LogPage { * @param object &$target A title object. * @param string $comment Description associated * @param array $params Parameters passed later to wfMsg.* functions + * @param Database $dbw, optional */ - function addEntry( $action, $target, $comment, $params = array() ) { + function addEntry( $action, $target, $comment, $params = array(), $dbw = NULL ) { if ( !is_array( $params ) ) { $params = array( $params ); } @@ -250,7 +251,7 @@ class LogPage { $this->actionText = LogPage::actionText( $this->type, $action, $target, NULL, $params ); - return $this->saveContent(); + return $this->saveContent( $dbw ); } /** diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php index 61a2910fe3..048a9a4244 100644 --- a/includes/SpecialBlockip.php +++ b/includes/SpecialBlockip.php @@ -349,14 +349,14 @@ class IPBlockForm { $this->BlockCreateAccount, $this->BlockEnableAutoblock, $this->BlockHideName, $this->BlockEmail); - if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) { - - if ( !$block->insert() ) { + if ( wfRunHooks('BlockIp', array(&$block, &$wgUser)) ) { + $dbw = wfGetDB( DB_MASTER ); + $dbw->begin(); + if ( !$block->insert( $dbw ) ) { + $dbw->rollback(); // this could be commit as well; zero rows either way return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress)); } - wfRunHooks('BlockIpComplete', array($block, $wgUser)); - # Prepare log parameters $logParams = array(); $logParams[] = $expirestr; @@ -365,14 +365,20 @@ class IPBlockForm { # Make log entry, if the name is hidden, put it in the oversight log $log_type = ($this->BlockHideName) ? 'suppress' : 'block'; $log = new LogPage( $log_type ); - $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), + $ok = $log->addEntry( 'block', Title::makeTitle( NS_USER, $this->BlockAddress ), $reasonstr, $logParams ); - + # Make sure logging got through + if( !$ok ) { + $dbw->rollback(); + return array('databaseerror'); + } + $dbw->commit(); + wfRunHooks('BlockIpComplete', array($block, $wgUser)); # Report to the user return array(); - } - else + } else { return array('hookaborted'); + } } /** -- 2.20.1