Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 26 additions & 10 deletions src/Symfony/Component/Messenger/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