From 51bf3e2d8678700a6a1a6c8c2075dec8e0c89a73 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 6 Feb 2020 20:31:05 +0000
Subject: [PATCH] Issue #2831065 by andypost, alexpott, mpdonadio, longwave,
 Berdir: Remove BC layer from \Drupal\Core\DrupalKernel::getInstallProfile()

---
 core/lib/Drupal/Core/DrupalKernel.php         |  13 +-
 core/lib/Drupal/Core/Site/Settings.php        |   3 -
 core/modules/system/system.install            |   4 +-
 ...istributionProfileExistingSettingsTest.php |   2 -
 ...ingSettingsReadOnlyMismatchProfileTest.php | 113 ------------------
 .../Update/UpdatePathTestBase.php             |  12 --
 .../ThemeEngineExtensionListTest.php          |   5 -
 .../Core/Extension/ThemeExtensionListTest.php |   5 -
 8 files changed, 4 insertions(+), 153 deletions(-)
 delete mode 100644 core/tests/Drupal/FunctionalTests/Installer/InstallerExistingSettingsReadOnlyMismatchProfileTest.php

diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index bc85ccd04c3d..ab00d3f9f784 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -491,7 +491,7 @@ public function boot() {
         // Continue if the PharStreamWrapperManager is already initialized. For
         // example, this occurs during a module install.
         // @see \Drupal\Core\Extension\ModuleInstaller::install()
-      };
+      }
       stream_wrapper_unregister('phar');
       stream_wrapper_register('phar', PharStreamWrapper::class);
     }
@@ -1602,18 +1602,9 @@ protected function addServiceFiles(array $service_yamls) {
    */
   protected function getInstallProfile() {
     $config = $this->getConfigStorage()->read('core.extension');
-    if (isset($config['profile'])) {
-      $install_profile = $config['profile'];
-    }
-    // @todo https://www.drupal.org/node/2831065 remove the BC layer.
-    else {
-      // If system_update_8300() has not yet run fallback to using settings.
-      $settings = Settings::getAll();
-      $install_profile = isset($settings['install_profile']) ? $settings['install_profile'] : NULL;
-    }
 
     // Normalize an empty string to a NULL value.
-    return empty($install_profile) ? NULL : $install_profile;
+    return $config['profile'] ?? NULL;
   }
 
 }
diff --git a/core/lib/Drupal/Core/Site/Settings.php b/core/lib/Drupal/Core/Site/Settings.php
index e6b3cfa33c60..762462464b31 100644
--- a/core/lib/Drupal/Core/Site/Settings.php
+++ b/core/lib/Drupal/Core/Site/Settings.php
@@ -84,9 +84,6 @@ public function __sleep() {
    *   The value of the setting, the provided default if not set.
    */
   public static function get($name, $default = NULL) {
-    if ($name === 'install_profile' && isset(self::$instance->storage[$name])) {
-      @trigger_error('To access the install profile in Drupal 8 use \Drupal::installProfile() or inject the install_profile container parameter into your service. See https://www.drupal.org/node/2538996', E_USER_DEPRECATED);
-    }
     return isset(self::$instance->storage[$name]) ? self::$instance->storage[$name] : $default;
   }
 
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index e6ee8bdd0ac1..61ec3aed1b39 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -1021,8 +1021,8 @@ function system_requirements($phase) {
       // hosting provider.
       $requirements['install_profile_in_settings'] = [
         'title' => t('Install profile in settings'),
-        'value' => t("Drupal 8 no longer uses the \$settings['install_profile'] value in settings.php and it can be removed."),
-        'severity' => REQUIREMENT_INFO,
+        'value' => t("Drupal 9 no longer uses the \$settings['install_profile'] value in settings.php and it should be removed."),
+        'severity' => REQUIREMENT_WARNING,
       ];
     }
   }
diff --git a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php
index d5194bdec11e..4b3c13af5879 100644
--- a/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php
+++ b/core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php
@@ -5,7 +5,6 @@
 use Drupal\Component\Serialization\Yaml;
 use Drupal\Core\Database\Database;
 use Drupal\Core\DrupalKernel;
