Merge "Avoid fatals in begin/commit/rollback if close() was called"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 19 May 2014 04:20:00 +0000 (04:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 19 May 2014 04:20:00 +0000 (04:20 +0000)
1  2 
includes/db/Database.php

diff --combined includes/db/Database.php
@@@ -926,6 -926,7 +926,6 @@@ abstract class DatabaseBase implements 
                if ( count( $this->mTrxIdleCallbacks ) ) { // sanity
                        throw new MWException( "Transaction idle callbacks still pending." );
                }
 -              $this->mOpened = false;
                if ( $this->mConn ) {
                        if ( $this->trxLevel() ) {
                                if ( !$this->mTrxAutomatic ) {
                                $this->commit( __METHOD__, 'flush' );
                        }
  
 -                      $ret = $this->closeConnection();
 +                      $closed = $this->closeConnection();
                        $this->mConn = false;
 -
 -                      return $ret;
                } else {
 -                      return true;
 +                      $closed = true;
                }
 +              $this->mOpened = false;
 +
 +              return $closed;
        }
  
        /**
                        $this->runOnTransactionIdleCallbacks();
                }
  
+               # Avoid fatals if close() was called
+               if ( !$this->isOpen() ) {
+                       throw new DBUnexpectedError( $this, "DB connection was already closed." );
+               }
                $this->doBegin( $fname );
                $this->mTrxFname = $fname;
                $this->mTrxDoneWrites = false;
                        }
                }
  
+               # Avoid fatals if close() was called
+               if ( !$this->isOpen() ) {
+                       throw new DBUnexpectedError( $this, "DB connection was already closed." );
+               }
                $this->runOnTransactionPreCommitCallbacks();
                $this->doCommit( $fname );
                if ( $this->mTrxDoneWrites ) {
                        }
                }
  
+               # Avoid fatals if close() was called
+               if ( !$this->isOpen() ) {
+                       throw new DBUnexpectedError( $this, "DB connection was already closed." );
+               }
                $this->doRollback( $fname );
                $this->mTrxIdleCallbacks = array(); // cancel
                $this->mTrxPreCommitCallbacks = array(); // cancel