Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.435
diff -u -r1.435 system.install
--- modules/system/system.install	8 Jan 2010 06:36:34 -0000	1.435
+++ modules/system/system.install	8 Jan 2010 09:05:31 -0000
@@ -2092,7 +2092,6 @@
  */
 function system_update_7020() {
   $module_list = array('field_sql_storage', 'field');
-  drupal_install_modules($module_list);
   module_enable($module_list);
 }
 
@@ -2315,7 +2314,6 @@
     ->condition('type', 'module')
     ->condition('name', $module_list)
     ->execute();
-  drupal_install_modules($module_list);
   module_enable($module_list);
 }
 
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.246
diff -u -r1.246 system.admin.inc
--- modules/system/system.admin.inc	4 Jan 2010 21:31:52 -0000	1.246
+++ modules/system/system.admin.inc	8 Jan 2010 09:05:30 -0000
@@ -1229,7 +1229,7 @@
       $sort[$module] = $files[$module]->sort;
     }
     array_multisort($sort, $new_modules);
-    drupal_install_modules($new_modules);
+    module_enable($new_modules);
   }
 
   $current_module_list = module_list(TRUE);
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.871
diff -u -r1.871 system.module
--- modules/system/system.module	8 Jan 2010 06:36:34 -0000	1.871
+++ modules/system/system.module	8 Jan 2010 09:05:31 -0000
@@ -2202,7 +2202,17 @@
   ksort($modules);
   system_get_files_database($modules, 'module');
   system_update_files_database($modules, 'module');
