minor #35819 [Messenger] Use Doctrine DBAL new Types::* constants (fancyweb)

This PR was merged into the 4.4 branch.

Discussion
----------

[Messenger] Use Doctrine DBAL new Types::* constants

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

f1fb1597ff [Messenger] Use Doctrine DBAL new Types::* constants
This commit is contained in:
Fabien Potencier 2020-02-25 14:05:06 +01:00
commit 8a678f6679
1 changed files with 26 additions and 10 deletions

View File

@ -20,6 +20,7 @@ use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer; use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer; use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Symfony\Component\Messenger\Exception\InvalidArgumentException; use Symfony\Component\Messenger\Exception\InvalidArgumentException;
use Symfony\Component\Messenger\Exception\TransportException; use Symfony\Component\Messenger\Exception\TransportException;
@ -53,12 +54,18 @@ class Connection
private $schemaSynchronizer; private $schemaSynchronizer;
private $autoSetup; private $autoSetup;
private static $useDeprecatedConstants;
public function __construct(array $configuration, DBALConnection $driverConnection, SchemaSynchronizer $schemaSynchronizer = null) public function __construct(array $configuration, DBALConnection $driverConnection, SchemaSynchronizer $schemaSynchronizer = null)
{ {
$this->configuration = array_replace_recursive(self::DEFAULT_OPTIONS, $configuration); $this->configuration = array_replace_recursive(self::DEFAULT_OPTIONS, $configuration);
$this->driverConnection = $driverConnection; $this->driverConnection = $driverConnection;
$this->schemaSynchronizer = $schemaSynchronizer ?? new SingleDatabaseSynchronizer($this->driverConnection); $this->schemaSynchronizer = $schemaSynchronizer ?? new SingleDatabaseSynchronizer($this->driverConnection);
$this->autoSetup = $this->configuration['auto_setup']; $this->autoSetup = $this->configuration['auto_setup'];
if (null === self::$useDeprecatedConstants) {
self::$useDeprecatedConstants = !class_exists(Types::class);
}
} }
public function getConfiguration(): array public function getConfiguration(): array
@ -125,12 +132,18 @@ class Connection
$this->configuration['queue_name'], $this->configuration['queue_name'],
$now, $now,
$availableAt, $availableAt,
], [ ], self::$useDeprecatedConstants ? [
null, null,
null, null,
null, null,
Type::DATETIME, Type::DATETIME,
Type::DATETIME, Type::DATETIME,
] : [
null,
null,
null,
Types::DATETIME_MUTABLE,
Types::DATETIME_MUTABLE,
]); ]);
return $this->driverConnection->lastInsertId(); return $this->driverConnection->lastInsertId();
@ -169,7 +182,7 @@ class Connection
$now, $now,
$doctrineEnvelope['id'], $doctrineEnvelope['id'],
], [ ], [
Type::DATETIME, self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
]); ]);
$this->driverConnection->commit(); $this->driverConnection->commit();
@ -278,9 +291,12 @@ class Connection
$redeliverLimit, $redeliverLimit,
$now, $now,
$this->configuration['queue_name'], $this->configuration['queue_name'],
], [ ], self::$useDeprecatedConstants ? [
Type::DATETIME, Type::DATETIME,
Type::DATETIME, Type::DATETIME,
] : [
Types::DATETIME_MUTABLE,
Types::DATETIME_MUTABLE,
]); ]);
} }
@ -314,20 +330,20 @@ class Connection
{ {
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig()); $schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
$table = $schema->createTable($this->configuration['table_name']); $table = $schema->createTable($this->configuration['table_name']);
$table->addColumn('id', Type::BIGINT) $table->addColumn('id', self::$useDeprecatedConstants ? Type::BIGINT : Types::BIGINT)
->setAutoincrement(true) ->setAutoincrement(true)
->setNotnull(true); ->setNotnull(true);
$table->addColumn('body', Type::TEXT) $table->addColumn('body', self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT)
->setNotnull(true); ->setNotnull(true);
$table->addColumn('headers', Type::TEXT) $table->addColumn('headers', self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT)
->setNotnull(true); ->setNotnull(true);
$table->addColumn('queue_name', Type::STRING) $table->addColumn('queue_name', self::$useDeprecatedConstants ? Type::STRING : Types::STRING)
->setNotnull(true); ->setNotnull(true);
$table->addColumn('created_at', Type::DATETIME) $table->addColumn('created_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
->setNotnull(true); ->setNotnull(true);
$table->addColumn('available_at', Type::DATETIME) $table->addColumn('available_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
->setNotnull(true); ->setNotnull(true);
$table->addColumn('delivered_at', Type::DATETIME) $table->addColumn('delivered_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
->setNotnull(false); ->setNotnull(false);
$table->setPrimaryKey(['id']); $table->setPrimaryKey(['id']);
$table->addIndex(['queue_name']); $table->addIndex(['queue_name']);