Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4:
  minor #35833 [FrameworkBundle] Add missing items in the unused tag pass whitelist (fabpot)
  [HttpClient][DX] Add URL context to JsonException messages
  [Routing] Improve localized routes performances
  [4.4][DoctrineBridge] Use new Types::* constants and support new json type
  [Validator] Add missing translations
  [Messenger] Use Doctrine DBAL new Types::* constants
  • Loading branch information
nicolas-grekas committed Feb 25, 2020
2 parents 290b589 + 7efb10d commit 8c812c8
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions Transport/Doctrine/Connection.php
Original file line number Diff line number Diff line change
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 8c812c8

Please sign in to comment.