diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index e604c3c..7e1e726 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1594,33 +1594,14 @@ function install_profile_modules(&$install_state) { $files = system_rebuild_module_data(); \Drupal::state()->delete('install_profile_modules'); - // Always install required modules first. Respect the dependencies between - // the modules. - $required = array(); - $non_required = array(); - - // Add modules that other modules depend on. - foreach ($modules as $module) { - if ($files[$module]->requires) { - $modules = array_merge($modules, array_keys($files[$module]->requires)); - } + $install = array(); + foreach($modules as $module) { + $install[$module] = $files[$module]->info['name']; } - $modules = array_unique($modules); - foreach ($modules as $module) { - if (!empty($files[$module]->info['required'])) { - $required[$module] = $files[$module]->sort; - } - else { - $non_required[$module] = $files[$module]->sort; - } - } - arsort($required); - arsort($non_required); - $operations = array(); - foreach ($required + $non_required as $module => $weight) { - $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name'])); - } + // Install the given modules. + $operations[] = array('_prepare_install_module_batch', array($install)); + $batch = array( 'operations' => $operations, 'title' => t('Installing @drupal', array('@drupal' => drupal_install_profile_distribution_name())), diff --git a/core/includes/install.inc b/core/includes/install.inc index 3e76648..a7cf979 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -1108,7 +1108,62 @@ function db_installer_object($driver) { /** * Batch callback for batch installation of modules. */ +function _prepare_install_module_batch($modules, &$context) { + $files = system_rebuild_module_data(); + + $install = array_keys($modules); + // Add modules that other modules depend on. + foreach (array_keys($modules) as $module) { + if ($files[$module]->requires) { + $install = array_merge($install, array_keys($files[$module]->requires)); + } + } + $install = array_unique($install); + + // Always install required modules first. Respect the dependencies between + // the modules. + $required = array(); + $non_required = array(); + foreach ($install as $module) { + if (!empty($files[$module]->info['required'])) { + $required[$module] = $files[$module]->sort; + } + else { + $non_required[$module] = $files[$module]->sort; + } + } + arsort($required); + arsort($non_required); + + $currently_installed = \Drupal::moduleHandler()->getModuleList(); + + // Prepare the batch operations. + $operations = array(); + foreach ($required + $non_required as $module => $weight) { + if (!array_key_exists($module, $currently_installed)) { + $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name'])); + } + } + + // Prevent starting a batch with no operation. + if (count($operations)) { + // Set the batch. + $batch = array( + 'operations' => $operations, + 'title' => t('Installing modules.'), + 'error_message' => t('The installation has encountered an error.'), + 'file' => 'core/includes/install.inc', + ); + + batch_set($batch); + } +} + +/** + * Batch callback for batch installation of modules. + */ function _install_module_batch($module, $module_name, &$context) { + $before = \Drupal::moduleHandler()->getModuleList(); // Install and enable the module right away, so that the module will be // loaded by drupal_bootstrap in subsequent batch requests, and other // modules possibly depending on it can safely perform their installation @@ -1139,16 +1194,29 @@ function _install_module_batch($module, $module_name, &$context) { } $context['results'][] = $module; - $context['message'] = t('Installed %module module.', array('%module' => $module_name)); + if ($before != \Drupal::moduleHandler()->getModuleList()) { + $context['message'] = t('Installed %module module.', array('%module' => $module_name)); + } + else{ + $context['message'] = t('An error occurred while trying to install %module module.', array('%module', $module_name)); + } } /** * Batch callback for batch uninstallation of modules. */ function _uninstall_module_batch($module, $module_name, &$context) { + $before = \Drupal::moduleHandler()->getModuleList(); + \Drupal::service('module_installer')->uninstall(array($module), FALSE); + $context['results'][] = $module; - $context['message'] = t('Uninstalled %module module.', array('%module' => $module_name)); + if ($before != \Drupal::moduleHandler()->getModuleList()) { + $context['message'] = t('Uninstalled %module module.', array('%module' => $module_name)); + } + else{ + $context['message'] = t('An error occurred while trying to uninstall %module module.', array('%module', $module_name)); + } } /** @@ -1158,7 +1226,7 @@ function _install_modules_batch_finished($success, $results, $operations) { if ($success && !count($operations)) { drupal_flush_all_caches(); - drupal_set_message(t('The selected modules have been installed.')); + drupal_set_message(t('The configuration options have been saved.')); } else if(!$success) { drupal_set_message(t('An error occurred while trying to install the selected modules.')); diff --git a/core/modules/system/src/Form/ModulesListConfirmForm.php b/core/modules/system/src/Form/ModulesListConfirmForm.php index 1dec420..8ddfd2d 100644 --- a/core/modules/system/src/Form/ModulesListConfirmForm.php +++ b/core/modules/system/src/Form/ModulesListConfirmForm.php @@ -150,28 +150,20 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // Install the given modules. if (!empty($this->modules['install'])) { - // Prepare the batch operations. - $operations = array(); - foreach ($this->modules['install'] as $machine_name => $module) { - // We don't have to make sure dependencies are installed because they - // are first in the list. - $operations[] = array('_install_module_batch', array($machine_name, $module)); - } - // Prevent starting a batch with no operation. - if (count($operations)) { - // Set the batch. - $batch = array( - 'operations' => $operations, - 'title' => t('Installing modules.'), - 'error_message' => t('The installation has encountered an error.'), - 'finished' => '_install_modules_batch_finished', - 'file' => 'core/includes/install.inc', - ); - - // Redirect the user after removal. - $form_state->setRedirectUrl($this->getCancelUrl()); - batch_set($batch); - } + $operations[] = array('_prepare_install_module_batch', array($this->modules['install'])); + + // Set the batch. + $batch = array( + 'operations' => $operations, + 'title' => t('Preparing installation.'), + 'error_message' => t('The installation has encountered an error.'), + 'finished' => '_install_modules_batch_finished', + 'file' => 'core/includes/install.inc', + ); + + // Redirect the user after install. + $form_state->setRedirectUrl($this->getCancelUrl()); + batch_set($batch); } } diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php index 502c67c..3f77aa7 100644 --- a/core/modules/system/src/Form/ModulesListForm.php +++ b/core/modules/system/src/Form/ModulesListForm.php @@ -515,55 +515,18 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // There seem to be no dependencies that would need approval. if (!empty($modules['install'])) { - $files = system_rebuild_module_data(); - - $install = array_keys($modules['install']); - // Add modules that other modules depend on. - foreach (array_keys($modules['install']) as $module) { - if ($files[$module]->requires) { - $install = array_merge($install, array_keys($files[$module]->requires)); - } - } - $install = array_unique($install); - - // Always install required modules first. Respect the dependencies between - // the modules. - $required = array(); - $non_required = array(); - foreach ($install as $module) { - if (!empty($files[$module]->info['required'])) { - $required[$module] = $files[$module]->sort; - } - else { - $non_required[$module] = $files[$module]->sort; - } - } - arsort($required); - arsort($non_required); - - // Prepare the batch operations. - $operations = array(); - foreach ($required + $non_required as $module => $weight) { - if (!empty($modules['install'][$module])) { - $operations[] = array( - '_install_module_batch', - array($module, $modules['install'][$module]) - ); - } - } + $operations[] = array('_prepare_install_module_batch', array($modules['install'])); + + // Set the batch. + $batch = array( + 'operations' => $operations, + 'title' => t('Preparing installation.'), + 'error_message' => t('The installation has encountered an error.'), + 'finished' => '_install_modules_batch_finished', + 'file' => 'core/includes/install.inc', + ); - // Prevent starting a batch with no operation. - if (count($operations)) { - // Set the batch. - $batch = array( - 'operations' => $operations, - 'title' => t('Installing modules.'), - 'error_message' => t('The installation has encountered an error.'), - 'finished' => '_install_modules_batch_finished', - 'file' => 'core/includes/install.inc', - ); - batch_set($batch); - } + batch_set($batch); } } diff --git a/core/modules/system/src/Tests/System/MainContentFallbackTest.php b/core/modules/system/src/Tests/System/MainContentFallbackTest.php index 7a57410..56a7e85 100644 --- a/core/modules/system/src/Tests/System/MainContentFallbackTest.php +++ b/core/modules/system/src/Tests/System/MainContentFallbackTest.php @@ -71,7 +71,7 @@ function testMainContentFallback() { $edit = array(); $edit['modules[Core][block][enable]'] = 'block'; $this->drupalPostForm('admin/modules', $edit, t('Save configuration')); - $this->assertText(t('The selected modules have been installed.'), 'Modules status has been updated.'); + $this->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.'); $this->rebuildContainer(); $this->assertTrue(\Drupal::moduleHandler()->moduleExists('block'), 'Block module re-enabled.'); }