Skip to content

Commit 91e0a2d

Browse files
author
gsimmer
committed
Add experimental loading of drupal settings.php file.
1 parent 7ee8695 commit 91e0a2d

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/DatabaseJanitorCommand.php

+22-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected function configure() {
4444
->addOption('username', 'u', InputOption::VALUE_OPTIONAL, 'Database username')
4545
->addOption('password', 'p', InputOption::VALUE_OPTIONAL, 'Database password')
4646
->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)')
4748
->addArgument('database', InputArgument::REQUIRED, 'Database to dump');
4849
}
4950

@@ -56,15 +57,28 @@ protected function execute(InputInterface $input, OutputInterface $output) {
5657
$helper = $this->getHelper('question');
5758
$this->host = $input->getOption('host');
5859
$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+
}
6271
}
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+
}
6882
}
6983

7084
$this->janitor = new DatabaseJanitor(

0 commit comments

Comments
 (0)