summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/module.inc54
-rw-r--r--modules/system/system.install2
2 files changed, 35 insertions, 21 deletions
diff --git a/includes/module.inc b/includes/module.inc
index 2bb2ce316..96c48b788 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -89,11 +89,9 @@ function module_list($refresh = FALSE, $bootstrap = FALSE, $sort = FALSE, $fixed
*
* @param $type
* The type of list to return:
- * - module: All modules.
* - module_enabled: All enabled modules.
* - bootstrap: All enabled modules required for bootstrap.
* - theme: All themes.
- * - theme_enabled: All enabled themes.
*
* @return
* An associative array of modules or themes, keyed by name, and having the
@@ -106,13 +104,31 @@ function module_list($refresh = FALSE, $bootstrap = FALSE, $sort = FALSE, $fixed
function system_list($type) {
$lists = &drupal_static(__FUNCTION__);
- if (!isset($lists)) {
+ // For bootstrap modules, attempt to fetch the list from cache if possible.
+ // if not fetch only the required information to fire bootstrap hooks
+ // in case we are going to serve the page from cache.
+ if ($type == 'bootstrap') {
+ if ($cached = cache_get('bootstrap_modules', 'cache_bootstrap')) {
+ $bootstrap_list = $cached->data;
+ }
+ else {
+ $bootstrap_list = db_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC")->fetchAllAssoc('name');
+ cache_set('bootstrap_modules', $bootstrap_list, 'cache');
+ }
+ foreach ($bootstrap_list as $module) {
+ // Prime the drupal_get_filename() static cache to avoid subsequent
+ // queries to retrieve module filename.
+ drupal_get_filename('module', $module->name, $module->filename);
+ }
+ // We only return the module names here since module_list() doesn't need
+ // the filename itself.
+ $lists['bootstrap'] = array_keys($bootstrap_list);
+ }
+ // Otherwise build the list for enabled modules and themes.
+ elseif (!isset($lists)) {
$lists = array(
- 'bootstrap' => array(),
- 'module' => array(),
'module_enabled' => array(),
'theme' => array(),
- 'theme_enabled' => array(),
);
// The module name (rather than the filename) is used as the fallback
// weighting in order to guarantee consistent behavior across different
@@ -121,25 +137,13 @@ function system_list($type) {
// consistent with the one used in module_implements().
$result = db_query("SELECT * FROM {system} ORDER BY weight ASC, name ASC");
foreach ($result as $record) {
- // Build a list of all modules.
- if ($record->type == 'module') {
- $lists['module'][$record->name] = $record;
+ if ($record->type == 'module' && $record->status) {
// Build a list of all enabled modules.
- if ($record->status) {
- $lists['module_enabled'][$record->name] = $record->name;
- // Build a separate array of modules required for bootstrap.
- if ($record->bootstrap) {
- $lists['bootstrap'][$record->name] = $record->name;
- }
- }
+ $lists['module_enabled'][$record->name] = $record->name;
}
// Build a list of themes.
if ($record->type == 'theme') {
$lists['theme'][$record->name] = $record;
- // Build a list of enabled themes.
- if ($record->status) {
- $lists['theme_enabled'][$record->name] = $record;
- }
}
// Additionally prime drupal_get_filename() with the filename and type
@@ -155,6 +159,14 @@ function system_list($type) {
}
/**
+ * Reset all system_list() caches.
+ */
+function system_list_reset() {
+ drupal_static_reset('system_list');
+ cache_clear_all('bootstrap_modules', 'cache_bootstrap');
+}
+
+/**
* Find dependencies any level deep and fill in required by information too.
*
* @param $files
@@ -293,6 +305,7 @@ function module_enable($module_list, $disable_modules_installed_hook = FALSE) {
if (!empty($invoke_modules)) {
// Refresh the module list to exclude the disabled modules.
+ system_list_reset();
module_list(TRUE);
module_implements('', FALSE, TRUE);
// Force to regenerate the stored list of hook implementations.
@@ -353,6 +366,7 @@ function module_disable($module_list) {
if (!empty($invoke_modules)) {
// Refresh the module list to exclude the disabled modules.
+ system_list_reset();
module_list(TRUE);
module_implements('', FALSE, TRUE);
// Invoke hook_modules_disabled before disabling modules,
diff --git a/modules/system/system.install b/modules/system/system.install
index 412d116b1..1da65c102 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -1567,6 +1567,7 @@ function system_schema() {
),
'primary key' => array('filename'),
'indexes' => array(
+ 'bootstrap' => array('status', 'bootstrap', 'type', 'weight', 'name'),
'system_list' => array('weight', 'name'),
'type_name' => array('type', 'name'),
),
@@ -2183,7 +2184,6 @@ function system_update_7017() {
function system_update_7018() {
db_drop_index('system', 'modules');
db_drop_index('system', 'type_name');
- db_drop_index('system', 'bootstrap');
db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
db_add_index('system', 'type_name', array('type', 'name'));
db_add_index('system', 'system_list', array('weight', 'name'));