8000 feature #50571 [DoctrineBridge] Kill DBAL 2 support (derrabus) · symfony/symfony@d63071c · GitHub
[go: up one dir, main page]

Skip to content

Commit d63071c

Browse files
committed
feature #50571 [DoctrineBridge] Kill DBAL 2 support (derrabus)
This PR was merged into the 7.0 branch. Discussion ---------- [DoctrineBridge] Kill DBAL 2 support | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A DBAL 2 is dead and buried. Let's remove code that we needed to maintain DBAL 2. TODO: - [x] Deprecation layer for removed classes - [x] Check changes for possible backports to 5.4/6.4 - [x] #50576 - [x] #50579 - [x] #50575 Commits ------- eacfedf Kill DBAL 2 support
2 parents 5e8e5b7 + eacfedf commit d63071c

35 files changed

+247
-564
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"doctrine/annotations": "^1.13.1|^2",
130130
"doctrine/collections": "^1.0|^2.0",
131131
"doctrine/data-fixtures": "^1.1",
132-
"doctrine/dbal": "^2.13.1|^3.0",
132+
"doctrine/dbal": "^3.6",
133133
"doctrine/orm": "^2.15",
134134
"dragonmantank/cron-expression": "^3",
135135
"egulias/email-validator": "^2.1.10|^3.1|^4",
@@ -161,7 +161,7 @@
161161
"ext-psr": "<1.1|>=2",
162162
"async-aws/core": "<1.5",
163163
"doctrine/annotations": "<1.13.1",
164-
"doctrine/dbal": "<2.13.1",
164+
"doctrine/dbal": "<3.6",
165165
"doctrine/orm": "<2.15",
166166
"egulias/email-validator": "~3.0.0",
167167
"masterminds/html5": "<2.6",

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bridge\Doctrine\DataCollector;
1313

14-
use Doctrine\DBAL\Logging\DebugStack;
1514
use Doctrine\DBAL\Types\ConversionException;
1615
use Doctrine\DBAL\Types\Type;
1716
use Doctrine\Persistence\ManagerRegistry;
@@ -32,11 +31,6 @@ class DoctrineDataCollector extends DataCollector
3231
private array $connections;
3332
private array $managers;
3433

