### Eclipse Workspace Patch 1.0
#P Test Drupal 6
Index: includes/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.inc,v
retrieving revision 1.49
diff -u -r1.49 install.inc
--- includes/install.inc	11 Nov 2007 16:14:45 -0000	1.49
+++ includes/install.inc	29 Nov 2007 03:17:29 -0000
@@ -294,19 +294,34 @@
 }
 
 /**
- * Install a profile (i.e. a set of modules) from scratch.
- * The profile must be verified first using drupal_verify_profile().
+ * Calls the install function and updates the system table for a given list of
+ * modules.
  *
- * @param profile
- *   The name of the profile to install.
  * @param module_list
- *   An array of modules to install.
+ *   The modules to install.
+ */
+function drupal_install_modules($module_list = array()) {
+  array_filter($module_list, '_drupal_install_module');
+  module_enable($module_list);
+}
+
+/**
+ * TODO
  */
-function drupal_install_profile($profile, $module_list) {
-  // The system module is a special case; we can't bootstrap until it's
-  // installed, so we can't use the normal installation function.
-  $module_list = array_diff($module_list, array('system'));
+function _drupal_install_module($module) {
+  if (drupal_get_installed_schema_version($module, TRUE) == SCHEMA_UNINSTALLED) {
+    module_load_install($module);
+    module_invoke($module, 'install');
+    $versions = drupal_get_schema_versions($module);
+    drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
+    return TRUE;
+  }
+}
 
+/**
+ * TODO
+ */
+function drupal_install_system() {
   $system_path = dirname(drupal_get_filename('module', 'system', NULL));
   require_once './'. $system_path .'/system.install';
   module_invoke('system', 'install');
@@ -315,34 +330,9 @@
   db_query("INSERT INTO {system} (filename, name, type, owner, status, throttle, bootstrap, schema_version) VALUES('%s', '%s', '%s', '%s', %d, %d, %d, %d)", $system_path .'/system.module', 'system', 'module', '', 1, 0, 0, $system_version);
   // Now that we've installed things properly, bootstrap the full Drupal environment
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-
-  // Install schemas for profile and all its modules.
   module_rebuild_cache();
-  drupal_install_modules($module_list);
 }
 
-/**
- * Calls the install function and updates the system table for a given list of
- * modules.
- *
- * @param module_list
- *   The modules to install.
- */
-function drupal_install_modules($module_list = array()) {
-  $enable_modules = array();
-
-  foreach ($module_list as $module) {
-    if (drupal_get_installed_schema_version($module, TRUE) == SCHEMA_UNINSTALLED) {
-      module_load_install($module);
-      module_invoke($module, 'install');
-      $versions = drupal_get_schema_versions($module);
-      drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
-      $enable_modules[] = $module;
-    }
-  }
-
-  module_enable($enable_modules);
-}
 
 /**
  * Calls the uninstall function and updates the system table for a given module.
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.111
diff -u -r1.111 module.inc
--- includes/module.inc	4 Sep 2007 21:10:45 -0000	1.111
+++ includes/module.inc	29 Nov 2007 03:17:31 -0000
@@ -261,7 +261,10 @@
   foreach ($invoke_modules as $module) {
     module_invoke($module, 'enable');
     // Check if node_access table needs rebuilding.
-    if (!node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
+    // We check for the existence of node_access_needs_rebuild() since
+    // at install time, module_enable() could be called while node.module
+    // is not enabled yet.
+    if (function_exists('node_access_needs_rebuild') && !node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
       node_access_needs_rebuild(TRUE);
     }
   }
Index: install.php
===================================================================
RCS file: /cvs/drupal/drupal/install.php,v
retrieving revision 1.97
diff -u -r1.97 install.php
--- install.php	26 Nov 2007 16:36:42 -0000	1.97
+++ install.php	29 Nov 2007 03:17:27 -0000
@@ -115,8 +115,15 @@
       install_change_settings($profile, $install_locale);
     }
 
-    // Perform actual installation defined in the profile.
-    drupal_install_profile($profile, $modules);
+    // Install system.module.
+    drupal_install_system();
+    // Save the list of other modules to install for the 'profile-install'
+    // task. variable_set() can be used now that system.module is installed
+    // and drupal is bootstrapped.
+    variable_set('install_profile_modules', array_diff($modules, array('system')));
+
+    // TODO : what about these messages ?
+    // Are they OK before modules install ?
 
     // Warn about settings.php permissions risk
     $settings_dir = './'. conf_path();
@@ -627,13 +634,44 @@
   // Build a page for final tasks.
   drupal_maintenance_theme();
   if (empty($task)) {
-    variable_set('install_task', 'locale-initial-import');
-    $task = 'locale-initial-import';
+    variable_set('install_task', 'profile-install');
+    $task = 'profile-install';
   }
 
   // We are using a list of if constructs here to allow for
   // passing from one task to the other in the same request.
 
+  // Install profile modules.
+  if ($task == 'profile-install') {
+    $modules = variable_get('install_profile_modules', array());
+    $files = module_rebuild_cache();
+    variable_del('install_profile_modules');
+    $operations = array();
+    foreach ($modules as $module) {
+      $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name']));
+    }
+    $batch = array(
+      'operations' => $operations,
+      'finished' => '_install_profile_batch_finished',
+      'title' => t('Installing @drupal', array('@drupal' => drupal_install_profile_name())),
+      'error_message' => t('The installation has encountered an error.'),
+    );
+    // TODO : merge locale-initial-import here ?
+    // Start a batch, switch to 'profile-install-batch' task. We need to
+    // set the variable here, because batch_process() redirects.
+    variable_set('install_task', 'profile-install-batch');
+    batch_set($batch);
+    batch_process($url, $url);
+  }
+  // We are running a batch install of the profile's modules.
+  // This might run in multiple HTTP requests, constantly redirecting
+  // to the same address, until the batch finished callback is invoked
+  // and the task advances to 'locale-initial-import'.
+  if ($task == 'profile-install-batch') {
+    include_once 'includes/batch.inc';
+    $output = _batch_page();
+  }
+
   // Import interface translations for the enabled modules.
   if ($task == 'locale-initial-import') {
     if (!empty($install_locale) && ($install_locale != 'en')) {
@@ -655,11 +693,6 @@
     // Found nothing to import or not foreign language, go to next task.
     $task = 'configure';
   }
-
-  // We are running a batch import of interface translation files.
-  // This might run in multiple HTTP requests, constantly redirecting
-  // to the same address, until the batch finished callback is invoked
-  // and the task advances to 'configure'.
   if ($task == 'locale-initial-batch') {
     include_once 'includes/batch.inc';
     include_once 'includes/locale.inc';
@@ -781,6 +814,29 @@
 }
 
 /**
+ * Batch callback for batch installation of modules.
+ */
+function _install_module_batch($module, $module_name, &$context) {
+  _drupal_install_module($module);
+  // We enable the installed 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
+  // steps.
+  module_enable(array($module));
+  $context['results'][] = $module;
+  $context['message'] = 'Installed '. $module_name. ' module.';
+}
+
+/**
+ * Finished callback for the modules install batch.
+ *
+ * Advance installer task to language import.
+ */
+function _install_profile_batch_finished($success, $results) {
+    variable_set('install_task', 'locale-initial-import');
+}
+
+/**
  * Finished callback for the first locale import batch.
  *
  * Advance installer task to the configure screen.
@@ -802,7 +858,7 @@
  * The list of reserved tasks to run in the installer.
  */
 function install_reserved_tasks() {
-  return array('configure', 'locale-initial-import', 'locale-initial-batch', 'profile-finished', 'locale-remaining-batch', 'finished', 'done');
+  return array('configure', 'profile-install', 'profile-install-batch', 'locale-initial-import', 'locale-initial-batch', 'profile-finished', 'locale-remaining-batch', 'finished', 'done');
 }
 
 /**
@@ -858,21 +914,25 @@
 function install_task_list($active = NULL) {
   // Default list of tasks.
   $tasks = array(
-    'profile-select'       => st('Choose profile'),
-    'locale-select'        => st('Choose language'),
-    'requirements'         => st('Verify requirements'),
-    'database'             => st('Set up database'),
-    'locale-initial-batch' => st('Set up translations'),
-    'configure'            => st('Configure site'),
+    'profile-select'        => st('Choose profile'),
+    'locale-select'         => st('Choose language'),
+    'requirements'          => st('Verify requirements'),
+    'database'              => st('Set up database'),
+    'profile-install-batch' => st('Install profile'),
+    'locale-initial-batch'  => st('Set up translations'),
+    'configure'             => st('Configure site'),
   );
+//  return array('locale-initial-import', 'profile-finished');
 
   $profiles = install_find_profiles();
   $profile = isset($_GET['profile']) && isset($profiles[$_GET['profile']]) ? $_GET['profile'] : '.';
   $locales = install_find_locales($profile);
 
-  // Remove select profile if we have only one.
   if (count($profiles) == 1) {
+    // If we have only one profile, remove 'Choose profile'
+    // and rename 'Install profile'.
     unset($tasks['profile-select']);
+    $tasks['profile-install-batch'] = st('Install site');
   }
 
   // Add tasks defined by the profile.
Index: profiles/default/default.profile
===================================================================
RCS file: /cvs/drupal/drupal/profiles/default/default.profile,v
retrieving revision 1.20
diff -u -r1.20 default.profile
--- profiles/default/default.profile	19 Nov 2007 13:56:14 -0000	1.20
+++ profiles/default/default.profile	29 Nov 2007 03:17:31 -0000
@@ -42,9 +42,10 @@
  * Perform any final installation tasks for this profile.
  *
  * The installer goes through the profile-select -> locale-select
- * -> requirements -> database -> locale-initial-batch -> configure
- * -> locale-remaining-batch -> finished -> done tasks in this order,
- * if you don't implement this function in your profile.
+ * -> requirements -> database -> profile-install-batch
+ * -> locale-initial-batch -> configure -> locale-remaining-batch
+ * -> finished -> done tasks, in this order, if you don't implement
+ * this function in your profile.
  *
  * If this function is implemented, you can have any number of
  * custom tasks to perform after 'configure', implementing a state
