From f43facee078b629d9063219f2e47228f2258183e Mon Sep 17 00:00:00 2001 From: Aleksey Tupichenkov Date: Mon, 6 Jul 2026 12:51:58 +0300 Subject: [PATCH] fix: reset schema on transaction rollback --- composer.json | 2 +- src/Doctrine/SchemaConnection.php | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index cd00235..6b4e291 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "doctrine/orm": "^2.17 || ^3.0", "symfony/doctrine-bridge": "^6.4 || ^7.4 || ^8.0", "doctrine/dbal": "^3.4", - "macpaw/schema-context-bundle": "^2.0.6" + "macpaw/schema-context-bundle": "^2.0.7" }, "require-dev": { "doctrine/migrations": "^3.6", diff --git a/src/Doctrine/SchemaConnection.php b/src/Doctrine/SchemaConnection.php index bcdee7f..282e91e 100644 --- a/src/Doctrine/SchemaConnection.php +++ b/src/Doctrine/SchemaConnection.php @@ -27,6 +27,24 @@ public static function setLogger(DebugLogger $logger): void self::$logger = $logger; } + public function close(): void + { + self::$logger?->logSchemaResetByConnectionClose($this->currentSchema ?? ''); + + $this->currentSchema = null; + + parent::close(); + } + + public function rollBack(): bool + { + self::$logger?->logSchemaResetByTransactionRollback($this->currentSchema ?? ''); + + $this->currentSchema = null; + + return parent::rollBack(); + } + public function connect(): bool { $isNewConnection = parent::connect(); @@ -43,8 +61,8 @@ public function connect(): bool if ($this->currentSchema === $schema) { if (self::$logger !== null) { - $actualScheme = $this->getActualSearchPath(); - self::$logger->logSkipSearchPath($schema, $actualScheme); + self::$logger->logActualSearchPath($this->getActualSearchPath()); + self::$logger->logSkipSearchPath($schema, $this->isTransactionActive()); } return $isNewConnection; @@ -89,7 +107,7 @@ private function applySearchPath(string $schema, bool $isNewConnection): void if ($this->_conn !== null) { $schema = $this->getDatabasePlatform()->quoteIdentifier($schema); - self::$logger?->logApplySearchPath($schema, $isNewConnection); + self::$logger?->logApplySearchPath($schema, $isNewConnection, $this->isTransactionActive()); $this->_conn->exec('SET search_path TO ' . $schema); }