diff --git a/composer.json b/composer.json index 4481ed51..40119f35 100644 --- a/composer.json +++ b/composer.json @@ -253,13 +253,13 @@ "test:database:setup": [ "bin/console doctrine:database:drop --if-exists --no-interaction --force --env=test", "bin/console doctrine:database:create --no-interaction --env=test", - "bin/console draw:doctrine:import-file ./data/sql/dump.sql --no-interaction --env=test", + "bin/console draw:doctrine:mysql-import-file ./data/sql/dump.sql --no-interaction --env=test", "bin/console messenger:setup-transports --no-interaction --env=test", "bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration --quiet --env=test" ], "test:database:setup-dump": [ "@test:database:setup", - "bin/console draw:doctrine:import-file ./data/sql/truncate.sql --no-interaction --env=test -vvv", + "bin/console draw:doctrine:mysql-import-file ./data/sql/truncate.sql --no-interaction --env=test -vvv", "bin/console draw:doctrine:mysql-dump ./data/sql/dump.sql --no-interaction --env=test" ], "linter": [ diff --git a/packages/doctrine-extra/ORM/Command/MysqlDumpCommand.php b/packages/doctrine-extra/ORM/Command/MysqlDumpCommand.php index 815eb883..c55bb162 100644 --- a/packages/doctrine-extra/ORM/Command/MysqlDumpCommand.php +++ b/packages/doctrine-extra/ORM/Command/MysqlDumpCommand.php @@ -27,16 +27,16 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $result = $this->ormManagerRegistry->getConnection($input->getOption('connection')) + $connectionParameter = $this->ormManagerRegistry->getConnection($input->getOption('connection')) ->getParams()['primary']; Process::fromShellCommandline(sprintf( 'mysqldump -h %s -P %s -u %s %s %s > %s', - $result['host'], - $result['port'], - $result['user'], - null === $result['password'] ? '' : '-p'.$result['password'], - $result['dbname'], + $connectionParameter['host'], + $connectionParameter['port'], + $connectionParameter['user'], + null === $connectionParameter['password'] ? '' : '-p'.$connectionParameter['password'], + $connectionParameter['dbname'], $input->getArgument('file') ))->mustRun(); diff --git a/packages/doctrine-extra/ORM/Command/ImportFileCommand.php b/packages/doctrine-extra/ORM/Command/MysqlImportFileCommand.php similarity index 57% rename from packages/doctrine-extra/ORM/Command/ImportFileCommand.php rename to packages/doctrine-extra/ORM/Command/MysqlImportFileCommand.php index 84c5349f..f3c7ade7 100644 --- a/packages/doctrine-extra/ORM/Command/ImportFileCommand.php +++ b/packages/doctrine-extra/ORM/Command/MysqlImportFileCommand.php @@ -8,12 +8,13 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Process\Process; -class ImportFileCommand extends Command +class MysqlImportFileCommand extends Command { public function __construct(private ManagerRegistry $ormManagerRegistry) { - parent::__construct('draw:doctrine:import-file'); + parent::__construct('draw:doctrine:mysql-import-file'); } protected function configure(): void @@ -26,10 +27,20 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $connection = $this->ormManagerRegistry->getConnection($input->getOption('connection')); + $connectionParameter = $this->ormManagerRegistry + ->getConnection($input->getOption('connection')) + ->getParams()['primary']; foreach ($input->getArgument('files') as $file) { - $connection->executeQuery(file_get_contents($file)); + Process::fromShellCommandline(sprintf( + 'mysql -h %s -P %s -u %s %s %s < %s', + $connectionParameter['host'], + $connectionParameter['port'], + $connectionParameter['user'], + null === $connectionParameter['password'] ? '' : '-p'.$connectionParameter['password'], + $connectionParameter['dbname'], + $file + ))->mustRun(); } return Command::SUCCESS; diff --git a/packages/framework-extra-bundle/Tests/DependencyInjection/Integration/DoctrineExtraIntegrationTest.php b/packages/framework-extra-bundle/Tests/DependencyInjection/Integration/DoctrineExtraIntegrationTest.php index efd73020..7011137c 100644 --- a/packages/framework-extra-bundle/Tests/DependencyInjection/Integration/DoctrineExtraIntegrationTest.php +++ b/packages/framework-extra-bundle/Tests/DependencyInjection/Integration/DoctrineExtraIntegrationTest.php @@ -6,8 +6,8 @@ use Doctrine\ORM\EntityManagerInterface; use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration\DoctrineExtraIntegration; use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration\IntegrationInterface; -use Draw\DoctrineExtra\ORM\Command\ImportFileCommand; use Draw\DoctrineExtra\ORM\Command\MysqlDumpCommand; +use Draw\DoctrineExtra\ORM\Command\MysqlImportFileCommand; use Draw\DoctrineExtra\ORM\EntityHandler; use PHPUnit\Framework\Attributes\CoversClass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -61,9 +61,9 @@ public static function provideTestLoad(): iterable ] ), new ServiceConfiguration( - 'draw.doctrine_extra.orm.command.import_file_command', + 'draw.doctrine_extra.orm.command.mysql_import_file_command', [ - ImportFileCommand::class, + MysqlImportFileCommand::class, ] ), new ServiceConfiguration(