Skip to content

Commit fbcd80b

Browse files
committed
[Messenger] Use Doctrine DBAL new Types::* constants
1 parent 88b89c9 commit fbcd80b

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php

+25-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
2121
use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer;
2222
use Doctrine\DBAL\Types\Type;
23+
use Doctrine\DBAL\Types\Types;
2324
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
2425
use Symfony\Component\Messenger\Exception\TransportException;
2526

@@ -53,12 +54,16 @@ class Connection
5354
private $schemaSynchronizer;
5455
private $autoSetup;
5556

57+
private static $useDeprecatedConstants;
58+
5659
public function __construct(array $configuration, DBALConnection $driverConnection, SchemaSynchronizer $schemaSynchronizer = null)
5760
{
5861
$this->configuration = array_replace_recursive(self::DEFAULT_OPTIONS, $configuration);
5962
$this->driverConnection = $driverConnection;
6063
$this->schemaSynchronizer = $schemaSynchronizer ?? new SingleDatabaseSynchronizer($this->driverConnection);
6164
$this->autoSetup = $this->configuration['auto_setup'];
65+
66+
self::$useDeprecatedConstants = self::$useDeprecatedConstants ?? !class_exists(Types::class);
6267
}
6368

6469
public function getConfiguration(): array
@@ -125,12 +130,18 @@ public function send(string $body, array $headers, int $delay = 0): string
125130
$this->configuration['queue_name'],
126131
$now,
127132
$availableAt,
128-
], [
133+
], self::$useDeprecatedConstants ? [
129134
null,
130135
null,
131136
null,
132137
Type::DATETIME,
133138
Type::DATETIME,
139+
] : [
140+
null,
141+
null,
142+
null,
143+
Types::DATETIME_MUTABLE,
144+
Types::DATETIME_MUTABLE,
134145
]);
135146

136147
return $this->driverConnection->lastInsertId();
@@ -168,8 +179,8 @@ public function get(): ?array
168179
$this->executeQuery($queryBuilder->getSQL(), [
169180
$now,
170181
$doctrineEnvelope['id'],
171-
], [
172-
Type::DATETIME,
182+
],[
183+
self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
173184
]);
174185

175186
$this->driverConnection->commit();
@@ -278,9 +289,12 @@ private function createAvailableMessagesQueryBuilder(): QueryBuilder
278289
$redeliverLimit,
279290
$now,
280291
$this->configuration['queue_name'],
281-
], [
292+
], self::$useDeprecatedConstants ? [
282293
Type::DATETIME,
283294
Type::DATETIME,
295+
] : [
296+
Types::DATETIME_MUTABLE,
297+
Types::DATETIME_MUTABLE,
284298
]);
285299
}
286300

@@ -314,20 +328,20 @@ private function getSchema(): Schema
314328
{
315329
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
316330
$table = $schema->createTable($this->configuration['table_name']);
317-
$table->addColumn('id', Type::BIGINT)
331+
$table->addColumn('id', self::$useDeprecatedConstants ? Type::BIGINT : Types::BIGINT)
318332
->setAutoincrement(true)
319333
->setNotnull(true);
320-
$table->addColumn('body', Type::TEXT)
334+
$table->addColumn('body', self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT)
321335
->setNotnull(true);
322-
$table->addColumn('headers', Type::TEXT)
336+
$table->addColumn('headers', self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT)
323337
->setNotnull(true);
324-
$table->addColumn('queue_name', Type::STRING)
338+
$table->addColumn('queue_name', self::$useDeprecatedConstants ? Type::STRING : Types::STRING)
325339
->setNotnull(true);
326-
$table->addColumn('created_at', Type::DATETIME)
340+
$table->addColumn('created_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
327341
->setNotnull(true);
328-
$table->addColumn('available_at', Type::DATETIME)
342+
$table->addColumn('available_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
329343
->setNotnull(true);
330-
$table->addColumn('delivered_at', Type::DATETIME)
344+
$table->addColumn('delivered_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
331345
->setNotnull(false);
332346
$table->setPrimaryKey(['id']);
333347
$table->addIndex(['queue_name']);

0 commit comments

Comments
 (0)