-  // Refresh bootstrap status.
+  $modules = _module_build_dependencies($modules);
+  return $modules;
+}
+
+/**
+ * Refresh bootstrap column in the system table.
+ *
+ * This column indicates which modules to load when invoking the boot and exit
+ * hooks.
+ */
+function system_update_bootstrap_status() {
   $bootstrap_modules = array();
   foreach (bootstrap_hooks() as $hook) {
     foreach (module_implements($hook) as $module) {
@@ -2218,8 +2228,6 @@
     $query->condition('name', $bootstrap_modules, 'NOT IN');
   }
   $query->execute();
-  $modules = _module_build_dependencies($modules);
-  return $modules;
 }
 
 /**
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.188
diff -u -r1.188 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	4 Jan 2010 23:08:34 -0000	1.188
+++ modules/simpletest/drupal_web_test_case.php	8 Jan 2010 09:05:30 -0000
@@ -1141,13 +1141,13 @@
     $profile_details = install_profile_info('standard', 'en');
 
     // Install the modules specified by the default profile.
-    drupal_install_modules($profile_details['dependencies'], TRUE);
+    module_enable($profile_details['dependencies'], FALSE, TRUE);
 
     drupal_static_reset('_node_types_build');
 
     if ($modules = func_get_args()) {
       // Install modules needed for this test.
-      drupal_install_modules($modules, TRUE);
+      module_enable($modules, TRUE, TRUE);
     }
 
     // Because the schema is static cached, we need to flush
@@ -1158,7 +1158,7 @@
 
     // Run default profile tasks.
     $install_state = array();
-    drupal_install_modules(array('standard'), TRUE);
+    module_enable(array('default'), FALSE, TRUE);
 
     // Rebuild caches.
     node_types_rebuild();
Index: modules/simpletest/tests/module.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/module.test,v
retrieving revision 1.18
diff -u -r1.18 module.test
--- modules/simpletest/tests/module.test	5 Jan 2010 18:00:14 -0000	1.18
+++ modules/simpletest/tests/module.test	8 Jan 2010 09:05:30 -0000
@@ -37,7 +37,7 @@
     $this->assertModuleList($module_list, t('Standard profile'));
 
     // Try to install a new module.
-    drupal_install_modules(array('contact'));
+    module_enable(array('contact'));
     $module_list[] = 'contact';
     sort($module_list);
     $this->assertModuleList($module_list, t('After adding a module'));
@@ -101,25 +101,25 @@
   }
 
   /**
-   * Test drupal_install_modules() and dependency resolution.
+   * Test dependency resolution.
    */
-  function testDrupalInstallModules() {
-    drupal_install_modules(array('module_test'));
+  function testDependencyResolution() {
+    module_enable(array('module_test'));
     $this->assertTrue(module_exists('module_test'), t('Test module is enabled.'));
 
     // First, create a fake missing dependency. Forum depends on poll, which
     // depends on a made-up module, foo. Nothing should be installed.
     variable_set('dependency_test', 'missing dependency');
-    $result = drupal_install_modules(array('forum'));
-    $this->assertFalse($result, t('drupal_install_modules() returns FALSE if dependencies are missing.'));
-    $this->assertFalse(module_exists('forum'), t('drupal_install_modules() aborts if dependencies are missing.'));
+    $result = module_enable(array('forum'), TRUE, TRUE);
+    $this->assertFalse($result, t('module_enable() returns FALSE if dependencies are missing.'));
+    $this->assertFalse(module_exists('forum'), t('module_enable() aborts if dependencies are missing.'));
 
-    // Now, fix the missing dependency. drupal_install_modules() should work.
+    // Now, fix the missing dependency. module_enable() should work.
     variable_set('dependency_test', 'dependency');
-    $result = drupal_install_modules(array('forum'));
-    $this->assertTrue($result, t('drupal_install_modules() returns the correct value.'));
+    $result = module_enable(array('forum'), TRUE, TRUE);
+    $this->assertTrue($result, t('module_enable() returns the correct value.'));
     // Verify that the fake dependency chain was installed.
-    $this->assertTrue(module_exists('poll') && module_exists('php'), t('Dependency chain was installed by drupal_install_modules().'));
+    $this->assertTrue(module_exists('poll') && module_exists('php'), t('Dependency chain was installed by module_enable().'));
     // Finally, verify that the original module was installed.
     $this->assertTrue(module_exists('forum'), t('Module installation with unlisted dependencies succeeded.'));
   }
Index: includes/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.inc,v
retrieving revision 1.121
diff -u -r1.121 install.inc
--- includes/install.inc	4 Jan 2010 21:31:52 -0000	1.121
+++ includes/install.inc	8 Jan 2010 09:05:29 -0000
@@ -531,49 +531,10 @@
 }
 
 /**
- * Calls the install function for a given list of modules.
- *
- * @param $module_list
- *   The modules to install.
- * @param $disable_modules_installed_hook
- *   Normally just testing wants to set this to TRUE.
- * 
- * @return
- *   TRUE if installation was attempted, FALSE if one or more dependencies are
- *   missing.
+ * Deprecated. Use module_enable() instead.
  */
 function drupal_install_modules($module_list = array(), $disable_modules_installed_hook = FALSE) {
-  $files = system_rebuild_module_data();
-  $module_list = array_flip(array_values($module_list));
-  do {
-    $moved = FALSE;
-    foreach ($module_list as $module => $weight) {
-      $file = $files[$module];
-      if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) {
-        foreach ($file->info['dependencies'] as $dependency) {
-          if (!isset($module_list[$dependency])) {
-            if (!isset($files[$dependency])) {
-              // A dependency was not found, abort installation.
-              return FALSE;
-            }
-            elseif (!$files[$dependency]->status) {
-              // Add dependencies to $module_list and install them first.
-              $module_list[$dependency] = $weight - 1;
-              $moved = TRUE;
-            }
-          }
-          elseif ($module_list[$module] < $module_list[$dependency] +1) {
-            $module_list[$module] = $module_list[$dependency] +1;
-            $moved = TRUE;
-          }
-        }
-      }
-    }
-  } while ($moved);
-  asort($module_list);
-  $module_list = array_keys($module_list);
-  module_enable($module_list, $disable_modules_installed_hook);
-  return TRUE;
+  return module_enable($module_list, TRUE, $disable_modules_installed_hook);
 }
 
 /**
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.178
diff -u -r1.178 module.inc
--- includes/module.inc	7 Jan 2010 04:54:18 -0000	1.178
+++ includes/module.inc	8 Jan 2010 09:05:29 -0000
@@ -287,10 +287,50 @@
  *
  * @param $module_list
  *   An array of module names.
+ * @param $check_dependencies
+ *   If TRUE, $module_list will be processed for dependencies.
  * @param $disable_modules_installed_hook
  *   Normally just testing wants to set this to TRUE.
+ * @return
+ *   FALSE if one or more dependencies are missing, TRUE otherwise.
  */
