| 5 module.inc | module_enable($module_list) |
| 6 module.inc | module_enable($module_list) |
| 7 module.inc | module_enable($module_list, $enable_dependencies = TRUE) |
| 8 module.inc | module_enable($module_list, $enable_dependencies = TRUE) |
Enable a given list of modules.
Parameters
$module_list: An array of module names.
File
- includes/
module.inc, line 312 - API for loading and interacting with Drupal modules.
Code
<?php
function module_enable($module_list) {
$invoke_modules = array();
foreach ($module_list as $module) {
$existing = db_fetch_object(db_query("SELECT status FROM {system} WHERE type = '%s' AND name = '%s'", 'module', $module));
if ($existing->status == 0) {
module_load_install($module);
db_query("UPDATE {system} SET status = %d, throttle = %d WHERE type = '%s' AND name = '%s'", 1, 0, 'module', $module);
drupal_load('module', $module);
$invoke_modules[] = $module;
}
}
if (!empty($invoke_modules)) {
// Refresh the module list to include the new enabled module.
module_list(TRUE, FALSE);
// Force to regenerate the stored list of hook implementations.
module_implements('', FALSE, TRUE);
}
foreach ($invoke_modules as $module) {
module_invoke($module, 'enable');
// Check if node_access table needs rebuilding.
// We check for the existence of node_access_needs_rebuild() since
// at install time, module_enable() could be called while node.module
// is not enabled yet.
if (function_exists('node_access_needs_rebuild') && !node_access_needs_rebuild() && module_hook($module, 'node_grants')) {
node_access_needs_rebuild(TRUE);
}
}
}
?> Login or register to post comments
Comments
No return value - that's
No return value - that's unfortunate.
Agree on return value
I just came here to the API page to make sure that this was indeed returning true on success... :(
Same here! Return value is
Same here! Return value is the all point!
You missed it
Look at the db_query in the first foreach loop. The modules are always marked as enabled, even if the install code fails. Period. Module_enable cannot fail.
I wouldn't consider this an optimal situation, but that's the way it is.
Use drupal_install_modules to do install
This function doesn't call hook_install. If you try using this function to install a module, it'll enable it but none of the module's tables will be created or anything else in its install hook.
You can always use
You can always use module_exists() which check the success of this function but I agree including this would have been nice.