Skip to content

Commit 1b7a9b3

Browse files
authored
Automatically select correct profile when using --existing-config (#3657)
1 parent 19de1b8 commit 1b7a9b3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Commands/core/SiteInstallCommands.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use Composer\Semver\Comparator;
55
use Consolidation\AnnotatedCommand\CommandData;
6+
use Drupal\Component\FileCache\FileCacheFactory;
67
use Drupal\Core\Database\ConnectionNotDefinedException;
78
use Drush\Commands\DrushCommands;
89
use Drush\Drush;
@@ -149,6 +150,18 @@ protected function determineProfile($profile, $options, $class_loader)
149150
$profile = 'minimal';
150151
}
151152

153+
// Try to get profile from existing config if not provided as an argument.
154+
// @todo Arguably Drupal core [$boot->getKernel()->getInstallProfile()] could do this - https://github.com/drupal/drupal/blob/8.6.x/core/lib/Drupal/Core/DrupalKernel.php#L1606 reads from DB storage but not file storage.
155+
if (empty($profile) && $options['existing-config']) {
156+
FileCacheFactory::setConfiguration([FileCacheFactory::DISABLE_CACHE => true]);
157+
$source_storage = new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY));
158+
if (!$source_storage->exists('core.extension')) {
159+
throw new \Exception('Existing configuration directory not found or does not contain a core.extension.yml file.".');
160+
}
161+
$config = $source_storage->read('core.extension');
162+
$profile = $config['profile'];
163+
}
164+
152165
if (empty($profile)) {
153166
$boot = Drush::bootstrap();
154167
$profile = $boot->getKernel()->getInstallProfile();
@@ -173,6 +186,8 @@ protected function determineProfile($profile, $options, $class_loader)
173186
// if it fails.
174187
}
175188
}
189+
190+
// Drupal currently requires that non-interactive installs provide a profile.
176191
if (empty($profile)) {
177192
$profile = 'standard';
178193
}

0 commit comments

Comments
 (0)