Unverified Commit 2732b8e0 authored by larowlan's avatar larowlan
Browse files

Issue #3052703 by voleger, Berdir, kim.pepper: Deprecate drupal_installation_attempted()

parent 9b41f7f8
......@@ -10,6 +10,7 @@
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Config\BootstrapConfigStorageFactory;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Test\TestDatabase;
use Drupal\Core\Session\AccountInterface;
......@@ -750,14 +751,16 @@ function drupal_maintenance_theme() {
/**
* Returns TRUE if a Drupal installation is currently being attempted.
*
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
* Use \Drupal\Core\Installer\InstallerKernel::installationAttempted()
* instead.
*
* @see https://www.drupal.org/node/3035275
*/
function drupal_installation_attempted() {
// This cannot rely on the MAINTENANCE_MODE constant, since that would prevent
// tests from using the non-interactive installer, in which case Drupal
// only happens to be installed within the same request, but subsequently
// executed code does not involve the installer at all.
// @see install_drupal()
return isset($GLOBALS['install_state']) && empty($GLOBALS['install_state']['installation_finished']);
@trigger_error('drupal_installation_attempted() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Installer\InstallerKernel::installationAttempted() instead. See https://www.drupal.org/node/3035275', E_USER_DEPRECATED);
return InstallerKernel::installationAttempted();
}
/**
......@@ -788,7 +791,7 @@ function drupal_get_profile() {
@trigger_error('drupal_get_profile() is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use the install_profile container parameter or \Drupal::installProfile() instead. If you are accessing the value before it is written to configuration during the installer use the $install_state global. If you need to access the value before container is available you can use BootstrapConfigStorageFactory to load the value directly from configuration. See https://www.drupal.org/node/2538996', E_USER_DEPRECATED);
if (drupal_installation_attempted()) {
if (InstallerKernel::installationAttempted()) {
// If the profile has been selected return it.
if (isset($install_state['parameters']['profile'])) {
$profile = $install_state['parameters']['profile'];
......
......@@ -7,6 +7,7 @@
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Render\Markup;
use Drupal\Core\Utility\Error;
......@@ -140,7 +141,7 @@ function error_displayable($error = NULL) {
* Non-recoverable fatal errors cannot be logged by Drupal.
*/
function _drupal_log_error($error, $fatal = FALSE) {
$is_installer = drupal_installation_attempted();
$is_installer = InstallerKernel::installationAttempted();
// Backtrace array is not a valid replacement value for t().
$backtrace = $error['backtrace'];
......@@ -301,7 +302,7 @@ function _drupal_get_error_level() {
// 'config.factory' service, which reads the default 'error_level' value from
// System module's default configuration and the default value is not verbose.
// @see error_displayable()
if (drupal_installation_attempted()) {
if (InstallerKernel::installationAttempted()) {
return ERROR_REPORTING_DISPLAY_VERBOSE;
}
$error_level = NULL;
......
......@@ -12,6 +12,7 @@
use Drupal\Core\Extension\Dependency;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\RedirectResponse;
......@@ -99,7 +100,7 @@ function drupal_install_profile_distribution_name() {
// During installation, the profile information is stored in the global
// installation state (it might not be saved anywhere yet).
$info = [];
if (drupal_installation_attempted()) {
if (InstallerKernel::installationAttempted()) {
global $install_state;
if (isset($install_state['profile_info'])) {
$info = $install_state['profile_info'];
......@@ -126,7 +127,7 @@ function drupal_install_profile_distribution_name() {
function drupal_install_profile_distribution_version() {
// During installation, the profile information is stored in the global
// installation state (it might not be saved anywhere yet).
if (drupal_installation_attempted()) {
if (InstallerKernel::installationAttempted()) {
global $install_state;
return isset($install_state['profile_info']['version']) ? $install_state['profile_info']['version'] : \Drupal::VERSION;
}
......
......@@ -5,6 +5,7 @@
* Theming for maintenance pages.
*/
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Site\Settings;
/**
......@@ -31,7 +32,7 @@ function _drupal_maintenance_theme() {
// Install and update pages are treated differently to prevent theming overrides.
if (defined('MAINTENANCE_MODE') && (MAINTENANCE_MODE == 'install' || MAINTENANCE_MODE == 'update')) {
if (drupal_installation_attempted()) {
if (InstallerKernel::installationAttempted()) {
$custom_theme = $GLOBALS['install_state']['theme'];
}
else {
......
......@@ -2,6 +2,7 @@
namespace Drupal\Core\Cache;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
......@@ -60,7 +61,7 @@ public function __construct(Settings $settings = NULL, $consistent_service_name
// Do not use the fast chained backend during installation. In those cases,
// we expect many cache invalidations and writes, the fast chained cache
// backend performs badly in such a scenario.
if (!drupal_installation_attempted()) {
if (!InstallerKernel::installationAttempted()) {
$this->fastServiceName = $fast_service_name;
}
}
......
......@@ -4,6 +4,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Config\Entity\ConfigDependencyManager;
use Drupal\Core\Installer\InstallerKernel;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class ConfigInstaller implements ConfigInstallerInterface {
......@@ -137,7 +138,7 @@ public function installDefaultConfig($type, $name) {
// During a drupal installation optional configuration is installed at the
// end of the installation process.
// @see install_install_profile()
if (!$this->isSyncing() && !$this->drupalInstallationAttempted()) {
if (!$this->isSyncing() && !InstallerKernel::installationAttempted()) {
$optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
if (is_dir($optional_install_path)) {
// Install any optional config the module provides.
......@@ -356,7 +357,7 @@ protected function createConfiguration($collection, array $config_to_create) {
* {@inheritdoc}
*/
public function installCollectionDefaultConfig($collection) {
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, $this->drupalInstallationAttempted(), $this->installProfile);
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, InstallerKernel::installationAttempted(), $this->installProfile);
// Only install configuration for enabled extensions.
$enabled_extensions = $this->getEnabledExtensions();
$config_to_install = array_filter($storage->listAll(), function ($config_name) use ($enabled_extensions) {
......@@ -701,9 +702,17 @@ protected function drupalGetProfile() {
*
* @return bool
* TRUE if a Drupal installation is currently being attempted.
*
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
* Use \Drupal\Core\Installer\InstallerKernel::installationAttempted()
* instead.
*
* @see https://www.drupal.org/node/3035275
* @see \Drupal\Core\Installer\InstallerKernel::installationAttempted()
*/
protected function drupalInstallationAttempted() {
return drupal_installation_attempted();
@trigger_error(__METHOD__ . '() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Installer\InstallerKernel::installationAttempted() instead. See https://www.drupal.org/node/3035275', E_USER_DEPRECATED);
return InstallerKernel::installationAttempted();
}
}
......@@ -3,6 +3,7 @@
namespace Drupal\Core\Config\Importer;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Installer\InstallerKernel;
/**
* Methods for running the ConfigImporter in a batch.
......@@ -60,7 +61,7 @@ public static function finish($success, $results, $operations) {
}
$messenger->addWarning(t('The configuration was imported with errors.'));
}
elseif (!drupal_installation_attempted()) {
elseif (!InstallerKernel::installationAttempted()) {
// Display a success message when not installing Drupal.
$messenger->addStatus(t('The configuration was imported successfully.'));
}
......
......@@ -17,6 +17,7 @@
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\File\MimeType\MimeTypeGuesser;
use Drupal\Core\Http\TrustedHostsRequestFactory;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Installer\InstallerRedirectTrait;
use Drupal\Core\Language\Language;
use Drupal\Core\Security\PharExtensionInterceptor;
......@@ -685,7 +686,7 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch =
// Redirect the user to the installation script if Drupal has not been
// installed yet (i.e., if no $databases array has been defined in the
// settings.php file) and we are not already installing.
if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') {
if (!Database::getConnectionInfo() && !InstallerKernel::installationAttempted() && PHP_SAPI !== 'cli') {
$response = new RedirectResponse($request->getBasePath() . '/core/install.php', 302, ['Cache-Control' => 'no-cache']);
}
else {
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Config\ConfigNameException;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Installer\InstallerKernel;
/**
* Config import subscriber for config import events.
......@@ -95,7 +96,7 @@ protected function validateModules(ConfigImporter $config_importer) {
// Ensure the profile is not changing.
if ($install_profile !== $core_extension['profile']) {
if (drupal_installation_attempted()) {
if (InstallerKernel::installationAttempted()) {
$config_importer->logError($this->t('The selected installation profile %install_profile does not match the profile stored in configuration %config_profile.', [
'%install_profile' => $install_profile,
'%config_profile' => $core_extension['profile'],
......
......@@ -2,6 +2,7 @@
namespace Drupal\Core\Form;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\RequestStack;
......@@ -147,9 +148,17 @@ public function redirectForm(FormStateInterface $form_state) {
* Wraps drupal_installation_attempted().
*
* @return bool
*
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0.
* Use \Drupal\Core\Installer\InstallerKernel::installationAttempted()
* instead.
*
* @see https://www.drupal.org/node/3035275
* @see \Drupal\Core\Installer\InstallerKernel::installationAttempted()
*/
protected function drupalInstallationAttempted() {
return drupal_installation_attempted();
@trigger_error(__METHOD__ . '() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Installer\InstallerKernel::installationAttempted() instead. See https://www.drupal.org/node/3035275', E_USER_DEPRECATED);
return InstallerKernel::installationAttempted();
}
/**
......
......@@ -28,7 +28,7 @@ public function register(ContainerBuilder $container) {
*/
public function loadOverrides($names) {
$overrides = [];
if (drupal_installation_attempted() && function_exists('drupal_install_profile_distribution_name')) {
if (InstallerKernel::installationAttempted() && function_exists('drupal_install_profile_distribution_name')) {
// Early in the installer the site name is unknown. In this case we need
// to fallback to the distribution's name.
$overrides['system.site'] = [
......
......@@ -66,4 +66,19 @@ public function getInstallProfile() {
return $profile;
}
/**
* Returns TRUE if a Drupal installation is currently being attempted.
*
* @return bool
* TRUE if the installation is currently being attempted.
*/
public static function installationAttempted() {
// This cannot rely on the MAINTENANCE_MODE constant, since that would
// prevent tests from using the non-interactive installer, in which case
// Drupal only happens to be installed within the same request, but
// subsequently executed code does not involve the installer at all.
// @see install_drupal()
return isset($GLOBALS['install_state']) && empty($GLOBALS['install_state']['installation_finished']);
}
}
......@@ -44,7 +44,7 @@ protected function shouldRedirectToInstaller(\Exception $exception, Connection $
}
// Never redirect if we're already in the installer.
if (drupal_installation_attempted()) {
if (InstallerKernel::installationAttempted()) {
return FALSE;
}
......
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
......@@ -19,7 +20,7 @@ function content_translation_install() {
// Skip the guidance messages about enabling translation features if the
// module was installed in the Drupal installation process.
if (drupal_installation_attempted()) {
if (InstallerKernel::installationAttempted()) {
return;
}
......
......@@ -17,6 +17,7 @@
use Drupal\Component\Utility\Xss;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Core\Asset\AttachedAssetsInterface;
......@@ -408,7 +409,7 @@ function locale_system_update(array $components) {
// Skip running the translation imports if in the installer,
// because it would break out of the installer flow. We have
// built-in support for translation imports in the installer.
if (!drupal_installation_attempted() && locale_translatable_language_list()) {
if (!InstallerKernel::installationAttempted() && locale_translatable_language_list()) {
if (\Drupal::config('locale.settings')->get('translation.import_enabled')) {
module_load_include('compare.inc', 'locale');
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Config\ConfigEvents;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\StorableConfigBase;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\language\Config\LanguageConfigOverrideCrudEvent;
use Drupal\language\Config\LanguageConfigOverrideEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -78,7 +79,7 @@ public static function getSubscribedEvents() {
public function onConfigSave(ConfigCrudEvent $event) {
// Only attempt to feed back configuration translation changes to locale if
// the update itself was not initiated by locale data changes.
if (!drupal_installation_attempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) {
if (!InstallerKernel::installationAttempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) {
$config = $event->getConfig();
$langcode = $config->get('langcode') ?: 'en';
$this->updateLocaleStorage($config, $langcode);
......@@ -94,7 +95,7 @@ public function onConfigSave(ConfigCrudEvent $event) {
public function onOverrideChange(LanguageConfigOverrideCrudEvent $event) {
// Only attempt to feed back configuration override changes to locale if
// the update itself was not initiated by locale data changes.
if (!drupal_installation_attempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) {
if (!InstallerKernel::installationAttempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) {
$translation_config = $event->getLanguageConfigOverride();
$langcode = $translation_config->getLangcode();
$reference_config = $this->configFactory->getEditable($translation_config->getName())->get();
......
<?php
namespace Drupal\KernelTests\Core\Installer;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests for installer related legacy API.
*
* @group legacy
*/
class InstallerLegacyTest extends KernelTestBase {
/**
* Tests drupal_installation_attempted().
*
* @expectedDeprecation drupal_installation_attempted() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Installer\InstallerKernel::installationAttempted() instead. See https://www.drupal.org/node/3035275
*/
public function testDrupalInstallationAttempted() {
$this->assertFalse(drupal_installation_attempted());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment