4
4
5
5
namespace Netgen \Bundle \SiteBundle \Command ;
6
6
7
+ use Doctrine \DBAL \Connection ;
7
8
use RuntimeException ;
8
9
use Symfony \Component \Console \Command \Command ;
9
10
use Symfony \Component \Console \Input \InputArgument ;
10
11
use Symfony \Component \Console \Input \InputInterface ;
11
12
use Symfony \Component \Console \Output \OutputInterface ;
12
- use Symfony \Component \DependencyInjection \ContainerInterface ;
13
13
use Symfony \Component \Filesystem \Filesystem ;
14
14
use Symfony \Component \Process \Process ;
15
15
22
22
23
23
final class DumpDatabaseCommand extends Command
24
24
{
25
- public function __construct (private ContainerInterface $ container )
25
+ public function __construct (private Connection $ connection )
26
26
{
27
27
// Parent constructor call is mandatory for commands registered as services
28
28
parent ::__construct ();
@@ -40,11 +40,6 @@ protected function configure(): void
40
40
41
41
protected function execute (InputInterface $ input , OutputInterface $ output ): int
42
42
{
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
-
48
43
$ filePath = getcwd () . DIRECTORY_SEPARATOR . trim ($ input ->getArgument ('file ' ), '/ ' );
49
44
$ targetDirectory = dirname ($ filePath );
50
45
$ fileName = basename ($ filePath );
@@ -54,26 +49,28 @@ protected function execute(InputInterface $input, OutputInterface $output): int
54
49
$ fs ->mkdir ($ targetDirectory );
55
50
}
56
51
52
+ $ params = $ this ->connection ->getParams ();
53
+
57
54
// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_opt
58
55
// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_quick
59
56
// https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction
60
57
$ process = new Process (
61
58
[
62
59
'mysqldump ' ,
63
60
'-u ' ,
64
- $ databaseUser ,
61
+ $ params [ ' user ' ] ,
65
62
'-h ' ,
66
- $ databaseHost ,
63
+ $ params [ ' host ' ] ,
67
64
'--opt ' ,
68
65
'--quick ' ,
69
66
'--single-transaction ' ,
70
67
'-r ' ,
71
68
$ targetDirectory . '/ ' . $ fileName ,
72
- $ databaseName ,
69
+ $ params [ ' dbname ' ] ,
73
70
],
74
71
null ,
75
72
[
76
- 'MYSQL_PWD ' => $ databasePassword ,
73
+ 'MYSQL_PWD ' => $ params [ ' password ' ] ,
77
74
],
78
75
null ,
79
76
null ,
0 commit comments