Skip to content

Commit

Permalink
Register doctrine:database:import conditionally
Browse files Browse the repository at this point in the history
That command is built from
Doctrine\DBAL\Tools\Console\Command\ImportCommand, which no longer
exists in DBAL 3 (it is removed in favor of using a client application).
  • Loading branch information
greg0ire committed Nov 17, 2020
1 parent 065a36c commit 1597913
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection;

use Doctrine\Bundle\DoctrineBundle\Command\Proxy\ImportDoctrineCommand;
use Doctrine\Bundle\DoctrineBundle\Dbal\ManagerRegistryAwareConnectionProvider;
use Doctrine\Bundle\DoctrineBundle\Dbal\RegexSchemaAssetFilter;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
Expand All @@ -11,6 +12,7 @@
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Logging\LoggerChain;
use Doctrine\DBAL\SQLParserUtils;
use Doctrine\DBAL\Tools\Console\Command\ImportCommand;
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\ORM\Proxy\Autoloader;
use Doctrine\ORM\UnitOfWork;
Expand Down Expand Up @@ -96,6 +98,11 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$chainLogger->addArgument([$logger]);
}

if (class_exists(ImportCommand::class)) {
$container->register('doctrine.database_import_command', ImportDoctrineCommand::class)
->addTag('console.command', ['command' => 'doctrine:database:import']);
}

if (empty($config['default_connection'])) {
$keys = array_keys($config['connections']);
$config['default_connection'] = reset($keys);
Expand Down
4 changes: 0 additions & 4 deletions Resources/config/dbal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@
<tag name="console.command" command="doctrine:database:drop" />
</service>

<service id="doctrine.database_import_command" class="Doctrine\Bundle\DoctrineBundle\Command\Proxy\ImportDoctrineCommand">
<tag name="console.command" command="doctrine:database:import" />
</service>

<service id="doctrine.query_sql_command" class="Doctrine\Bundle\DoctrineBundle\Command\Proxy\RunSqlDoctrineCommand">
<tag name="console.command" command="doctrine:query:sql" />
</service>
Expand Down
6 changes: 6 additions & 0 deletions Tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Configuration as DBALConfiguration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Logging\LoggerChain;
use Doctrine\DBAL\Tools\Console\Command\ImportCommand;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
Expand All @@ -30,6 +31,11 @@ public function testContainerWithDbalOnly(): void
LoggerChain::class,
$container->get('doctrine.dbal.logger.chain.default')
);
if (class_exists(ImportCommand::class)) {
self::assertTrue($container->has('doctrine.database_import_command'));
} else {
self::assertFalse($container->has('doctrine.database_import_command'));
}
}

/**
Expand Down

0 comments on commit 1597913

Please sign in to comment.