8000 [Messenger] stop using the deprecated schema synchronizer API by xabbuh · Pull Request #37907 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] stop using the deprecated schema synchronizer API #37907

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

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
stop using the deprecated schema synchronizer API
  • Loading branch information
xabbuh committed Aug 21, 2020
commit 40129d623900668ecf9a79b68dbb91711a38a069
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\SchemaConfig;
use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer;
use Doctrine\DBAL\Statement;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
Expand All @@ -29,7 +28,6 @@ public function testGetAMessageWillChangeItsStatus()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$stmt = $this->getResultMock([
'id' => 1,
'body' => '{"message":"Hi"}',
Expand All @@ -52,7 +50,7 @@ public function testGetAMessageWillChangeItsStatus()
->method('executeQuery')
->willReturn($stmt);

$connection = new Connection([], $driverConnection, $schemaSynchronizer);
$connection = new Connection([], $driverConnection);
$doctrineEnvelope = $connection->get();
$this->assertEquals(1, $doctrineEnvelope['id']);
$this->assertEquals('{"message":"Hi"}', $doctrineEnvelope['body']);
Expand All @@ -63,7 +61,6 @@ public function testGetWithNoPendingMessageWillReturnNull()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$stmt = $this->getResultMock(false);

$queryBuilder
Expand All @@ -81,7 +78,7 @@ public function testGetWithNoPendingMessageWillReturnNull()
->method('executeQuery')
->willReturn($stmt);

$connection = new Connection([], $driverConnection, $schemaSynchronizer);
$connection = new Connection([], $driverConnection);
$doctrineEnvelope = $connection->get();
$this->assertNull($doctrineEnvelope);
}
Expand Down Expand Up @@ -154,11 +151,6 @@ private function getResultMock($expectedResult)
return $stmt;
}

private function getSchemaSynchronizerMock(): SchemaSynchronizer
{
return $this->createMock(SchemaSynchronizer::class);
}

/**
* @dataProvider buildConfigurationProvider
*/
Expand Down Expand Up @@ -261,7 +253,6 @@ public function testFind()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$id = 1;
$stmt = $this->getResultMock([
'id' => $id,
Expand All @@ -285,7 +276,7 @@ public function testFind()
->method('executeQuery')
->willReturn($stmt);

$connection = new Connection([], $driverConnection, $schemaSynchronizer);
$connection = new Connection([], $driverConnection);
$doctrineEnvelope = $connection->find($id);
$this->assertEquals(1, $doctrineEnvelope['id']);
$this->assertEquals('{"message":"Hi"}', $doctrineEnvelope['body']);
Expand All @@ -296,7 +287,6 @@ public function testFindAll()
{
$queryBuilder = $this->getQueryBuilderMock();
$driverConnection = $this->getDBALConnectionMock();
$schemaSynchronizer = $this->getSchemaSynchronizerMock();
$message1 = [
'id' => 1,
'body' => '{"message":"Hi"}',
Expand Down Expand Up @@ -332,7 +322,7 @@ public function testFindAll()
->method('executeQuery')
->willReturn($stmt);

$connection = new Connection([], $driverConnection, $schemaSynchronizer);
$connection = new Connection([], $driverConnection);
$doctrineEnvelopes = $connection->findAll();

$this->assertEquals(1, $doctrineEnvelopes[0]['id']);
Expand Down
26 changes: 23 additions & 3 deletions src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
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;
Expand Down Expand Up @@ -60,7 +60,7 @@ public function __construct(array $configuration, DBALConnection $driverConnecti
{
$this->configuration = array_replace_recursive(self::DEFAULT_OPTIONS, $configuration);
$this->driverConnection = $driverConnection;
$this->schemaSynchronizer = $schemaSynchronizer ?? new SingleDatabaseSynchronizer($this->driverConnection);
$this->schemaSynchronizer = $schemaSynchronizer;
$this->autoSetup = $this->configuration['auto_setup'];

if (null === self::$useDeprecatedConstants) {
Expand Down Expand Up @@ -233,7 +233,7 @@ public function setup(): void
$this->driverConnection->getConfiguration()->setFilterSchemaAssetsExpression(null);
}

$this->schemaSynchronizer->updateSchema($this->getSchema(), true);
$this->updateSchema();

if ($hasFilterCallback) {
$this->driverConnection->getConfiguration()->setSchemaAssetsFilter($assetFilter);
Expand Down Expand Up @@ -390,4 +390,24 @@ private function decodeEnvelopeHeaders(array $doctrineEnvelope): array

return $doctrineEnvelope;
}

private function updateSchema(): void
{
if (null !== $this->schemaSynchronizer) {
$this->schemaSynchronizer->updateSchema($this->getSchema(), true);

return;
}

$comparator = new Comparator();
$schemaDiff = $comparator->compare($this->driverConnection->getSchemaManager()->createSchema(), $this->getSchema());

foreach ($schemaDiff->toSaveSql($this->driverConnection->getDatabasePlatform()) as $sql) {
if (method_exists($this->driverConnection, 'executeStatement')) {
$this->driverConnection->executeStatement($sql);
} else {
$this->driverConnection->exec($sql);
}
}
}
}
< 156C /ghcc-consent>
0