Commit 30d7bd56 authored by drumm's avatar drumm

#93212 by Jaza. Refactor module enabling for greater API avialiablity during hook_enable().

parent 968a51a4
......@@ -328,31 +328,26 @@ function drupal_install_profile($profile, $module_list) {
/**
* Execute the install scripts for a set of modules.
* Calls the install function and updates the system table for a given list of
* modules.
*
* @param module_list
* The modules to install.
*/
function drupal_install_modules($module_list = array()) {
$enable_modules = array();
foreach ($module_list as $module) {
drupal_install_module($module);
if (drupal_get_installed_schema_version($module, TRUE) == SCHEMA_UNINSTALLED) {
module_load_install($module);
module_invoke($module, 'install');
$versions = drupal_get_schema_versions($module);
drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
$enable_modules[] = $module;
}
}
}
/**
* Calls the install function and updates the system table for a given module.
*
* @param module
* The module to install.
*/
function drupal_install_module($module) {
if (drupal_get_installed_schema_version($module, TRUE) == SCHEMA_UNINSTALLED) {
module_load_install($module);
module_invoke($module, 'install');
$versions = drupal_get_schema_versions($module);
drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
module_enable($module);
}
module_enable($enable_modules);
}
/**
......
......@@ -227,22 +227,33 @@ function module_load_install($module) {
}
/**
* Enable a given module.
* Enable a given list of modules.
*
* @param $module
* Enable a given module and call its enable hook.
* @param $module_list
* An array of module names.
*/
function module_enable($module) {
$existing = db_fetch_object(db_query("SELECT name, status FROM {system} WHERE type = 'module' AND name = '%s'", $module));
if ($existing->status === '0') {
module_load_install($module);
db_query("UPDATE {system} SET status = 1, throttle = 0 WHERE type = 'module' AND name = '%s'", $module);
drupal_load('module', $module);
module_invoke($module, 'enable');
return TRUE;
function module_enable($module_list) {
$invoke_modules = array();
foreach ($module_list as $module) {
$existing = db_fetch_object(db_query("SELECT name, status FROM {system} WHERE type = 'module' AND name = '%s'", $module));
if ($existing->status === '0') {
module_load_install($module);
db_query("UPDATE {system} SET status = 1, throttle = 0 WHERE type = 'module' AND name = '%s'", $module);
drupal_load('module', $module);
$invoke_modules[] = $module;
}
}
else {
return FALSE;
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);
cache_clear_all('*', 'cache_menu', TRUE);
}
foreach ($invoke_modules as $module) {
module_invoke($module, 'enable');
}
}
......
......@@ -1442,13 +1442,14 @@ function system_modules_submit($form_id, $form_values) {
}
}
$enable_modules = array();
foreach ($form_values['status'] as $key => $choice) {
if ($choice) {
if (drupal_get_installed_schema_version($key) == SCHEMA_UNINSTALLED) {
$new_modules[] = $key;
}
else {
module_enable($key);
$enable_modules[] = $key;
}
}
else {
......@@ -1456,14 +1457,19 @@ function system_modules_submit($form_id, $form_values) {
}
}
if (!empty($enable_modules)) {
module_enable($enable_modules);
}
$old_module_list = module_list();
// Install new modules.
foreach ($new_modules as $module) {
if (drupal_check_module($module)) {
drupal_install_module($module);
foreach ($new_modules as $key => $module) {
if (!drupal_check_module($module)) {
unset($new_modules[$key]);
}
}
drupal_install_modules($new_modules);
$current_module_list = module_list(TRUE, FALSE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment