diff --git a/includes/module.inc b/includes/module.inc index 08749f3..14ee5ae 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -86,7 +86,7 @@ function module_list($refresh = FALSE, $bootstrap_refresh = FALSE, $sort = FALSE } else { // Not using drupal_map_assoc() here as that requires common.inc. - $list = array_keys(system_list('module_enabled')); + $list = system_list('module_enabled'); $list = (!empty($list) ? array_combine($list, $list) : array()); } } @@ -167,7 +167,7 @@ function system_list($type) { $record->info = unserialize($record->info); // Build a list of all enabled modules. if ($record->type == 'module') { - $lists['module_enabled'][$record->name] = $record; + $lists['module_enabled'][] = $record->name; } // Build a list of themes. if ($record->type == 'theme') { @@ -199,6 +199,7 @@ function system_list_reset() { drupal_static_reset('list_themes'); cache_clear_all('bootstrap_modules', 'cache_bootstrap'); cache_clear_all('system_list', 'cache_bootstrap'); + cache_clear_all('system_info:', 'cache', TRUE); } /** diff --git a/modules/system/system.module b/modules/system/system.module index 21b23f4..1dcea58 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -1908,7 +1908,7 @@ function system_init() { * Adds CSS and JavaScript files declared in module .info files. */ function system_add_module_assets() { - foreach (system_get_info('module') as $module => $info) { + foreach (system_get_info('module', NULL, array('stylesheets', 'scripts')) as $module => $info) { if (!empty($info['stylesheets'])) { foreach ($info['stylesheets'] as $media => $stylesheets) { foreach ($stylesheets as $stylesheet) { @@ -2290,6 +2290,12 @@ function system_update_files_database(&$files, $type) { * returned. If omitted, all records for the provided $type will be returned. * If $name does not exist in the provided $type or is not enabled, an empty * array will be returned. + * @param $options + * (optional) An array of keys to get info for. For example array('styles') + * will fetch only the styles information. array('styles', 'scripts') would + * fetch the information for both styles and scripts. This conserves memory + * usage since loading the full info for all modules can be a very large + * amount of data. * * @return * An associative array of module or theme information keyed by name, or only @@ -2299,16 +2305,27 @@ function system_update_files_database(&$files, $type) { * @see system_rebuild_module_data() * @see system_rebuild_theme_data() */ -function system_get_info($type, $name = NULL) { +function system_get_info($type, $name = NULL, $options = array()) { $info = array(); - if ($type == 'module') { - $type = 'module_enabled'; + $cid = 'system_info' . ':' . $type . implode('|', $options); + if ($cached = cache_get($cid)) { + $info = $cached->data; } - $list = system_list($type); - foreach ($list as $shortname => $item) { - if (!empty($item->status)) { - $info[$shortname] = $item->info; + else { + $result = db_query('SELECT * FROM {system} WHERE type = :type AND status = 1', array(':type' => $type)); + foreach($result as $record) { + $record->info = unserialize($record->info); + if (!empty($options)) { + $record->info = array_intersect_key($record->info, array_flip($options)); + if (!empty($record->info)) { + $info[$record->name] = $record->info; + } + } + else { + $info[$record->name] = $record->info; + } } + cache_set($cid, $info); } if (isset($name)) { return isset($info[$name]) ? $info[$name] : array();