- Patch #887870 by sun, David_Rothstein: make system_list() return full module records.

merge-requests/26/head
Dries Buytaert 2010-09-03 19:49:56 +00:00
parent 9427ec09f8
commit 5d810f73e7
4 changed files with 43 additions and 17 deletions

View File

@ -72,7 +72,9 @@ function module_list($refresh = FALSE, $bootstrap = FALSE, $sort = FALSE, $fixed
$list = system_list('bootstrap'); $list = system_list('bootstrap');
} }
else { else {
$list = system_list('module_enabled'); // Not using drupal_map_assoc() here as that requires common.inc.
$list = array_keys(system_list('module_enabled'));
$list = (!empty($list) ? array_combine($list, $list) : array());
} }
} }
} }
@ -96,9 +98,10 @@ function module_list($refresh = FALSE, $bootstrap = FALSE, $sort = FALSE, $fixed
* - theme: All themes. * - theme: All themes.
* *
* @return * @return
* An associative array of modules or themes, keyed by name, and having the * An associative array of modules or themes, keyed by name. For $type
* respective database row as value. For $type 'module_enabled' and * 'bootstrap', the array values equal the keys. For $type 'module_enabled'
* 'bootstrap', the array values equal the keys. * or 'theme', the array values are objects representing the respective
* database row, with the 'info' property already unserialized.
* *
* @see module_list() * @see module_list()
* @see list_themes() * @see list_themes()
@ -143,11 +146,12 @@ function system_list($type) {
// Drupal installations, which might have modules installed in different // Drupal installations, which might have modules installed in different
// locations in the file system. The ordering here must also be // locations in the file system. The ordering here must also be
// consistent with the one used in module_implements(). // consistent with the one used in module_implements().
$result = db_query("SELECT * FROM {system} ORDER BY weight ASC, name ASC"); $result = db_query("SELECT * FROM {system} WHERE type = 'theme' OR (type = 'module' AND status = 1) ORDER BY weight ASC, name ASC");
foreach ($result as $record) { foreach ($result as $record) {
if ($record->type == 'module' && $record->status) { $record->info = unserialize($record->info);
// Build a list of all enabled modules. // Build a list of all enabled modules.
$lists['module_enabled'][$record->name] = $record->name; if ($record->type == 'module') {
$lists['module_enabled'][$record->name] = $record;
} }
// Build a list of themes. // Build a list of themes.
if ($record->type == 'theme') { if ($record->type == 'theme') {

View File

@ -583,7 +583,6 @@ function list_themes($refresh = FALSE) {
try { try {
foreach (system_list('theme') as $theme) { foreach (system_list('theme') as $theme) {
if (file_exists($theme->filename)) { if (file_exists($theme->filename)) {
$theme->info = unserialize($theme->info);
$themes[] = $theme; $themes[] = $theme;
} }
} }

View File

@ -1573,8 +1573,7 @@ function system_schema() {
), ),
'primary key' => array('filename'), 'primary key' => array('filename'),
'indexes' => array( 'indexes' => array(
'bootstrap' => array('status', 'bootstrap', 'type', 'weight', 'name'), 'system_list' => array('status', 'bootstrap', 'type', 'weight', 'name'),
'system_list' => array('weight', 'name'),
'type_name' => array('type', 'name'), 'type_name' => array('type', 'name'),
), ),
); );
@ -2884,6 +2883,15 @@ function system_update_7060(&$sandbox) {
} }
} }
/**
* Replace 'system_list' index with 'bootstrap' index on {system}.
*/
function system_update_7061() {
db_drop_index('system', 'bootstrap');
db_drop_index('system', 'system_list');
db_add_index('system', 'system_list', array('status', 'bootstrap', 'type', 'weight', 'name'));
}
/** /**
* @} End of "defgroup updates-6.x-to-7.x" * @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000. * The next series of updates should start at 8000.

View File

@ -2217,25 +2217,40 @@ function system_update_files_database(&$files, $type) {
} }
/** /**
* Returns an array of information about active modules or themes. * Returns an array of information about enabled modules or themes.
* *
* This function returns the information from the {system} table corresponding * This function returns the information from the {system} table corresponding
* to the cached contents of the .info file for each active module or theme. * to the cached contents of the .info file for each active module or theme.
* *
* @param $type * @param $type
* Either 'module' or 'theme'. * Either 'module' or 'theme'.
* @param $name
* (optional) The name of a module or theme whose information shall be
* 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.
* *
* @return * @return
* An associative array of module or theme information keyed by name. * An associative array of module or theme information keyed by name, or only
* information for $name, if given. If no records are available, an empty
* array is returned.
* *
* @see system_rebuild_module_data() * @see system_rebuild_module_data()
* @see system_rebuild_theme_data() * @see system_rebuild_theme_data()
*/ */
function system_get_info($type) { function system_get_info($type, $name = NULL) {
$info = array(); $info = array();
$result = db_query('SELECT name, info FROM {system} WHERE type = :type AND status = 1', array(':type' => $type)); if ($type == 'module') {
foreach ($result as $item) { $type = 'module_enabled';
$info[$item->name] = unserialize($item->info); }
$list = system_list($type);
foreach ($list as $shortname => $item) {
if (!empty($item->status)) {
$info[$shortname] = $item->info;
}
}
if (isset($name)) {
return isset($info[$name]) ? $info[$name] : array();
} }
return $info; return $info;
} }