From 54b68d189c9634c9bc05016718ac5e9f82938910 Mon Sep 17 00:00:00 2001 From: Kyle McGrogan Date: Thu, 25 Apr 2024 14:50:57 -0400 Subject: [PATCH] Update the export command to use a PHP8-safe PDO transaction commit path PHP8 updated commit to throw an exception if the PDO object knows it's not in a transaction anymore while Doctrine believes that it is. Export is often running DDL commands which cause MySQL to auto-commit transactions, leading to this mismatched state. Add a helper class to support only committing if it's safe to do so --- lib/Doctrine/Export.php | 2 +- lib/Doctrine/TransactionHelper.php | 47 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 lib/Doctrine/TransactionHelper.php diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index ab56d6620..f09610451 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -1221,7 +1221,7 @@ public function exportClasses(array $classes) } } - $connection->commit(); + Doctrine_TransactionHelper::commitIfInTransaction($connection); } } diff --git a/lib/Doctrine/TransactionHelper.php b/lib/Doctrine/TransactionHelper.php new file mode 100644 index 000000000..42cea4706 --- /dev/null +++ b/lib/Doctrine/TransactionHelper.php @@ -0,0 +1,47 @@ +. + */ + +/** + * Doctrine_TransactionHelper + * + * @package Doctrine + * @subpackage Transaction + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 1.4 + * @version $Revision$ + * @author Kyle McGrogan + */ +final class Doctrine_TransactionHelper +{ + public static function commitIfInTransaction(Doctrine_Connection $connection): void + { + $handler = $connection->getDbh(); + + // Attempt to commit while no transaction is running results in exception since PHP 8 + pdo_mysql combination + if ($handler instanceof PDO && !$handler->inTransaction()) { + return; + } + + $connection->commit(); + } +} \ No newline at end of file