From 522cec38dc8f8ffa65f5a5ebc9e0ac436bdeeda3 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Fri, 15 Apr 2022 12:45:24 +0200 Subject: [PATCH] deprecate sharding functionality --- Command/CreateDatabaseDoctrineCommand.php | 14 +++++++++++++ Command/DoctrineCommand.php | 8 +++++++ Command/DropDatabaseDoctrineCommand.php | 8 +++++++ Command/ImportMappingDoctrineCommand.php | 10 +++++++++ DependencyInjection/Configuration.php | 21 ++++++++++++++++--- DependencyInjection/DoctrineExtension.php | 7 +++++++ Tests/Command/CreateDatabaseDoctrineTest.php | 5 ++++- .../AbstractDoctrineExtensionTest.php | 1 + .../DoctrineExtensionTest.php | 1 + 9 files changed, 71 insertions(+), 4 deletions(-) diff --git a/Command/CreateDatabaseDoctrineCommand.php b/Command/CreateDatabaseDoctrineCommand.php index a02017565..18c89cdcd 100644 --- a/Command/CreateDatabaseDoctrineCommand.php +++ b/Command/CreateDatabaseDoctrineCommand.php @@ -13,6 +13,7 @@ use function array_merge; use function in_array; use function sprintf; +use function trigger_deprecation; /** * Database tool allows you to easily create your configured databases. @@ -78,6 +79,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $params = array_merge($params, $params['global'] ?? []); unset($params['global']['dbname'], $params['global']['path'], $params['global']['url']); if ($input->getOption('shard')) { + trigger_deprecation( + 'doctrine/doctrine-bundle', + '2.7', + 'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.', + self::class + ); + foreach ($shards as $i => $shard) { if ($shard['id'] === (int) $input->getOption('shard')) { // Select sharded database @@ -101,6 +109,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $tmpConnection = DriverManager::getConnection($params); if ($tmpConnection instanceof PoolingShardConnection) { $tmpConnection->connect($input->getOption('shard')); + trigger_deprecation( + 'doctrine/doctrine-bundle', + '2.7', + 'Using a DBAL connection of type "%s" is deprecated. DBAL 3 does not support shards anymore.', + PoolingShardConnection::class + ); } else { $tmpConnection->connect(); } diff --git a/Command/DoctrineCommand.php b/Command/DoctrineCommand.php index 44b98a122..ba3541f2f 100644 --- a/Command/DoctrineCommand.php +++ b/Command/DoctrineCommand.php @@ -12,6 +12,7 @@ use Symfony\Component\Console\Command\Command; use function sprintf; +use function trigger_deprecation; /** * Base class for Doctrine console commands to extend from. @@ -61,6 +62,13 @@ protected function getEntityManager($name, $shardId = null) $manager = $this->getDoctrine()->getManager($name); if ($shardId) { + trigger_deprecation( + 'doctrine/doctrine-bundle', + '2.7', + 'Passing a "shardId" argument to "%s" is deprecated. DBAL 3 does not support shards anymore.', + __METHOD__ + ); + if (! $manager instanceof EntityManagerInterface) { throw new LogicException(sprintf('Sharding is supported only in EntityManager of instance "%s".', EntityManagerInterface::class)); } diff --git a/Command/DropDatabaseDoctrineCommand.php b/Command/DropDatabaseDoctrineCommand.php index 75dfcba7e..24e2cf39a 100644 --- a/Command/DropDatabaseDoctrineCommand.php +++ b/Command/DropDatabaseDoctrineCommand.php @@ -12,6 +12,7 @@ use function array_merge; use function in_array; use function sprintf; +use function trigger_deprecation; /** * Database tool allows you to easily drop your configured databases. @@ -86,6 +87,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Default select global $params = array_merge($params, $params['global'] ?? []); if ($input->getOption('shard')) { + trigger_deprecation( + 'doctrine/doctrine-bundle', + '2.7', + 'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.', + self::class + ); + foreach ($shards as $shard) { if ($shard['id'] === (int) $input->getOption('shard')) { // Select sharded database diff --git a/Command/ImportMappingDoctrineCommand.php b/Command/ImportMappingDoctrineCommand.php index 47697e9ad..6d452790f 100644 --- a/Command/ImportMappingDoctrineCommand.php +++ b/Command/ImportMappingDoctrineCommand.php @@ -20,6 +20,7 @@ use function mkdir; use function sprintf; use function str_replace; +use function trigger_deprecation; /** * Import Doctrine ORM metadata mapping information from an existing database. @@ -120,6 +121,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int $exporter->setEntityGenerator($entityGenerator); } + if ($input->getOption('shard')) { + trigger_deprecation( + 'doctrine/doctrine-bundle', + '2.7', + 'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.', + self::class + ); + } + $em = $this->getEntityManager($input->getOption('em'), $input->getOption('shard')); $databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager()); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 19b0864fd..9b9ac6c1e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -173,9 +173,21 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition ->scalarNode('server_version')->end() ->scalarNode('driver_class')->end() ->scalarNode('wrapper_class')->end() - ->scalarNode('shard_manager_class')->end() - ->scalarNode('shard_choser')->end() - ->scalarNode('shard_choser_service')->end() + ->scalarNode('shard_manager_class') + ->setDeprecated( + ...$this->getDeprecationMsg('The "shard_manager_class" configuration is deprecated and not supported anymore using DBAL 3.', '2.7') + ) + ->end() + ->scalarNode('shard_choser') + ->setDeprecated( + ...$this->getDeprecationMsg('The "shard_choser" configuration is deprecated and not supported anymore using DBAL 3.', '2.7') + ) + ->end() + ->scalarNode('shard_choser_service') + ->setDeprecated( + ...$this->getDeprecationMsg('The "shard_choser_service" configuration is deprecated and not supported anymore using DBAL 3.', '2.7') + ) + ->end() ->booleanNode('keep_slave') ->setDeprecated( ...$this->getDeprecationMsg('The "keep_slave" configuration key is deprecated since doctrine-bundle 2.2. Use the "keep_replica" configuration key instead.', '2.2') @@ -222,6 +234,9 @@ private function getDbalConnectionsNode(): ArrayNodeDefinition $shardNode = $connectionNode ->children() ->arrayNode('shards') + ->setDeprecated( + ...$this->getDeprecationMsg('The "shards" configuration is deprecated and not supported anymore using DBAL 3.', '2.7') + ) ->prototype('array'); $shardNode diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index a95cde667..63b109aaa 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -65,6 +65,7 @@ use function reset; use function sprintf; use function str_replace; +use function trigger_deprecation; use const PHP_VERSION_ID; @@ -277,6 +278,12 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder // Create a shard_manager for this connection if (isset($options['shards'])) { + trigger_deprecation( + 'doctrine/doctrine-bundle', + '2.7', + 'Using shards for connection "%s" is deprecated. DBAL 3 does not support shards anymore.', + $name + ); $shardManagerDefinition = new Definition($options['shardManagerClass'], [new Reference($connectionId)]); $container->setDefinition(sprintf('doctrine.dbal.%s_shard_manager', $name), $shardManagerDefinition); } diff --git a/Tests/Command/CreateDatabaseDoctrineTest.php b/Tests/Command/CreateDatabaseDoctrineTest.php index 6d76e5295..f39f427b9 100644 --- a/Tests/Command/CreateDatabaseDoctrineTest.php +++ b/Tests/Command/CreateDatabaseDoctrineTest.php @@ -54,7 +54,10 @@ public function testExecute(): void ); } - /** @dataProvider provideShardOption */ + /** + * @group legacy + * @dataProvider provideShardOption + */ public function testExecuteWithShardAlias(string $shardOption): void { $connectionName = 'default'; diff --git a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 25c0f63f9..daa5ed4ad 100644 --- a/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -216,6 +216,7 @@ public function testDbalLoadSingleMasterSlaveConnection(): void $this->assertEquals(['engine' => 'InnoDB'], $param['defaultTableOptions']); } + /** @group legacy */ public function testDbalLoadPoolShardingConnection(): void { $container = $this->loadContainer('dbal_service_pool_sharding_connection'); diff --git a/Tests/DependencyInjection/DoctrineExtensionTest.php b/Tests/DependencyInjection/DoctrineExtensionTest.php index fe5881001..146d22827 100644 --- a/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -1079,6 +1079,7 @@ public static function cacheConfigurationProvider(): array ]; } + /** @group legacy */ public function testShardManager(): void { $container = $this->getContainer();