diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php index 10f28c53e8..50cc927d71 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php @@ -432,15 +432,13 @@ public function rollBack($savepoint_name = 'drupal_transaction') { } // MySQL will automatically commit transactions when tables are altered or - // created (DDL transactions are not supported). On PHP 7 - // $this->connection->rollback() does not throw an exception if there is no - // active transaction. This behavior is fixed in PHP 8. In order to maintain - // consistent behavior regardless of PHP version, prevent triggering an - // exception on PHP 8. This ensures that the error that has caused the - // rollback is properly reported. + // created (DDL transactions are not supported). Prevent triggering an + // exception to ensure that the error that has caused the rollback is + // properly reported. if (!$this->connection->inTransaction()) { - // This code is unreachable on PHP 7 when a DDL statement has caused a - // commit as $this->connection->inTransaction() will return TRUE. + // On PHP 7 $this->connection->inTransaction() will return TRUE and + // $this->connection->rollback() does not throw an exception; the + // following code is unreachable. trigger_error('Rollback attempted when there is no active transaction. This can cause data integrity issues.', E_USER_WARNING); return; } @@ -452,12 +450,11 @@ public function rollBack($savepoint_name = 'drupal_transaction') { */ protected function doCommit() { // MySQL will automatically commit transactions when tables are altered or - // created (DDL transactions are not supported). On PHP 7 - // $this->connection->commit() does not throw an exception if there is no - // active transaction. This behavior is fixed in PHP 8. In order to maintain - // consistent behavior regardless of PHP version, we check to see if we're - // in transaction before calling commit. + // created (DDL transactions are not supported). Prevent triggering an + // exception in this case as all statements have been committed. if ($this->connection->inTransaction()) { + // On PHP 7 $this->connection->inTransaction() will return TRUE and + // $this->connection->commit() does not throw an exception. $success = parent::doCommit(); } else {