diff --git a/core/includes/update.inc b/core/includes/update.inc index 508e01b..93d0b64 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -640,8 +640,15 @@ function update_fix_d8_requirements() { /** * Installs a new module in Drupal 8 via hook_update_N(). + * + * @param array $modules + * List of modules to enable. Dependencies are not checked and must be + * ensured by the caller. + * @param bool $update_schema_version + * (optional) The schema version the module should be set to. Defaults to 0 + * which works well for completely new modules. */ -function update_module_enable(array $modules) { +function update_module_enable(array $modules, $schema_version = 0) { $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); foreach ($modules as $module) { // Check for initial schema and install it. The schema version of a newly @@ -666,9 +673,14 @@ function update_module_enable(array $modules) { config('system.module.disabled') ->clear($module) ->save(); - // Change the schema version from SCHEMA_UNINSTALLED to 0, so any module - // updates since the module's inception are executed in a core upgrade. - $schema_store->set($module, 0); + + // Set the schema version if the module was not just disabled before. + if ($schema_store->get($module) === NULL || $schema_store->get($module) === SCHEMA_UNINSTALLED) { + // Change the schema version to the given value (defaults to 0), so any + // module updates since the module's inception are executed in a core + // upgrade. + $schema_store->set($module, $schema_version); + } // system_list_reset() is in module.inc but that would only be available // once the variable bootstrap is done. diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php index 499acf2..f6784b9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BareMinimalUpgradePathTest.php @@ -87,6 +87,9 @@ public function testBasicMinimalUpgrade() { return !empty($data->info['required']); }); $this->assertEqual(array_diff_key($required, $enabled), array()); + + // Verify that image.module was correctly installed. + $this->assertEqual('thumbnail', config('image.style.thumbnail')->get('name')); } } diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 9a0b663..7ce49a8 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -658,7 +658,19 @@ function user_update_8011() { // User pictures can only be migrated to the new user picture image field // if Image module is installed. if (!module_exists('image')) { - module_enable(array('image')); + // Install image.module with schema version 8002 as a previous version + // would have to create tables that would be removed again. + update_module_enable(array('image'), 8002); + $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + if ($schema_store->get('image') == 8002) { + // If the schema version is now 8002 then it was not installed before, + // install default config and run the install hook. + config_install_default_config('module', 'image'); + module_load_install('install'); + image_install(); + } + + // } if ($default_image = update_variable_get('user_picture_default', '')) {