diff --git a/bundle/Command/DumpDatabaseCommand.php b/bundle/Command/DumpDatabaseCommand.php index b667bd6e..bd4497f4 100644 --- a/bundle/Command/DumpDatabaseCommand.php +++ b/bundle/Command/DumpDatabaseCommand.php @@ -4,12 +4,12 @@ namespace Netgen\Bundle\SiteBundle\Command; +use Doctrine\DBAL\Connection; use RuntimeException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\Process; @@ -22,7 +22,7 @@ final class DumpDatabaseCommand extends Command { - public function __construct(private ContainerInterface $container) + public function __construct(private Connection $connection) { // Parent constructor call is mandatory for commands registered as services parent::__construct(); @@ -40,11 +40,6 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $databaseName = $this->container->getParameter('database_name'); - $databaseHost = $this->container->getParameter('database_host'); - $databaseUser = $this->container->getParameter('database_user'); - $databasePassword = $this->container->getParameter('database_password'); - $filePath = getcwd() . DIRECTORY_SEPARATOR . trim($input->getArgument('file'), '/'); $targetDirectory = dirname($filePath); $fileName = basename($filePath); @@ -54,6 +49,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $fs->mkdir($targetDirectory); } + $params = $this->connection->getParams(); + // https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_opt // https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_quick // https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction @@ -61,19 +58,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int [ 'mysqldump', '-u', - $databaseUser, + $params['user'], '-h', - $databaseHost, + $params['host'], '--opt', '--quick', '--single-transaction', '-r', $targetDirectory . '/' . $fileName, - $databaseName, + $params['dbname'], ], null, [ - 'MYSQL_PWD' => $databasePassword, + 'MYSQL_PWD' => $params['password'], ], null, null, diff --git a/bundle/Resources/config/services/commands.yaml b/bundle/Resources/config/services/commands.yaml index 8fd03f64..38ab46bd 100644 --- a/bundle/Resources/config/services/commands.yaml +++ b/bundle/Resources/config/services/commands.yaml @@ -33,7 +33,7 @@ services: ngsite.command.dump_database: class: Netgen\Bundle\SiteBundle\Command\DumpDatabaseCommand arguments: - - "@service_container" + - "@ibexa.persistence.connection" tags: - { name: console.command, command: 'ngsite:database:dump' }