35-
/**
36-
* @var array<string, DebugStack>
37-
*/
38-
private array $loggers = [];
39-
4034
public function __construct(
4135
private ManagerRegistry $registry,
4236
private DebugDataHolder $debugDataHolder,
@@ -61,16 +55,8 @@ private function collectQueries(): array
6155
{
6256
$queries = [];
6357

64-
if (null !== $this->debugDataHolder) {
65-
foreach ($this->debugDataHolder->getData() as $name => $data) {
66-
$queries[$name] = $this->sanitizeQueries($name, $data);
67-
}
68-
69-
return $queries;
70-
}
71-
72-
foreach ($this->loggers as $name => $logger) {
73-
$queries[$name] = $this->sanitizeQueries($name, $logger->queries);
58+
foreach ($this->debugDataHolder->getData() as $name => $data) {
59+
$queries[$name] = $this->sanitizeQueries($name, $data);
7460
}
7561

7662
return $queries;
@@ -82,17 +68,7 @@ private function collectQueries(): array
8268
public function reset()
8369
{
8470
$this->data = [];
85-
86-
if (null !== $this->debugDataHolder) {
87-
$this->debugDataHolder->reset();
88-
89-
return;
90-
}
91-
92-
foreach ($this->loggers as $logger) {
93-
$logger->queries = [];
94-
$logger->currentQuery = 0;
95-
}
71+
$this->debugDataHolder->reset();
9672
}
9773

9874
public function getManagers()

src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
1313

1414
use Doctrine\DBAL\ArrayParameterType;
15-
use Doctrine\DBAL\Connection;
1615
use Doctrine\DBAL\Types\ConversionException;
1716
use Doctrine\DBAL\Types\Type;
1817
use Doctrine\ORM\QueryBuilder;
@@ -71,13 +70,13 @@ public function getEntitiesByIds(string $identifier, array $values): array
7170
$entity = current($qb->getRootEntities());
7271
$metadata = $qb->getEntityManager()->getClassMetadata($entity);
7372
if (\in_array($type = $metadata->getTypeOfField($identifier), ['integer', 'bigint', 'smallint'])) {
74-
$parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY;
73+
$parameterType = ArrayParameterType::INTEGER;
7574

7675
// Filter out non-integer values (e.g. ""). If we don't, some
7776
// databases such as PostgreSQL fail.
7877
$values = array_values(array_filter($values, fn ($v) => (string) $v === (string) (int) $v || ctype_digit($v)));
7978
} elseif (\in_array($type, ['ulid', 'uuid', 'guid'])) {
80-
$parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;
79+
$parameterType = ArrayParameterType::STRING;
8180

8281
// Like above, but we just filter out empty strings.
8382
$values = array_values(array_filter($values, fn ($v) => '' !== (string) $v));
@@ -96,7 +95,7 @@ public function getEntitiesByIds(string $identifier, array $values): array
9695
unset($value);
9796
}
9897
} else {
99-
$parameterType = class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY;
98+
$parameterType = ArrayParameterType::STRING;
10099
}
101100
if (!$values) {
102101
return [];

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Security\RememberMe;
1313

1414
use Doctrine\DBAL\Connection;
15-
use Doctrine\DBAL\Driver\Result as DriverResult;
1615
use Doctrine\DBAL\ParameterType;
17-
use Doctrine\DBAL\Result;
1816
use Doctrine\DBAL\Schema\Schema;
1917
use Doctrine\DBAL\Types\Types;
2018
use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken;
@@ -43,11 +41,9 @@
4341
*/
4442
class DoctrineTokenProvider implements TokenProviderInterface, TokenVerifierInterface
4543
{
46-
private Connection $conn;
47-
48-
public function __construct(Connection $conn)
49-
{
50-
$this->conn = $conn;
44+
public function __construct(
45+
private Connection $co 10000 nn,
46+
) {
5147
}
5248

5349
public function loadTokenBySeries(string $series): PersistentTokenInterface
@@ -57,13 +53,9 @@ public function loadTokenBySeries(string $series): PersistentTokenInterface
5753
$paramValues = ['series' => $series];
5854
$paramTypes = ['series' => ParameterType::STRING];
5955
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
60-
$row = $stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchAssociative() : $stmt->fetch(\PDO::FETCH_ASSOC);
61-
62-
if ($row) {
63-
return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTime($row['last_used']));
64-
}
56+
$row = $stmt->fetchAssociative() ?: throw new TokenNotFoundException('No token found.');
6557

66-
throw new TokenNotFoundException('No token found.');
58+
return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTime($row['last_used']));
6759
}
6860

6961
/**
@@ -74,11 +66,7 @@ public function deleteTokenBySeries(string $series)
7466
$sql = 'DELETE FROM rememberme_token WHERE series=:series';
7567
$paramValues = ['series' => $series];
7668
$paramTypes = ['series' => ParameterType::STRING];
77-
if (method_exists($this->conn, 'executeStatement')) {
78-
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
79-
} else {
80-
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
81-
}
69+
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
8270
}
8371

8472
/**
@@ -97,11 +85,8 @@ public function updateToken(string $series, #[\SensitiveParameter] string $token
9785
'lastUsed' => Types::DATETIME_IMMUTABLE,
9886
'series' => ParameterType::STRING,
9987
];
100-
if (method_exists($this->conn, 'executeStatement')) {
101-
$updated = $this->conn->executeStatement($sql, $paramValues, $paramTypes);
102-
} else {
103-
$updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes);
104-
}
88+
$updated = $this->conn->executeStatement($sql, $paramValues, $paramTypes);
89+
10590
if ($updated < 1) {
10691
throw new TokenNotFoundException('No token found.');
10792
}
@@ -127,11 +112,7 @@ public function createNewToken(PersistentTokenInterface $token)
127112
'value' => ParameterType::STRING,
128113
'lastUsed' => Types::DATETIME_IMMUTABLE,
129114
];
130-
if (method_exists($this->conn, 'executeStatement')) {
131-
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
132-
} else {
133-
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
134-
}
115+
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
135116
}
136117

137118
public function verifyToken(PersistentTokenInterface $token, #[\SensitiveParameter] string $tokenValue): bool

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,84 @@
2525
use Symfony\Component\VarDumper\Cloner\Data;
2626
use Symfony\Component\VarDumper\Dumper\CliDumper;
2727

28-
// Doctrine DBAL 2 compatibility
29-
class_exists(\Doctrine\DBAL\Platforms\MySqlPlatform::class);
30-
3128
class DoctrineDataCollectorTest extends TestCase
3229
{
33-
use DoctrineDataCollectorTestTrait;
34-
3530
protected function setUp(): void
3631
{
3732
ClockMock::register(self::class);
3833
ClockMock::withClockMock(1500000000);
3934
}
4035

36+
public function testCollectConnections()
37+
{
38+
$c = $this->createCollector([]);
39+
$c->collect(new Request(), new Response());
40+
$c = unserialize(serialize($c));
41+
$this->assertEquals(['default' => 'doctrine.dbal.default_connection'], $c->getConnections());
42+
}
43+
44+
public function testCollectManagers()
45+
{
46+
$c = $this->createCollector([]);
47+
$c->collect(new Request(), new Response());
48+
$c = unserialize(serialize($c));
49+
$this->assertEquals(['default' => 'doctrine.orm.default_entity_manager'], $c->getManagers());
50+
}
51+
52+
public function testCollectQueryCount()
53+
{
54+
$c = $this->createCollector([]);
55+
$c->collect(new Request(), new Response());
56+
$c = unserialize(serialize($c));
57+
$this->assertEquals(0, $c->getQueryCount());
58+
59+
$queries = [
60+
['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 0],
61+
];
62+
$c = $this->createCollector($queries);
63+
$c->collect(new Request(), new Response());
64+
$c = unserialize(serialize($c));
65+
$this->assertEquals(1, $c->getQueryCount());
66+
}
67+
68+
public function testCollectTime()
69+
{
70+
$c = $this->createCollector([]);
71+
$c->collect(new Request(), new Response());
72+
$c = unserialize(serialize($c));
73+
$this->assertEquals(0, $c->getTime());
74+
75+
$queries = [
76+
['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1],
77+
];
78+
$c = $this->createCollector($queries);
79+
$c->collect(new Request(), new Response());
80+
$c = unserialize(serialize($c));
81+
$this->assertEquals(1, $c->getTime());
82+
83+
$queries = [
84+
['sql' => 'SELECT * FROM table1', 'params' => [], 'types' => [], 'executionMS' => 1],
85+
['sql' => 'SELECT * FROM table2', 'params' => [], 'types' => [], 'executionMS' => 2],
86+
];
87+
$c = $this->createCollector($queries);
88+
$c->collect(new Request(), new Response());
89+
$c = unserialize(serialize($c));
90+
$this->assertEquals(3, $c->getTime());
91+
}
92+
93+
public function testCollectQueryWithNoTypes()
94+
{
95+
$queries = [
96+
['sql' => 'SET sql_mode=(SELECT REPLACE(@@sql_mode, \'ONLY_FULL_GROUP_BY\', \'\'))', 'params' => [], 'types' => null, 'executionMS' => 1],
97+
];
98+
$c = $this->createCollector($queries);
99+
$c->collect(new Request(), new Response());
100+
$c = unserialize(serialize($c));
101+
102+
$collectedQueries = $c->getQueries();
103+
$this->assertSame([], $collectedQueries['default'][0]['types']);
104+
}
105+
41106
public function testReset()
42107
{
43108
$queries = [

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTestTrait.php

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ public static function createTestConfiguration(): Configuration
5858
$config->setProxyDir(sys_get_temp_dir());
5959
$config->setProxyNamespace('SymfonyTests\Doctrine');
6060
$config->setMetadataDriverImpl(new AttributeDriver([__DIR__.'/../Tests/Fixtures' => 'Symfony\Bridge\Doctrine\Tests\Fixtures'], true));
61-
if (class_exists(DefaultSchemaManagerFactory::class)) {
62-
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
63-
}
61+
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
6462

6563
return $config;
6664
}

0 commit comments

Comments
 (0)
0