-function module_enable($module_list, $disable_modules_installed_hook = FALSE) {
+function module_enable($module_list, $check_dependencies = FALSE, $disable_modules_installed_hook = FALSE) {
+  if ($check_dependencies) {
+    // Get all module data so we can find dependencies and sort.
+    $module_data = system_rebuild_module_data();
+    // Create an associative array with weights as values.
+    $module_list = array_flip(array_values($module_list));
+
+    while (list($module) = each($module_list)) {
+      if (!isset($module_data[$module])) {
+        // This module is not found in the filesystem, abort.
+        return FALSE;
+      }
+      if ($module_data[$module]->status) {
+        // Skip already enabled modules.
+        unset($module_list[$module]);
+        continue;
+      }
+      $module_list[$module] = $module_data[$module]->sort;
+
+      // Add dependencies to the module list.
+      foreach ($module_data[$module]->info['dependencies'] as $dependency) {
+        if (!isset($module_list[$dependency])) {
+          $module_list[$dependency] = 0;
+        }
+      }
+    }
+
+    if (!$module_list) {
+      // Nothing to do. All modules already enabled.
+      return TRUE;
+    }
+
+    // Sort the module list by pre-calculated weights.
+    arsort($module_list);
+    $module_list = array_keys($module_list);
+  }
+
   $invoke_modules = array();
 
   // Try to install the enabled modules and collect which were installed.
@@ -328,6 +368,7 @@
     if (!$disable_modules_installed_hook && !empty($modules_installed)) {
       module_invoke_all('modules_installed', $modules_installed);
     }
+    system_update_bootstrap_status();
   }
 
   foreach ($invoke_modules as $module) {
@@ -346,6 +387,8 @@
     // enabled.
     module_invoke_all('modules_enabled', $invoke_modules);
   }
+
+  return TRUE;
 }
 
 /**
@@ -353,9 +396,39 @@
  *
  * @param $module_list
  *   An array of module names.
+ * @param $check_dependencies
+ *   If TRUE, $module_list will be processed for dependents.
  */
-function module_disable($module_list) {
+function module_disable($module_list, $check_dependencies = FALSE) {
+  if ($check_dependencies) {
+    // Get all module data so we can find dependents and sort.
+    $module_data = system_rebuild_module_data();
+    // Create an associative array with weights as values.
+    $module_list = array_flip(array_values($module_list));
+
+    while (list($module) = each($module_list)) {
+      if (!isset($module_data[$module]) || !$module_data[$module]->status) {
+        // This module doesn't exist or is already disabled, skip it.
+        unset($module_list[$module]);
+        continue;
+      }
+      $module_list[$module] = $module_data[$module]->sort;
+
+      // Add dependent modules.
+      foreach ($module_data[$module]->required_by as $dependent => $dependent_data) {
+        if (!isset($module_list[$dependent]) && !strstr($module_data[$dependent]->filename, '.profile')) {
+          $module_list[$dependent] = 0;
+        }
+      }
+    }
+
+    // Sort the module list by pre-calculated weights.
+    asort($module_list);
+    $module_list = array_keys($module_list);
+  }
+
   $invoke_modules = array();
+
   foreach ($module_list as $module) {
     if (module_exists($module)) {
       // Check if node_access table needs rebuilding.
@@ -385,6 +458,7 @@
     module_invoke_all('modules_disabled', $invoke_modules);
     // Update the registry to remove the newly-disabled module.
     registry_update();
+    system_update_bootstrap_status();
   }
 
   // If there remains no more node_access module, rebuilding will be
Index: install.php
===================================================================
RCS file: /cvs/drupal/drupal/install.php,v
retrieving revision 1.231
diff -u -r1.231 install.php
--- install.php	4 Jan 2010 23:08:34 -0000	1.231
+++ install.php	8 Jan 2010 09:05:29 -0000
@@ -1709,7 +1709,7 @@
 
   // Enable update.module if this option was selected.
   if ($form_state['values']['update_status_module'][1]) {
-    drupal_install_modules(array('update'));
+		module_enable(array('update'));
 
     // Add the site maintenance account's email address to the list of
     // addresses to be notified when updates are available, if selected.
