Skip to content

Commit

Permalink
[site:install] Small improvements (#4061)
Browse files Browse the repository at this point in the history
* 1

* 2

* 3

* Update InstallCommand.php
  • Loading branch information
mondrake authored and enzolutions committed May 23, 2019
1 parent ac553b7 commit 131bb18
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Command/Site/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ protected function configure()
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
// If Drupal is already installed, and --force is not set, there's no
// point to continue.
$database = Database::getConnectionInfo();
if (!empty($database['default']) && Database::isActiveConnection() && !$input->getOption('force')) {
$this->getIo()->error($this->trans('commands.site.install.messages.already-installed'));
exit(1);
}

// --profile option
$profile = $input->getArgument('profile');
if (!$profile) {
Expand Down Expand Up @@ -225,8 +233,7 @@ function ($profile) {

$is_database_info_set = false;

// Use default database setting if is available
$database = Database::getConnectionInfo();
// Use default database setting if they are available.
if (!empty($database['default'])) {
$this->getIo()->info(
sprintf(
Expand All @@ -239,7 +246,7 @@ function ($profile) {
$is_database_info_set = true;
}

// Use the --db-url argument if it is entered and valid
// Use the db-url argument if it is entered and valid.
if (!$is_database_info_set && !empty($input->getArgument('db-url'))) {
try {
$database = Database::convertDbUrlToConnectionInfo($input->getArgument('db-url'), $this->appRoot);
Expand All @@ -253,15 +260,16 @@ function ($profile) {
);
$is_database_info_set = true;
} catch (\Exception $e) {
$this->getIo()->warning('Invalid --db-url argument: ' . $e->getMessage());
$this->getIo()->warning('Invalid db-url argument: ' . $e->getMessage());
}
}

// Interact if database info is still not available
if (!$is_database_info_set) {

// --db-type option
if (!$input->getOption('db-type')) {
$dbType = $input->getOption('db-type');
if (!$dbType) {
$databases = $this->site->getDatabaseTypes();
$dbType = $this->getIo()->choice(
$this->trans('commands.migrate.setup.questions.db-type'),
Expand Down Expand Up @@ -398,12 +406,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$database_install = $database['default'];
}

// Use the --db-url argument if it is entered and valid
// Use the db-url argument if it is entered and valid
if (!$database_install && !empty($input->getArgument('db-url'))) {
try {
$database_install = Database::convertDbUrlToConnectionInfo($input->getArgument('db-url'), $this->appRoot);
} catch (\Exception $e) {
$this->getIo()->error('Invalid --db-url argument: ' . $e->getMessage());
$this->getIo()->error('Invalid db-url argument: ' . $e->getMessage());
return 1;
}
}
Expand Down Expand Up @@ -434,7 +442,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

// Database option defaults.
// Cleanup an installed database.
if ($input->getOption('force') && Database::isActiveConnection()) {
$connection = Database::getConnection();
if ($connection->driver() === 'sqlite') {
Expand Down Expand Up @@ -575,7 +583,7 @@ protected function runInstaller($database, $uri) {
$this->getIo()->error($this->trans('commands.site.install.messages.already-installed'));
return 1;
} catch (\Exception $e) {
$this->getIo()->error($e->getMessage());
$this->getIo()->error(html_entity_decode(strip_tags($e->getMessage()), ENT_QUOTES));
return 1;
}

Expand Down

0 comments on commit 131bb18

Please sign in to comment.