Fix PHP 8 PDO exception 'There is no active transaction' when autocommitted (as MySQL does when schema changes).
This commit is contained in:
parent
326d025e8d
commit
9f139c70f4
@ -129,9 +129,14 @@ class MigrateTest extends UloggerDatabaseTestCase {
|
||||
foreach ($queries[0] as $query) {
|
||||
uDb::getInstance()->exec($query);
|
||||
}
|
||||
uDb::getInstance()->commit();
|
||||
// make sure the transaction wasn't autocommitted
|
||||
if (uDb::getInstance()->inTransaction()) {
|
||||
uDb::getInstance()->commit();
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
uDb::getInstance()->rollBack();
|
||||
if (uDb::getInstance()->inTransaction()) {
|
||||
uDb::getInstance()->rollBack();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
@ -89,11 +89,16 @@ function updateSchemas() {
|
||||
foreach ($queries as $query) {
|
||||
uDb::getInstance()->exec($query);
|
||||
}
|
||||
uDb::getInstance()->commit();
|
||||
// make sure the transaction wasn't autocommitted
|
||||
if (uDb::getInstance()->inTransaction()) {
|
||||
uDb::getInstance()->commit();
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo "Database query failed: {$e->getMessage()}" . PHP_EOL;
|
||||
echo "Reverting changes..." . PHP_EOL;
|
||||
uDb::getInstance()->rollBack();
|
||||
if (uDb::getInstance()->inTransaction()) {
|
||||
echo "Reverting changes..." . PHP_EOL;
|
||||
uDb::getInstance()->rollBack();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
echo PHP_EOL;
|
||||
|
@ -96,9 +96,14 @@ switch ($command) {
|
||||
foreach ($queries as $query) {
|
||||
$pdo->exec($query);
|
||||
}
|
||||
$pdo->commit();
|
||||
// MySQL autocommits queries that change schema
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->commit();
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
$messages[] = "<span class=\"warn\">{$langSetup["dbqueryfailed"]}</span>";
|
||||
$messages[] = sprintf($langSetup["serversaid"], "<b>" . htmlentities($e->getMessage()) . "</b>");
|
||||
$error = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user