Skip to content

Commit 5b27047

Browse files
vpeltotweitzman
authored andcommitted
fix #3624: Change usage of '--config-dir' site-install option. (#3625)
* #3624: Change usage of '--config-dir' site-install option. * Change comment wording. * Check drupal version for backward compatibility & add new existing-config option to use the config sync directory * Fix checkstyle
1 parent 1844496 commit 5b27047

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/Commands/core/SiteInstallCommands.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ class SiteInstallCommands extends DrushCommands implements SiteAliasManagerAware
1919
{
2020
use SiteAliasManagerAwareTrait;
2121

22+
/**
23+
* Drupal version exploded.
24+
*
25+
* eg. [8,6,0-alpha1]
26+
*
27+
* @var array
28+
*/
29+
protected $version_parts = [];
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function __construct()
35+
{
36+
$drupal_root = Drush::bootstrapManager()->getRoot();
37+
$version = Drush::bootstrap()->getVersion($drupal_root);
38+
$this->version_parts = explode('.', $version);
39+
}
40+
2241
/**
2342
* Install Drupal along with modules/themes/configuration/profile.
2443
*
@@ -35,7 +54,8 @@ class SiteInstallCommands extends DrushCommands implements SiteAliasManagerAware
3554
* @option site-name Defaults to Site-Install
3655
* @option site-mail From: for system mailings. Defaults to [email protected]
3756
* @option sites-subdir Name of directory under 'sites' which should be created.
38-
* @option config-dir A path pointing to a full set of configuration which should be imported after installation.
57+
* @option config-dir A path pointing to a full set of configuration which should be installed during installation.
58+
* @option existing-config Configuration from "sync" directory should be installed during installation. This option is ignored if --config-dir is already set.
3959
* @usage drush si expert --locale=uk
4060
* (Re)install using the expert install profile. Set default language to Ukrainian.
4161
* @usage drush si --db-url=mysql://root:pass@localhost:port/dbname
@@ -51,7 +71,7 @@ class SiteInstallCommands extends DrushCommands implements SiteAliasManagerAware
5171
* @aliases si,sin,site-install
5272
*
5373
*/
54-
public function install(array $profile, $options = ['db-url' => self::REQ, 'db-prefix' => self::REQ, 'db-su' => self::REQ, 'db-su-pw' => self::REQ, 'account-name' => 'admin', 'account-mail' => '[email protected]', 'site-mail' => '[email protected]', 'account-pass' => self::REQ, 'locale' => 'en', 'site-name' => 'Drush Site-Install', 'site-pass' => self::REQ, 'sites-subdir' => self::REQ, 'config-dir' => self::REQ])
74+
public function install(array $profile, $options = ['db-url' => self::REQ, 'db-prefix' => self::REQ, 'db-su' => self::REQ, 'db-su-pw' => self::REQ, 'account-name' => 'admin', 'account-mail' => '[email protected]', 'site-mail' => '[email protected]', 'account-pass' => self::REQ, 'locale' => 'en', 'site-name' => 'Drush Site-Install', 'site-pass' => self::REQ, 'sites-subdir' => self::REQ, 'config-dir' => self::REQ, 'existing-config' => false])
5575
{
5676
$additional = $profile;
5777
$profile = array_shift($additional) ?: '';
@@ -81,6 +101,7 @@ public function install(array $profile, $options = ['db-url' => self::REQ, 'db-p
81101
'parameters' => [
82102
'profile' => $profile,
83103
'langcode' => $options['locale'],
104+
'existing_config' => $options['existing-config'],
84105
],
85106
'forms' => [
86107
'install_settings_form' => [
@@ -105,6 +126,7 @@ public function install(array $profile, $options = ['db-url' => self::REQ, 'db-p
105126
'op' => dt('Save and continue'),
106127
],
107128
],
129+
'config_install_path' => $options['config-dir'],
108130
];
109131

110132
// Merge in the additional options.
@@ -137,11 +159,12 @@ public function install(array $profile, $options = ['db-url' => self::REQ, 'db-p
137159
protected function determineProfile($profile, $options, $class_loader)
138160
{
139161
// --config-dir fails with Standard profile and any other one that carries content entities.
140-
// Force to minimal install profile.
141-
if ($options['config-dir']) {
162+
// Force to minimal install profile only for drupal <= 8.5.x.
163+
if ($options['config-dir'] && $this->version_parts[0] <= 8 && $this->version_parts[1] <= 5) {
142164
$this->logger()->info(dt("Using 'minimal' install profile since --config-dir option was provided."));
143165
$profile = 'minimal';
144166
}
167+
145168
if (empty($profile)) {
146169
$boot = Drush::bootstrap();
147170
$profile = $boot->getKernel()->getInstallProfile();
@@ -179,7 +202,8 @@ protected function determineProfile($profile, $options, $class_loader)
179202
*/
180203
public function post($result, CommandData $commandData)
181204
{
182-
if ($config = $commandData->input()->getOption('config-dir')) {
205+
// Only for drupal <= 8.5.x.
206+
if ($config = $commandData->input()->getOption('config-dir') && $this->version_parts[0] <= 8 && $this->version_parts[1] <= 5) {
183207
// Set the destination site UUID to match the source UUID, to bypass a core fail-safe.
184208
$source_storage = new FileStorage($config);
185209
$options = ['yes' => true];

0 commit comments

Comments
 (0)