Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 'double wrapped' database connections #3139

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions src/Doctrine/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,46 @@ public function __construct(Connection $connection, string $tablePrefix = 'bolt'
$this->tablePrefix = Str::ensureEndsWith($tablePrefix, '_');
}

/**
* @throws \Exception
*/
public function getPlatform(): array
{
/** @var PDOConnection $wrapped */
$wrapped = $this->connection->getWrappedConnection();

[$client_version] = explode(' - ', $wrapped->getAttribute(\PDO::ATTR_CLIENT_VERSION));
// if the wrapped connection has itself a wrapped connection, use that one, etc.
// This is the case in phpunit tests that use the dama/doctrine-test-bundle functionality
while (true) {
if (method_exists($wrapped, 'getWrappedConnection')) {
$nextLevel = $wrapped->getWrappedConnection();
if ($nextLevel) {
$wrapped = $nextLevel;
} else {
break;
}
} else {
break;
}
}

try {
$status = $wrapped->getAttribute(\PDO::ATTR_CONNECTION_STATUS);
} catch (\PDOException $e) {
$status = '';
if ($wrapped instanceof \PDO) {
[$client_version] = explode(' - ', $wrapped->getAttribute(\PDO::ATTR_CLIENT_VERSION));

try {
$status = $wrapped->getAttribute(\PDO::ATTR_CONNECTION_STATUS);
} catch (\PDOException $e) {
$status = '';
}

return [
'client_version' => $client_version,
'driver_name' => $wrapped->getAttribute(\PDO::ATTR_DRIVER_NAME),
'connection_status' => $status,
'server_version' => $wrapped->getAttribute(\PDO::ATTR_SERVER_VERSION),
];
}

return [
'client_version' => $client_version,
'driver_name' => $wrapped->getAttribute(\PDO::ATTR_DRIVER_NAME),
'connection_status' => $status,
'server_version' => $wrapped->getAttribute(\PDO::ATTR_SERVER_VERSION),
];
throw new \Exception("Wrapped connection is not an instanceof \PDO");
}

public function tableContentExists(): bool
Expand Down