-use Drupal\Core\Site\Settings;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
@@ -122,7 +121,6 @@ public function testInstalled() {
 
     // Confirm that Drupal recognizes this distribution as the current profile.
     $this->assertEqual(\Drupal::installProfile(), 'mydistro');
-    $this->assertArrayNotHasKey('install_profile', Settings::getAll(), 'The install profile has not been written to settings.php.');
     $this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.');
 
     $this->rebuildContainer();
diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerExistingSettingsReadOnlyMismatchProfileTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerExistingSettingsReadOnlyMismatchProfileTest.php
deleted file mode 100644
index 86ac0a5956f8..000000000000
--- a/core/tests/Drupal/FunctionalTests/Installer/InstallerExistingSettingsReadOnlyMismatchProfileTest.php
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-
-namespace Drupal\FunctionalTests\Installer;
-
-use Drupal\Core\DrupalKernel;
-use Drupal\Core\Database\Database;
-use Drupal\Core\Site\Settings;
-use Symfony\Component\HttpFoundation\Request;
-
-/**
- * Tests installer breaks with a profile mismatch and a read-only settings.php.
- *
- * @group Installer
- * @group legacy
- */
-class InstallerExistingSettingsReadOnlyMismatchProfileTest extends InstallerTestBase {
-
-  /**
-   * {@inheritdoc}
-   */
-  protected $defaultTheme = 'stark';
-
-  /**
-   * {@inheritdoc}
-   *
-   * Configures a preexisting settings.php file without an install_profile
-   * setting before invoking the interactive installer.
-   */
-  protected function prepareEnvironment() {
-    parent::prepareEnvironment();
-    // Pre-configure hash salt.
-    // Any string is valid, so simply use the class name of this test.
-    $this->settings['settings']['hash_salt'] = (object) [
-      '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) [
-      'value' => $connection_info,
-      'required' => TRUE,
-    ];
-
-    // During interactive install we'll change this to a different profile and
-    // this test will ensure that the new value is written to settings.php.
-    $this->settings['settings']['install_profile'] = (object) [
-      'value' => 'minimal',
-      'required' => TRUE,
-    ];
-
-    // Pre-configure config directories.
-    $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
-    $this->settings['settings']['config_sync_directory'] = (object) [
-      'value' => $site_path . '/files/config_staging',
-      'required' => TRUE,
-    ];
-    mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function visitInstaller() {
-    // Make settings file not writable. This will break the installer.
-    $filename = $this->siteDirectory . '/settings.php';
-    // Make the settings file read-only.
-    // Not using File API; a potential error must trigger a PHP warning.
-    chmod($filename, 0444);
-
-    $this->drupalGet($GLOBALS['base_url'] . '/core/install.php?langcode=en&profile=testing');
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function setUpLanguage() {
-    // This step is skipped, because there is a lagcode as a query param.
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function setUpProfile() {
-    // This step is skipped, because there is a profile as a query param.
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function setUpSettings() {
-    // This step should not appear, since settings.php is fully configured
-    // already.
-  }
-
-  /**
-   * Verifies that installation succeeded.
-   *
-   * @expectedDeprecation To access the install profile in Drupal 8 use \Drupal::installProfile() or inject the install_profile container parameter into your service. See https://www.drupal.org/node/2538996
-   */
-  public function testInstalled() {
-    $this->initBrowserOutputFile();
-    $this->htmlOutput(NULL);
-    $this->assertEquals('testing', \Drupal::installProfile());
-    $this->assertEquals('minimal', Settings::get('install_profile'));
-    $this->drupalGet('admin/reports/status');
-    $this->assertSession()->pageTextContains("Drupal 8 no longer uses the \$settings['install_profile'] value in settings.php and it can be removed.");
-  }
-
-}
diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php
index 98ba5be9c53d..6fa592066bdd 100644
--- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php
+++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php
@@ -66,13 +66,6 @@ abstract class UpdatePathTestBase extends BrowserTestBase {
    */
   protected $databaseDumpFiles = [];
 
-  /**
-   * The install profile used in the database dump file.
-   *
-   * @var string
-   */
-  protected $installProfile = 'standard';
-
   /**
    * Flag that indicates whether the child site has been updated.
    *
@@ -250,11 +243,6 @@ abstract protected function setDatabaseDumpFiles();
   protected function prepareSettings() {
     parent::prepareSettings();
 
-    // Remember the profile which was used.
-    $settings['settings']['install_profile'] = (object) [
-      'value' => $this->installProfile,
-      'required' => TRUE,
-    ];
     // Generate a hash salt.
     $settings['settings']['hash_salt'] = (object) [
       'value'    => Crypt::randomBytesBase64(55),
diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ThemeEngineExtensionListTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ThemeEngineExtensionListTest.php
index 3f59ff0e976a..1a3ce0365cac 100644
--- a/core/tests/Drupal/KernelTests/Core/Extension/ThemeEngineExtensionListTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Extension/ThemeEngineExtensionListTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\KernelTests\Core\Extension;
 
-use Drupal\Core\Site\Settings;
 use Drupal\KernelTests\KernelTestBase;
 
 /**
@@ -15,10 +14,6 @@ class ThemeEngineExtensionListTest extends KernelTestBase {
    * @covers ::getList
    */
   public function testGetlist() {
-    $settings = Settings::getAll();
-    $settings['install_profile'] = 'testing';
-    new Settings($settings);
-
     // Confirm that all theme engines are available.
     $theme_engines = \Drupal::service('extension.list.theme_engine')->getList();
     $this->assertArrayHasKey('twig', $theme_engines);
diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ThemeExtensionListTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ThemeExtensionListTest.php
index 09829839229e..9b80e5a1efc2 100644
--- a/core/tests/Drupal/KernelTests/Core/Extension/ThemeExtensionListTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Extension/ThemeExtensionListTest.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\KernelTests\Core\Extension;
 
-use Drupal\Core\Site\Settings;
 use Drupal\KernelTests\KernelTestBase;
 
 /**
@@ -15,10 +14,6 @@ class ThemeExtensionListTest extends KernelTestBase {
    * @covers ::getList
    */
   public function testGetlist() {
-    $settings = Settings::getAll();
-    $settings['install_profile'] = 'testing';
-    new Settings($settings);
-
     \Drupal::configFactory()->getEditable('core.extension')
       ->set('module.testing', 1000)
       ->set('theme.test_theme', 0)
-- 
GitLab