TransactionHelper.php 594 B

1234567891011121314151617181920212223242526
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\Migrations\Tools;
  4. use Doctrine\DBAL\Connection;
  5. use PDO;
  6. /**
  7. * @internal
  8. */
  9. final class TransactionHelper
  10. {
  11. public static function commitIfInTransaction(Connection $connection): void
  12. {
  13. $wrappedConnection = $connection->getWrappedConnection();
  14. // Attempt to commit while no transaction is running results in exception since PHP 8 + pdo_mysql combination
  15. if ($wrappedConnection instanceof PDO && ! $wrappedConnection->inTransaction()) {
  16. return;
  17. }
  18. $connection->commit();
  19. }
  20. }