From 39e8f38876c08f9f79bbf82375ebefab1adcb452 Mon Sep 17 00:00:00 2001 From: pookmish Date: Sun, 11 Aug 2024 11:15:00 -0700 Subject: [PATCH] ISSUE-69: Respect config.yml database credentials if set. --- src/Drush/Commands/SettingsDrushCommands.php | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Drush/Commands/SettingsDrushCommands.php b/src/Drush/Commands/SettingsDrushCommands.php index 540c130..4754161 100644 --- a/src/Drush/Commands/SettingsDrushCommands.php +++ b/src/Drush/Commands/SettingsDrushCommands.php @@ -47,19 +47,18 @@ class SettingsDrushCommands extends BaseDrushCommands { description: 'Generates the settings.php for site2 passing db credentials.', )] public function initSettings(array $options = [ - 'database' => 'drupal', - 'username' => 'drupal', - 'password' => 'drupal', - 'host' => 'localhost', - 'port' => "3306", + 'database' => NULL, + 'username' => NULL, + 'password' => NULL, + 'host' => NULL, + 'port' => NULL, ]): int { - $db["drupal"]["db"] = [ - 'database' => $options['database'], - 'username' => $options['username'], - 'password' => $options['password'], - 'host' => $options['host'], - 'port' => $options['port'], - ]; + $db = []; + $db['drupal']['db'] = array_filter( + $options, + fn($value, $key) => in_array($key, ['database', 'username', 'password', 'host', 'port']) && $value !== NULL, + ARRAY_FILTER_USE_BOTH + ); try { $site_directory = $this->getSitesSubdirFromUri($this->getConfigValue("docroot"), $this->getConfigValue("drush.uri")); $settings = new Settings($this->getConfigValue("docroot"), $site_directory);