$exception = null; // error to throw after disconnecting
if ( $this->conn ) {
- // Resolve any dangling transaction first
+ // Roll back any dangling transaction first
if ( $this->trxLevel ) {
if ( $this->trxAtomicLevels ) {
// Cannot let incomplete atomic sections be committed
);
} elseif ( $this->trxAutomatic ) {
// Only the connection manager can commit non-empty DBO_TRX transactions
+ // (empty ones we can silently roll back)
if ( $this->writesOrCallbacksPending() ) {
$exception = new DBUnexpectedError(
$this,
": mass commit/rollback of peer transaction required (DBO_TRX set)."
);
}
- } elseif ( $this->trxLevel ) {
- // Commit explicit transactions as if this was commit()
- $this->queryLogger->warning(
- __METHOD__ . ": writes or callbacks still pending.",
- [ 'trace' => ( new RuntimeException() )->getTraceAsString() ]
+ } else {
+ // Manual transactions should have been committed or rolled
+ // back, even if empty.
+ $exception = new DBUnexpectedError(
+ $this,
+ __METHOD__ . ": transaction is still open (from {$this->trxFname})."
);
}
);
}
- // Commit or rollback the changes and run any callbacks as needed
- if ( $this->trxStatus === self::STATUS_TRX_OK && !$exception ) {
- $this->commit(
- __METHOD__,
- $this->trxAutomatic ? self::FLUSHING_INTERNAL : self::FLUSHING_ONE
- );
- } else {
- $this->rollback( __METHOD__, self::FLUSHING_INTERNAL );
- }
+ // Rollback the changes and run any callbacks as needed
+ $this->rollback( __METHOD__, self::FLUSHING_INTERNAL );
}
// Close the actual connection in the binding handle