diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 3f2232b55f9459037faf19152224985ad39ba653..33a439f8a25a6c9fc400d8027e3a984910153ec5 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -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']; diff --git a/core/includes/errors.inc b/core/includes/errors.inc index 674fbc7559a8c0b49487b79a689ed1758e79479f..8fc4f39a4c5cc32c79a537ad735a207de17a1901 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -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; diff --git a/core/includes/install.inc b/core/includes/install.inc index 9922166cb65d688c2e164e41d6cf8bc9230933cb..2834e918f535105e9f4be231ee9bef6b4b0b11c6 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -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; } diff --git a/core/includes/theme.maintenance.inc b/core/includes/theme.maintenance.inc index 2982f845421f69d6833cc91f9722f87e3cfececf..aa43f080bfff40bc16062677d0b5b445ebf4a1c0 100644 --- a/core/includes/theme.maintenance.inc +++ b/core/includes/theme.maintenance.inc @@ -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 { diff --git a/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php b/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php index 1016e5a3ec6b3e9ddb53418c8702f0cd5d3e813f..b04ee5c55cfd8d4ce5a82b49317d9b28165ac727 100644 --- a/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/ChainedFastBackendFactory.php @@ -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; } } diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index 66ebcedd5e166de9599f721b5fb27b0f6485dcd9..2d8e4d52c01230fb0ddcf7140d767ca6f888aef9 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -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(); } } diff --git a/core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php b/core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php index 8aee289e0d14b32f9409c94ce8343be171ae4d09..274e68173750859effadacfea5249c215c0430c1 100644 --- a/core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php +++ b/core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php @@ -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.')); } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index d80e87270be8892c3d154ed70e9a26f548d7e6e3..b9f7b306138f3b3a5bc2936180c196dc6dbbd2d3 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -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 { diff --git a/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php index 7f2f35c32ba418fc4eb4b8b72834cf73346c4af0..f521bb1655862f5b75c93db684f69277c72e7ec1 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php @@ -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'], diff --git a/core/lib/Drupal/Core/Form/FormSubmitter.php b/core/lib/Drupal/Core/Form/FormSubmitter.php index 4a4275ef8d0e4a79278e370e5befab87edb83a80..8591edaa2bbcf35de70155360fd3963b01282a83 100644 --- a/core/lib/Drupal/Core/Form/FormSubmitter.php +++ b/core/lib/Drupal/Core/Form/FormSubmitter.php @@ -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(); } /** diff --git a/core/lib/Drupal/Core/Installer/ConfigOverride.php b/core/lib/Drupal/Core/Installer/ConfigOverride.php index ff8d068b2fec360582815ad675a8e3457126098d..b343b23c8d8de7faf0be1e246e082b88291c6baa 100644 --- a/core/lib/Drupal/Core/Installer/ConfigOverride.php +++ b/core/lib/Drupal/Core/Installer/ConfigOverride.php @@ -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'] = [ diff --git a/core/lib/Drupal/Core/Installer/InstallerKernel.php b/core/lib/Drupal/Core/Installer/InstallerKernel.php index adeb5c53eed62b1935dcd43c079b8d10a6abbe45..501d1f27de45ec50d1910a48083a7d56f5febc97 100644 --- a/core/lib/Drupal/Core/Installer/InstallerKernel.php +++ b/core/lib/Drupal/Core/Installer/InstallerKernel.php @@ -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']); + } + } diff --git a/core/lib/Drupal/Core/Installer/InstallerRedirectTrait.php b/core/lib/Drupal/Core/Installer/InstallerRedirectTrait.php index 067802d2bbbf61257c95840328ef44db392bc78b..73001e545ab194292f263e6fc517dc320e570d02 100644 --- a/core/lib/Drupal/Core/Installer/InstallerRedirectTrait.php +++ b/core/lib/Drupal/Core/Installer/InstallerRedirectTrait.php @@ -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; } diff --git a/core/modules/content_translation/content_translation.install b/core/modules/content_translation/content_translation.install index 80488f6bdfb90d086b8e140e7869b786ddfc6638..96859faaebde510f826e4a8c2f0af31ae1b63c80 100644 --- a/core/modules/content_translation/content_translation.install +++ b/core/modules/content_translation/content_translation.install @@ -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; } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index db37cec3b5ef94f090b00fcf2e2e534f65cce31d..40cd9d2491bf107ce9c493459d3bf4cc7304dd5b 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -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'); diff --git a/core/modules/locale/src/LocaleConfigSubscriber.php b/core/modules/locale/src/LocaleConfigSubscriber.php index 7d7ff393e2f46e600bc0f869b28a27d1dc8cb0b7..289e838e05450e128841d27e5e90bf5dc35bd8b2 100644 --- a/core/modules/locale/src/LocaleConfigSubscriber.php +++ b/core/modules/locale/src/LocaleConfigSubscriber.php @@ -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(); diff --git a/core/tests/Drupal/KernelTests/Core/Installer/InstallerLegacyTest.php b/core/tests/Drupal/KernelTests/Core/Installer/InstallerLegacyTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fea14b1d1d8e1998fba08bc4222b8dc5cc922b0b --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Installer/InstallerLegacyTest.php @@ -0,0 +1,23 @@ +<?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()); + } + +}