From 9defd332d4c83300b21dff14354983e7dcc59de9 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Wed, 12 Jan 2022 13:33:05 +0000 Subject: [PATCH] Issue #2010380 by alexpott, TR, tstoeckler, MerryHamster, sanjayk, andypost, chx, Pancho, daffie: Deprecate module_load_install() and replace it with ModuleHandler::loadInstall --- core/includes/install.inc | 9 +++++++-- core/includes/module.inc | 7 +++++++ core/includes/update.inc | 4 ++-- core/lib/Drupal/Core/Extension/ModuleInstaller.php | 4 ++-- .../Drupal/Core/Installer/Form/SelectProfileForm.php | 7 ++++++- .../Functional/System/SitesDirectoryHardeningTest.php | 2 +- core/modules/update/update.fetch.inc | 2 +- core/modules/update/update.module | 2 +- .../Drupal/KernelTests/Core/Entity/EntityFieldTest.php | 2 +- .../KernelTests/Core/Entity/EntityLanguageTestBase.php | 2 +- .../KernelTests/Core/Entity/EntityValidationTest.php | 2 +- .../KernelTests/Core/Extension/ModuleLegacyTest.php | 10 ++++++++++ .../Drupal/KernelTests/Core/Field/FieldAccessTest.php | 2 +- .../Core/File/FileSystemRequirementsTest.php | 2 +- 14 files changed, 42 insertions(+), 15 deletions(-) diff --git a/core/includes/install.inc b/core/includes/install.inc index 2b3232942c33..00a4a3459ed1 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -84,7 +84,7 @@ function drupal_load_updates() { foreach (\Drupal::service('update.update_hook_registry')->getAllInstalledVersions() as $module => $schema_version) { if ($extension_list_module->exists($module) && !$extension_list_module->checkIncompatibility($module)) { if ($schema_version > -1) { - module_load_install($module); + \Drupal::moduleHandler()->loadInclude($module, 'install'); } } } @@ -1033,7 +1033,12 @@ function drupal_requirements_severity(&$requirements) { * TRUE or FALSE, depending on whether the requirements are met. */ function drupal_check_module($module) { - module_load_install($module); + /** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */ + $module_list = \Drupal::service('extension.list.module'); + $file = DRUPAL_ROOT . '/' . $module_list->getPath($module) . "/$module.install"; + if (is_file($file)) { + require_once $file; + } // Check requirements $requirements = \Drupal::moduleHandler()->invoke($module, 'requirements', ['install']); if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) { diff --git a/core/includes/module.inc b/core/includes/module.inc index d718a31492be..cee6f894694a 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -15,8 +15,15 @@ * * @return * The name of the module's install file, if successful; FALSE otherwise. + * + * @deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use + * \Drupal::moduleHandler()->loadInclude($module, 'install') instead. Note, + * the replacement no longer allows including code from uninstalled modules. + * + * @see https://www.drupal.org/node/3220952 */ function module_load_install($module) { + @trigger_error('module_load_install() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Instead, you should use \Drupal::moduleHandler()->loadInclude($module, \'install\'). Note, the replacement no longer allows including code from uninstalled modules. See https://www.drupal.org/project/drupal/issues/2010380', E_USER_DEPRECATED); // Make sure the installation API is available include_once __DIR__ . '/install.inc'; diff --git a/core/includes/update.inc b/core/includes/update.inc index 7c37673f9157..2dbcd3ce3595 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -115,7 +115,7 @@ function _update_fix_missing_schema() { // don't, detect and fix the problem. if (!isset($versions[$module])) { // Ensure the .install file is loaded. - module_load_install($module); + $module_handler->loadInclude($module, 'install'); $all_updates = $update_registry->getAvailableUpdates($module); // If the schema version of a module hasn't been recorded, we cannot // know the actual schema version a module is at, because @@ -704,7 +704,7 @@ function update_retrieve_dependencies() { } $function = $module . '_update_dependencies'; // Ensure install file is loaded. - module_load_install($module); + \Drupal::moduleHandler()->loadInclude($module, 'install'); if (function_exists($function)) { $updated_dependencies = $function(); // Each implementation of hook_update_dependencies() returns a diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 8b24bcdf123c..4669bb7cc873 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -242,7 +242,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // Load the module's .module and .install files. $this->moduleHandler->load($module); - module_load_install($module); + $this->moduleHandler->loadInclude($module, 'install'); if (!InstallerKernel::installationAttempted()) { // Replace the route provider service with a version that will rebuild @@ -468,7 +468,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { $this->moduleHandler->invokeAll('module_preuninstall', [$module]); // Uninstall the module. - module_load_install($module); + $this->moduleHandler->loadInclude($module, 'install'); $this->moduleHandler->invoke($module, 'uninstall', [$sync_status]); // Remove all configuration belonging to the module. diff --git a/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php b/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php index 82b7d3c9e251..98578d10f816 100644 --- a/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SelectProfileForm.php @@ -93,7 +93,12 @@ public function buildForm(array $form, FormStateInterface $form_state, $install_ // profile's which implement hook_INSTALL() are not supported. // @todo https://www.drupal.org/project/drupal/issues/2982052 Remove // this restriction. - module_load_install($extensions['profile']); + $root = \Drupal::root(); + include_once $root . '/core/includes/install.inc'; + $file = $root . '/' . $install_state['profiles'][$extensions['profile']]->getPath() . "/{$extensions['profile']}.install"; + if (is_file($file)) { + require_once $file; + } if (!function_exists($extensions['profile'] . '_install')) { $form['profile']['#options'][static::CONFIG_INSTALL_PROFILE_KEY] = $this->t('Use existing configuration'); $form['profile'][static::CONFIG_INSTALL_PROFILE_KEY]['#description'] = [ diff --git a/core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php b/core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php index 9a4f57d7dcbb..b4de64738821 100644 --- a/core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php +++ b/core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php @@ -92,7 +92,7 @@ public function testSitesDirectoryHardeningConfig() { * An array of system requirements. */ protected function checkSystemRequirements() { - module_load_install('system'); + \Drupal::moduleHandler()->loadInclude('system', 'install'); return system_requirements('runtime'); } diff --git a/core/modules/update/update.fetch.inc b/core/modules/update/update.fetch.inc index b418d9c3ec3e..b1ab4196689a 100644 --- a/core/modules/update/update.fetch.inc +++ b/core/modules/update/update.fetch.inc @@ -18,7 +18,7 @@ */ function _update_cron_notify() { $update_config = \Drupal::config('update.settings'); - module_load_install('update'); + \Drupal::moduleHandler()->loadInclude('update', 'install'); $status = update_requirements('runtime'); $params = []; $notify_all = ($update_config->get('notification.threshold') == 'all'); diff --git a/core/modules/update/update.module b/core/modules/update/update.module index 7a1a927ab7c3..4eb82ebb672d 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -92,7 +92,7 @@ function update_page_top() { break; } - module_load_install('update'); + \Drupal::moduleHandler()->loadInclude('update', 'install'); $status = update_requirements('runtime'); foreach (['core', 'contrib'] as $report_type) { $type = 'update_' . $report_type; diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php index e55211d347d0..7c701f1b269a 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php @@ -64,7 +64,7 @@ protected function setUp(): void { } // Create the test field. - module_load_install('entity_test'); + $this->container->get('module_handler')->loadInclude('entity_test', 'install'); entity_test_install(); // Install required default configuration for filter module. diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php index 52b364a19328..1182e47f60fa 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php @@ -56,7 +56,7 @@ protected function setUp(): void { $this->installConfig(['language']); // Create the test field. - module_load_install('entity_test'); + $this->container->get('module_handler')->loadInclude('entity_test', 'install'); entity_test_install(); // Enable translations for the test entity type. diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php index 09298d4673f4..c4426c3c7c4f 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php @@ -52,7 +52,7 @@ protected function setUp(): void { $this->installEntitySchema('entity_test_mulrev_changed'); // Create the test field. - module_load_install('entity_test'); + $this->container->get('module_handler')->loadInclude('entity_test', 'install'); entity_test_install(); // Install required default configuration for filter module. diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleLegacyTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleLegacyTest.php index 1b281c286a72..848170099e6b 100644 --- a/core/tests/Drupal/KernelTests/Core/Extension/ModuleLegacyTest.php +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleLegacyTest.php @@ -22,4 +22,14 @@ public function testModuleLoadInclude() { } + /** + * Test deprecation of module_load_install() function. + */ + public function testModuleLoadInstall() { + $this->assertFalse(\Drupal::moduleHandler()->moduleExists('node'), 'The Node module is not installed'); + $this->expectDeprecation('module_load_install() is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Instead, you should use \Drupal::moduleHandler()->loadInclude($module, \'install\'). Note, the replacement no longer allows including code from uninstalled modules. See https://www.drupal.org/project/drupal/issues/2010380'); + $filename = module_load_install('node'); + $this->assertStringEndsWith("node.install", $filename); + } + } diff --git a/core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php b/core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php index c8f306039f0d..02b155534e68 100644 --- a/core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php +++ b/core/tests/Drupal/KernelTests/Core/Field/FieldAccessTest.php @@ -54,7 +54,7 @@ protected function setUp(): void { // The users table is needed for creating dummy user accounts. $this->installEntitySchema('user'); // Register entity_test text field. - module_load_install('entity_test'); + $this->container->get('module_handler')->loadInclude('entity_test', 'install'); entity_test_install(); } diff --git a/core/tests/Drupal/KernelTests/Core/File/FileSystemRequirementsTest.php b/core/tests/Drupal/KernelTests/Core/File/FileSystemRequirementsTest.php index 425542853243..ac8b802df365 100644 --- a/core/tests/Drupal/KernelTests/Core/File/FileSystemRequirementsTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/FileSystemRequirementsTest.php @@ -45,7 +45,7 @@ public function testSettingsExist() { * An array of system requirements. */ protected function checkSystemRequirements() { - module_load_install('system'); + $this->container->get('module_handler')->loadInclude('system', 'install'); return system_requirements('runtime'); } -- GitLab