diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index a6e918f..32e23dd 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -725,6 +725,8 @@ function install_tasks($install_state) { 'run' => $install_state['settings_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED, 'function' => 'Drupal\Core\Installer\Form\SiteSettingsForm', ), + 'install_write_profile' => array( + ), 'install_verify_database_ready' => array( 'run' => $install_state['database_ready'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED, ), @@ -1173,6 +1175,10 @@ function install_select_profile(&$install_state) { * selected. */ function _install_select_profile(&$install_state) { + // Use install profile from settings.php if it is set already. + if ($existing_profile = Settings::get('install_profile')) { + return $existing_profile; + } // Don't need to choose profile if only one available. if (count($install_state['profiles']) == 1) { return key($install_state['profiles']); @@ -2258,3 +2264,20 @@ function install_display_requirements($install_state, $requirements) { } } } + +/** + * Installation task; ensures install profile is written to settings.php. + * + * @param $install_state + * An array of information about the current installation state. + */ +function install_write_profile($install_state) { + if (Settings::get('install_profile') !== $install_state['parameters']['profile']) { + // Remember the profile which was used. + $settings['settings']['install_profile'] = (object) array( + 'value' => $install_state['parameters']['profile'], + 'required' => TRUE, + ); + drupal_rewrite_settings($settings); + } +} diff --git a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsNoProfileTest.php b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsNoProfileTest.php new file mode 100644 index 0000000..61dd5be --- /dev/null +++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsNoProfileTest.php @@ -0,0 +1,79 @@ +settings['settings']['hash_salt'] = (object) array( + 'value' => __CLASS__, + 'required' => TRUE, + ); + + // Pre-configure database credentials. + $connection_info = Database::getConnectionInfo(); + unset($connection_info['default']['pdo']); + unset($connection_info['default']['init_commands']); + + $this->settings['databases']['default'] = (object) array( + 'value' => $connection_info, + 'required' => TRUE, + ); + + // Pre-configure config directories. + $this->settings['config_directories'] = array( + CONFIG_ACTIVE_DIRECTORY => (object) array( + 'value' => conf_path() . '/files/config_active', + 'required' => TRUE, + ), + CONFIG_STAGING_DIRECTORY => (object) array( + 'value' => conf_path() . '/files/config_staging', + 'required' => TRUE, + ), + ); + mkdir($this->settings['config_directories'][CONFIG_ACTIVE_DIRECTORY]->value, 0777, TRUE); + mkdir($this->settings['config_directories'][CONFIG_STAGING_DIRECTORY]->value, 0777, TRUE); + + parent::setUp(); + } + + /** + * {@inheritdoc} + */ + protected function setUpSettings() { + // This step should not appear, since settings.php is fully configured + // already. + } + + /** + * Verifies that installation succeeded. + */ + public function testInstaller() { + $this->assertUrl('user/1'); + $this->assertResponse(200); + $this->assertEqual('testing', Settings::get('install_profile')); + } + +} diff --git a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php index 1951f57..3027d76 100644 --- a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsTest.php @@ -33,8 +33,6 @@ protected function setUp() { // Actually the install profile should be skipped to because it is written // to settings.php. - // @todo https://www.drupal.org/node/2451369 Fix install_profile so that it - // is written to an existing settings.php if possible or if set used. $this->settings['settings']['install_profile'] = (object) array( 'value' => 'testing', 'required' => TRUE, @@ -70,6 +68,14 @@ protected function setUp() { /** * {@inheritdoc} */ + protected function setUpProfile() { + // This step should not appear, since settings.php is fully configured + // already. + } + + /** + * {@inheritdoc} + */ protected function setUpSettings() { // This step should not appear, since settings.php is fully configured // already.