Skip to content

Commit

Permalink
minor #35819 [Messenger] Use Doctrine DBAL new Types::* constants (fa…
Browse files Browse the repository at this point in the history
…ncyweb)

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
-------

f1fb159 [Messenger] Use Doctrine DBAL new Types::* constants
  • Loading branch information
fabpot committed Feb 25, 2020
2 parents ef95f2e + f1fb159 commit 8a678f6
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php
Expand Up @@ -20,6 +20,7 @@
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Symfony\Component\Messenger\Exception\InvalidArgumentException;
use Symfony\Component\Messenger\Exception\TransportException;

Expand Down Expand Up @@ -53,12 +54,18 @@ class Connection
private $schemaSynchronizer;
private $autoSetup;

private static $useDeprecatedConstants;

public function __construct(array $configuration, DBALConnection $driverConnection, SchemaSynchronizer $schemaSynchronizer = null)
{
$this->configuration = array_replace_recursive(self::DEFAULT_OPTIONS, $configuration);
$this->driverConnection = $driverConnection;
$this->schemaSynchronizer = $schemaSynchronizer ?? new SingleDatabaseSynchronizer($this->driverConnection);
$this->autoSetup = $this->configuration['auto_setup'];

if (null === self::$useDeprecatedConstants) {
self::$useDeprecatedConstants = !class_exists(Types::class);
}
}

public function getConfiguration(): array
Expand Down Expand Up @@ -125,12 +132,18 @@ public function send(string $body, array $headers, int $delay = 0): string
$this->configuration['queue_name'],
$now,
$availableAt,
], [
], self::$useDeprecatedConstants ? [
null,
null,
null,
Type::DATETIME,
Type::DATETIME,
] : [
null,
null,
null,
Types::DATETIME_MUTABLE,
Types::DATETIME_MUTABLE,
]);

return $this->driverConnection->lastInsertId();
Expand Down Expand Up @@ -169,7 +182,7 @@ public function get(): ?array
$now,
$doctrineEnvelope['id'],
], [
Type::DATETIME,
self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE,
]);

$this->driverConnection->commit();
Expand Down Expand Up @@ -278,9 +291,12 @@ private function createAvailableMessagesQueryBuilder(): QueryBuilder
$redeliverLimit,
$now,
$this->configuration['queue_name'],
], [
], self::$useDeprecatedConstants ? [
Type::DATETIME,
Type::DATETIME,
] : [
Types::DATETIME_MUTABLE,
Types::DATETIME_MUTABLE,
]);
}

Expand Down Expand Up @@ -314,20 +330,20 @@ private function getSchema(): Schema
{
$schema = new Schema([], [], $this->driverConnection->getSchemaManager()->createSchemaConfig());
$table = $schema->createTable($this->configuration['table_name']);
$table->addColumn('id', Type::BIGINT)
$table->addColumn('id', self::$useDeprecatedConstants ? Type::BIGINT : Types::BIGINT)
->setAutoincrement(true)
->setNotnull(true);
$table->addColumn('body', Type::TEXT)
$table->addColumn('body', self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT)
->setNotnull(true);
$table->addColumn('headers', Type::TEXT)
$table->addColumn('headers', self::$useDeprecatedConstants ? Type::TEXT : Types::TEXT)
->setNotnull(true);
$table->addColumn('queue_name', Type::STRING)
$table->addColumn('queue_name', self::$useDeprecatedConstants ? Type::STRING : Types::STRING)
->setNotnull(true);
$table->addColumn('created_at', Type::DATETIME)
$table->addColumn('created_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
->setNotnull(true);
$table->addColumn('available_at', Type::DATETIME)
$table->addColumn('available_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
->setNotnull(true);
$table->addColumn('delivered_at', Type::DATETIME)
$table->addColumn('delivered_at', self::$useDeprecatedConstants ? Type::DATETIME : Types::DATETIME_MUTABLE)
->setNotnull(false);
$table->setPrimaryKey(['id']);
$table->addIndex(['queue_name']);
Expand Down

0 comments on commit 8a678f6

Please sign in to comment.