@@ -44,6 +44,7 @@ protected function configure() {
44
44
->addOption ('username ' , 'u ' , InputOption::VALUE_OPTIONAL , 'Database username ' )
45
45
->addOption ('password ' , 'p ' , InputOption::VALUE_OPTIONAL , 'Database password ' )
46
46
->addOption ('trim ' , 't ' , InputOption::VALUE_NONE , 'Whether or not to execute trimming ' )
47
+ ->addOption ('drupal ' , 'd ' , InputOption::VALUE_REQUIRED , 'Whether to read from a Drupal settings file (and where) ' )
47
48
->addArgument ('database ' , InputArgument::REQUIRED , 'Database to dump ' );
48
49
}
49
50
@@ -56,15 +57,28 @@ protected function execute(InputInterface $input, OutputInterface $output) {
56
57
$ helper = $ this ->getHelper ('question ' );
57
58
$ this ->host = $ input ->getOption ('host ' );
58
59
$ this ->database = $ input ->getArgument ('database ' );
59
- if (!$ this ->username = $ input ->getOption ('username ' )) {
60
- $ question = new Question ('Enter database user: ' );
61
- $ this ->username = $ helper ->ask ($ input , $ output , $ question );
60
+ if (!$ input ->getOption ('drupal ' )) {
61
+ if (!$ this ->username = $ input ->getOption ('username ' )) {
62
+ $ question = new Question ('Enter database user: ' );
63
+ $ this ->username = $ helper ->ask ($ input , $ output , $ question );
64
+ }
65
+ if (!$ this ->password = $ input ->getOption ('password ' ) && !$ input ->getOption ('drupal ' )) {
66
+ $ question = new Question ('Enter database password for ' . $ this ->username . ': ' );
67
+ $ question ->setHidden (TRUE );
68
+ $ question ->setHiddenFallback (FALSE );
69
+ $ this ->password = $ helper ->ask ($ input , $ output , $ question );
70
+ }
62
71
}
63
- if (!$ this ->password = $ input ->getOption ('password ' )) {
64
- $ question = new Question ('Enter database password for ' . $ this ->username . ': ' );
65
- $ question ->setHidden (TRUE );
66
- $ question ->setHiddenFallback (FALSE );
67
- $ this ->password = $ helper ->ask ($ input , $ output , $ question );
72
+ else {
73
+ // Try to load drupal configuration file specified, assuming database is
74
+ // "default" until I hear otherwise.
75
+ require_once $ input ->getOption ('drupal ' );
76
+ if ($ databases ['default ' ] && is_array ($ databases ['default ' ])) {
77
+ $ db_array = $ databases ['default ' ]['default ' ];
78
+ $ this ->host = $ db_array ['host ' ];
79
+ $ this ->username = $ db_array ['username ' ];
80
+ $ this ->password = $ db_array ['password ' ];
81
+ }
68
82
}
69
83
70
84
$ this ->janitor = new DatabaseJanitor (
0 commit comments