-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop throwing exceptions on commit in PHP8+pdo_mysql combo
MySQL commits implicitly after every DDL query, but since PHP 8, mysql_pdo started to throw exception when attempting to explicitly commit after it implicitly committed. This causes to interrupt the migration process even though all queries completed successfully. Alternative would be to disable transaction for PHP8+pdo_mysql, but that would affect all queries, not only DDL ones like intended, hence going with guard check before each explicit commit. Hopefully this will be fixed directly in DBAL in future, but so far this doesn't look very likely...
- Loading branch information
1 parent
a229b64
commit 670ed59
Showing
5 changed files
with
34 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
lib/Doctrine/Migrations/Tools/Console/TransactionHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Migrations\Tools\Console; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use PDO; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TransactionHelper | ||
{ | ||
public static function commitIfInTransaction(Connection $connection): void | ||
{ | ||
$wrappedConnection = $connection->getWrappedConnection(); | ||
|
||
// Attempt to commit while no transaction is running results in exception since PHP 8 + pdo_mysql combination | ||
if ($wrappedConnection instanceof PDO && ! $wrappedConnection->inTransaction()) { | ||
return; | ||
} | ||
|
||
$connection->commit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters