diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 4b21b6c..0959099 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -13,6 +13,7 @@ use Drupal\Core\Form\FormState; use Drupal\Core\Installer\Exception\AlreadyInstalledException; use Drupal\Core\Installer\Exception\InstallerException; +use Drupal\Core\Installer\Exception\InstallProfileMismatchException; use Drupal\Core\Installer\Exception\NoProfilesException; use Drupal\Core\Installer\InstallerKernel; use Drupal\Core\Language\Language; @@ -2187,13 +2188,16 @@ function install_display_requirements($install_state, $requirements) { * * @see _install_select_profile() * + * @throws \Drupal\Core\Installer\Exception\InstallProfileMismatchException + * * @deprecated in Drupal 8.3.0 and will be removed before Drupal 9.0.0. The * install profile is written to core.extension. */ function install_write_profile($install_state) { // Only need to write to settings.php if it is possible. The primary storage // for the install profile is the core.extension configuration. - if (is_writable(\Drupal::service('site.path') . '/settings.php')) { + $settings_path = \Drupal::service('site.path') . '/settings.php'; + if (is_writable($settings_path)) { // Remember the profile which was used. $settings['settings']['install_profile'] = (object) array( 'value' => $install_state['parameters']['profile'], @@ -2201,4 +2205,7 @@ function install_write_profile($install_state) { ); drupal_rewrite_settings($settings); } + elseif (($settings_profile = Settings::get('install_profile')) && $settings_profile !== $install_state['parameters']['profile']) { + throw new InstallProfileMismatchException($install_state['parameters']['profile'], $settings_profile, $settings_path, \Drupal::translation()); + } } diff --git a/core/lib/Drupal/Core/Installer/Exception/InstallProfileMismatchException.php b/core/lib/Drupal/Core/Installer/Exception/InstallProfileMismatchException.php new file mode 100644 index 0000000..d679789 --- /dev/null +++ b/core/lib/Drupal/Core/Installer/Exception/InstallProfileMismatchException.php @@ -0,0 +1,45 @@ +stringTranslation = $string_translation; + + $title = $this->t('Install profile mismatch'); + $message = $this->t( + 'The selected profile %profile does not match the install_profile setting, which is %settings_profile. Cannot write updated setting to %settings_file.', + [ + '%profile' => $selected_profile, + '%settings_profile' => $settings_profile, + '%settings_file' => $settings_file, + ] + ); + parent::__construct($message, $title); + } + +} diff --git a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileBrokenTest.php b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileBrokenTest.php index 69a81c6..6d866f0 100644 --- a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileBrokenTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileBrokenTest.php @@ -2,8 +2,6 @@ namespace Drupal\system\Tests\Installer; -use Drupal\Component\Render\FormattableMarkup; -use Drupal\Component\Utility\Html; use Drupal\Core\DrupalKernel; use Drupal\simpletest\InstallerTestBase; use Drupal\Core\Database\Database; @@ -17,12 +15,6 @@ class InstallerExistingSettingsMismatchProfileBrokenTest extends InstallerTestBase { /** - * The excepted exception message thrown during the installer. - * @var string; - */ - protected $exceptionMessage; - - /** * {@inheritdoc} * * Configures a preexisting settings.php file without an install_profile @@ -63,8 +55,6 @@ protected function setUp() { ]; mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE); - // @todo Remove HTML once https://www.drupal.org/node/2514044 is fixed. - $this->exceptionMessage = (string) new FormattableMarkup('Failed to modify %path. Verify the file permissions.', ['%path' => $this->siteDirectory . '/settings.php']); parent::setUp(); } @@ -111,21 +101,8 @@ protected function setUpSite() { * Verifies that installation did not succeed. */ public function testBrokenInstaller() { - $this->assertRaw(Html::escape($this->exceptionMessage)); - // The exceptions are expected. Do not interpret them as a test failure. - // Not using File API; a potential error must trigger a PHP warning. - unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); - } - - /** - * {@inheritdoc} - */ - protected function error($message = '', $group = 'Other', array $caller = NULL) { - if ($group == 'Exception' && $message == $this->exceptionMessage) { - // Ignore the expected exception. - return FALSE; - } - return parent::error($message, $group, $caller); + $this->assertTitle('Install profile mismatch | Drupal'); + $this->assertText("The selected profile testing does not match the install_profile setting, which is minimal. Cannot write updated setting to {$this->siteDirectory}/settings.php."); } }