function module_rebuild_cache in Drupal 6
Same name and namespace in other branches
- 5 includes/module.inc \module_rebuild_cache()
Rebuild the database cache of module files.
Return value
The array of filesystem objects used to rebuild the cache.
10 calls to module_rebuild_cache()
- drupal_install_modules in includes/
install.inc - Calls the install function and updates the system table for a given list of modules.
- drupal_install_system in includes/
install.inc - Callback to install the system module.
- help_links_as_list in modules/
help/ help.admin.inc - install_tasks in ./
install.php - Tasks performed after the database is initialized.
- system_admin_by_module in modules/
system/ system.admin.inc - Menu callback; prints a listing of admin tasks for each installed module.
File
- includes/
module.inc, line 95 - API for loading and interacting with Drupal modules.
Code
function module_rebuild_cache() {
$write_database = TRUE;
// If lock not acquired, return $files data without writing to database.
if (!lock_acquire('module_rebuild_cache')) {
$write_database = FALSE;
// Wait for the parallel thread to be done so we are more likely
// to get updated and consistent data.
lock_wait('module_rebuild_cache');
}
// Get current list of modules
$files = drupal_system_listing('\\.module$', 'modules', 'name', 0);
// Extract current files from database.
system_get_files_database($files, 'module');
ksort($files);
// Set defaults for module info
$defaults = array(
'dependencies' => array(),
'dependents' => array(),
'description' => '',
'version' => NULL,
'php' => DRUPAL_MINIMUM_PHP,
);
foreach ($files as $filename => $file) {
// Look for the info file.
$file->info = drupal_parse_info_file(dirname($file->filename) . '/' . $file->name . '.info');
// Skip modules that don't provide info.
if (empty($file->info)) {
unset($files[$filename]);
continue;
}
// Invoke hook_system_info_alter() to give installed modules a chance to
// modify the data in the .info files if necessary.
drupal_alter('system_info', $files[$filename]->info, $files[$filename]);
// Merge in defaults and save.
$files[$filename]->info = $file->info + $defaults;
}
// If lock not acquired, return $files data without writing to database.
if ($write_database) {
foreach ($files as $filename => $file) {
// Log the critical hooks implemented by this module.
$bootstrap = 0;
foreach (bootstrap_hooks() as $hook) {
if (module_hook($file->name, $hook)) {
$bootstrap = 1;
break;
}
}
// Update the contents of the system table:
if (isset($file->status)) {
db_query("UPDATE {system} SET info = '%s', name = '%s', filename = '%s', bootstrap = %d WHERE filename = '%s'", serialize($files[$filename]->info), $file->name, $file->filename, $bootstrap, $file->old_filename);
}
else {
// This is a new module.
$files[$filename]->status = 0;
$files[$filename]->throttle = 0;
db_query("INSERT INTO {system} (name, info, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, serialize($files[$filename]->info), 'module', $file->filename, 0, 0, $bootstrap);
}
}
lock_release('module_rebuild_cache');
}
$files = _module_build_dependencies($files);
return $files;
}