Skip to content

Commit ceb95ed

Browse files
committed
Fix ngsite:database:dump command
1 parent 19cb360 commit ceb95ed

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

bundle/Command/DumpDatabaseCommand.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Netgen\Bundle\SiteBundle\Command;
66

7+
use Doctrine\DBAL\Connection;
78
use RuntimeException;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputArgument;
1011
use Symfony\Component\Console\Input\InputInterface;
1112
use Symfony\Component\Console\Output\OutputInterface;
12-
use Symfony\Component\DependencyInjection\ContainerInterface;
1313
use Symfony\Component\Filesystem\Filesystem;
1414
use Symfony\Component\Process\Process;
1515

@@ -22,7 +22,7 @@
2222

2323
final class DumpDatabaseCommand extends Command
2424
{
25-
public function __construct(private ContainerInterface $container)
25+
public function __construct(private Connection $connection)
2626
{
2727
// Parent constructor call is mandatory for commands registered as services
2828
parent::__construct();
@@ -40,11 +40,6 @@ protected function configure(): void
4040

4141
protected function execute(InputInterface $input, OutputInterface $output): int
4242
{
43-
$databaseName = $this->container->getParameter('database_name');
44-
$databaseHost = $this->container->getParameter('database_host');
45-
$databaseUser = $this->container->getParameter('database_user');
46-
$databasePassword = $this->container->getParameter('database_password');
47-
4843
$filePath = getcwd() . DIRECTORY_SEPARATOR . trim($input->getArgument('file'), '/');
4944
$targetDirectory = dirname($filePath);
5045
$fileName = basename($filePath);
@@ -54,26 +49,28 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5449
$fs->mkdir($targetDirectory);
5550
}
5651

52+
$params = $this->connection->getParams();
53+
5754
// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_opt
5855
// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_quick
5956
// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction
6057
$process = new Process(
6158
[
6259
'mysqldump',
6360
'-u',
64-
$databaseUser,
61+
$params['user'],
6562
'-h',
66-
$databaseHost,
63+
$params['host'],
6764
'--opt',
6865
'--quick',
6966
'--single-transaction',
7067
'-r',
7168
$targetDirectory . '/' . $fileName,
72-
$databaseName,
69+
$params['dbname'],
7370
],
7471
null,
7572
[
76-
'MYSQL_PWD' => $databasePassword,
73+
'MYSQL_PWD' => $params['password'],
7774
],
7875
null,
7976
null,

bundle/Resources/config/services/commands.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ services:
3333
ngsite.command.dump_database:
3434
class: Netgen\Bundle\SiteBundle\Command\DumpDatabaseCommand
3535
arguments:
36-
- "@service_container"
36+
- "@ibexa.persistence.connection"
3737
tags:
3838
- { name: console.command, command: 'ngsite:database:dump' }
3939

0 commit comments

Comments
 (0)