From 57a09fab3ff9a2c892c46c53dbfe0153712296fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Sun, 18 Oct 2020 21:08:33 +0200 Subject: [PATCH] #1179 Deprecate doctrine:query:sql command --- Command/Proxy/RunSqlDoctrineCommand.php | 4 +++ ...ManagerRegistryAwareConnectionProvider.php | 28 +++++++++++++++++++ DependencyInjection/DoctrineExtension.php | 16 +++++++++-- Resources/config/dbal.xml | 6 ++++ UPGRADE-2.2.md | 7 +++++ 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 Dbal/ManagerRegistryAwareConnectionProvider.php create mode 100644 UPGRADE-2.2.md diff --git a/Command/Proxy/RunSqlDoctrineCommand.php b/Command/Proxy/RunSqlDoctrineCommand.php index d784fcbdb..9dab535e2 100644 --- a/Command/Proxy/RunSqlDoctrineCommand.php +++ b/Command/Proxy/RunSqlDoctrineCommand.php @@ -9,6 +9,8 @@ /** * Execute a SQL query and output the results. + * + * @deprecated use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand instead */ class RunSqlDoctrineCommand extends RunSqlCommand { @@ -41,6 +43,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + @trigger_error(sprintf('The "%s" (doctrine:query:sql) is deprecated, use dbal:run-sql command instead.', self::class), E_USER_DEPRECATED); + DoctrineCommandHelper::setApplicationConnection($this->getApplication(), $input->getOption('connection')); // compatibility with doctrine/dbal 2.11+ diff --git a/Dbal/ManagerRegistryAwareConnectionProvider.php b/Dbal/ManagerRegistryAwareConnectionProvider.php new file mode 100644 index 000000000..9ef8969df --- /dev/null +++ b/Dbal/ManagerRegistryAwareConnectionProvider.php @@ -0,0 +1,28 @@ +managerRegistry = $managerRegistry; + } + + public function getDefaultConnection() : Connection + { + return $this->managerRegistry->getConnection(); + } + + public function getConnection(string $name) : Connection + { + return $this->managerRegistry->getConnection($name); + } +} diff --git a/DependencyInjection/DoctrineExtension.php b/DependencyInjection/DoctrineExtension.php index 1c267114c..a98fea567 100644 --- a/DependencyInjection/DoctrineExtension.php +++ b/DependencyInjection/DoctrineExtension.php @@ -2,10 +2,12 @@ namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection; +use Doctrine\Bundle\DoctrineBundle\Dbal\ManagerRegistryAwareConnectionProvider; use Doctrine\Bundle\DoctrineBundle\Dbal\RegexSchemaAssetFilter; use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; +use Doctrine\DBAL\Tools\Console\ConnectionProvider; use Doctrine\ORM\Proxy\Autoloader; use Doctrine\ORM\UnitOfWork; use LogicException; @@ -197,12 +199,20 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder } // Create a shard_manager for this connection - if (! isset($options['shards'])) { + if (isset($options['shards'])) { + $shardManagerDefinition = new Definition($options['shardManagerClass'], [new Reference(sprintf('doctrine.dbal.%s_connection', $name))]); + $container->setDefinition(sprintf('doctrine.dbal.%s_shard_manager', $name), $shardManagerDefinition); + } + + // dbal < 2.11 BC layer + if (! class_exists(ConnectionProvider::class)) { return; } - $shardManagerDefinition = new Definition($options['shardManagerClass'], [new Reference(sprintf('doctrine.dbal.%s_connection', $name))]); - $container->setDefinition(sprintf('doctrine.dbal.%s_shard_manager', $name), $shardManagerDefinition); + $container->setDefinition( + ManagerRegistryAwareConnectionProvider::class, + new Definition(ManagerRegistryAwareConnectionProvider::class, $container->getDefinition('doctrine')) + ); } protected function getConnectionOptions($connection) diff --git a/Resources/config/dbal.xml b/Resources/config/dbal.xml index cb4ae293c..25a4cc656 100644 --- a/Resources/config/dbal.xml +++ b/Resources/config/dbal.xml @@ -102,5 +102,11 @@ + + + + + + diff --git a/UPGRADE-2.2.md b/UPGRADE-2.2.md new file mode 100644 index 000000000..ba928d49a --- /dev/null +++ b/UPGRADE-2.2.md @@ -0,0 +1,7 @@ +UPGRADE FROM 2.1 to 2.2 +======================= + +Commands +-------- + + * `doctrine:query:sql` command has been deprecated. Use `dbal:run-sql` command instead.