Skip to content

Commit

Permalink
#1179 Deprecate doctrine:query:sql command
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Oct 20, 2020
1 parent 6396475 commit 95c9daf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Command/Proxy/RunSqlDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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+
Expand Down
28 changes: 28 additions & 0 deletions Dbal/ManagerRegistryAwareConnectionProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Doctrine\Bundle\DoctrineBundle\Dbal;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\Persistence\AbstractManagerRegistry;

class ManagerRegistryAwareConnectionProvider implements ConnectionProvider
{
/** @var AbstractManagerRegistry */
private $managerRegistry;

public function __construct(AbstractManagerRegistry $managerRegistry)
{
$this->managerRegistry = $managerRegistry;
}

public function getDefaultConnection() : Connection
{
return $this->managerRegistry->getConnection();
}

public function getConnection(string $name) : Connection
{
return $this->managerRegistry->getConnection($name);
}
}
16 changes: 13 additions & 3 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (! interface_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)
Expand Down
6 changes: 6 additions & 0 deletions Resources/config/dbal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,11 @@
<tag name="console.command" command="doctrine:query:sql" />
</service>

<service id="Doctrine\DBAL\Tools\Console\Command\RunSqlCommand">
<argument type="service" id="Doctrine\Bundle\DoctrineBundle\Dbal\ManagerRegistryAwareConnectionProvider" on-invalid="null" />

<tag name="console.command" command="dbal:run-sql" />
</service>

</services>
</container>
7 changes: 7 additions & 0 deletions UPGRADE-2.2.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 95c9daf

Please sign in to comment.