);
$page = WikiPage::factory( $title );
$dbw = wfGetDB( DB_MASTER );
- try {
- $dbw->startAtomic( __METHOD__ );
- // delete the associated article first
- $error = '';
- $deleteStatus = $page->doDeleteArticleReal( $reason, $suppress, 0, false, $error, $user );
- // doDeleteArticleReal() returns a non-fatal error status if the page
- // or revision is missing, so check for isOK() rather than isGood()
- if ( $deleteStatus->isOK() ) {
- $status = $file->delete( $reason, $suppress, $user );
- if ( $status->isOK() ) {
- $status->value = $deleteStatus->value; // log id
- $dbw->endAtomic( __METHOD__ );
- } else {
- // Page deleted but file still there? rollback page delete
- wfGetLBFactory()->rollbackMasterChanges( __METHOD__ );
- }
- } else {
- // Done; nothing changed
+ $dbw->startAtomic( __METHOD__ );
+ // delete the associated article first
+ $error = '';
+ $deleteStatus = $page->doDeleteArticleReal( $reason, $suppress, 0, false, $error, $user );
+ // doDeleteArticleReal() returns a non-fatal error status if the page
+ // or revision is missing, so check for isOK() rather than isGood()
+ if ( $deleteStatus->isOK() ) {
+ $status = $file->delete( $reason, $suppress, $user );
+ if ( $status->isOK() ) {
+ $status->value = $deleteStatus->value; // log id
$dbw->endAtomic( __METHOD__ );
+ } else {
+ // Page deleted but file still there? rollback page delete
+ wfGetLBFactory()->rollbackMasterChanges( __METHOD__ );
}
- } catch ( Exception $e ) {
- // Rollback before returning to prevent UI from displaying
- // incorrect "View or restore N deleted edits?"
- $dbw->rollback( __METHOD__ );
- throw $e;
+ } else {
+ // Done; nothing changed
+ $dbw->endAtomic( __METHOD__ );
}
}
*
* @param DBError $exception
* @param int $serverIndex
+ * @throws Exception
*/
protected function handleWriteError( DBError $exception, $serverIndex ) {
if ( $exception instanceof DBConnectionError ) {
}
if ( $exception->db && $exception->db->wasReadOnlyError() ) {
if ( $exception->db->trxLevel() ) {
+ if ( !$this->serverInfos ) {
+ // Errors like deadlocks and connection drops already cause rollback.
+ // For consistency, we have no choice but to throw an error and trigger
+ // complete rollback if the main DB is also being used as the cache DB.
+ throw $exception;
+ }
+
try {
$exception->db->rollback( __METHOD__ );
} catch ( DBError $e ) {
$revisionId = $revision->insertOn( $dbw );
// Update page_latest and friends to reflect the new revision
if ( !$this->updateRevisionOn( $dbw, $revision, null, $meta['oldIsRedirect'] ) ) {
- $dbw->rollback( __METHOD__ ); // sanity; this should never happen
throw new MWException( "Failed to update page row to use new revision." );
}
$revisionId = $revision->insertOn( $dbw );
// Update the page record with revision data
if ( !$this->updateRevisionOn( $dbw, $revision, 0 ) ) {
- $dbw->rollback( __METHOD__ ); // sanity; this should never happen
throw new MWException( "Failed to update page row to use new revision." );
}