Jump to:
| Project: | Drupal core |
| Version: | 6.x-dev |
| Component: | install system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
Suppose you have a.module which implements hook_requirements(), and b.module which depends on a.module (and declares its dependency in its .info file).
Suppose you installed them, and you want to enable them at the same time. After you click on the Save configuration button present on the modules page, you will notice that an error message will be presented on the page, and that the checkbox for a.module is disabled (and not selected) while the checkbox for b.module is enabled (and selected).
The problem is caused by the following code:
<?php
// Install new modules.
foreach ($new_modules as $key => $module) {
if (!drupal_check_module($module)) {
unset($new_modules[$key]);
}
}
drupal_install_modules($new_modules);
?>When the implementation of hook_requirements returns an error, drupal_check_module($module) will return FALSE, and the array key for that module will be removed (unset($new_modules[$key]) is executed). The array keys for the modules that depends on that module are not removed from the array, with the consequence that the other modules will be listed selected.
This is actually a real case I had with flag.module, which is implementing hook_requirements() that is executed also at installation time, and flag_actions.module.
Comments
#1
I am changing the referring version.
#2
subscribe. I've had this difficulty with jquery_ui as well as some custom modules.
#3
The issue is not present in Drupal 7.
Compare the code used in Drupal 6 (
system_modules_submit())<?php
$enable_modules = array();
$disable_modules = array();
foreach ($form_state['values']['status'] as $key => $choice) {
if ($choice) {
if (drupal_get_installed_schema_version($key) == SCHEMA_UNINSTALLED) {
$new_modules[] = $key;
}
else {
$enable_modules[] = $key;
}
}
else {
$disable_modules[] = $key;
}
}
$old_module_list = module_list();
if (!empty($enable_modules)) {
module_enable($enable_modules);
}
if (!empty($disable_modules)) {
module_disable($disable_modules);
}
// Install new modules.
foreach ($new_modules as $key => $module) {
if (!drupal_check_module($module)) {
unset($new_modules[$key]);
}
}
drupal_install_modules($new_modules);
?>
with the code used in Drupal 7 for the same function
<?php// Invokes hook_requirements('install'). If failures are detected, makes sure
// the dependent modules aren't installed either.
foreach ($modules as $name => $module) {
// Only invoke hook_requirements() on modules that are going to be installed.
if ($module['enabled'] && drupal_get_installed_schema_version($name) == SCHEMA_UNINSTALLED) {
if (!drupal_check_module($name)) {
$modules[$name]['enabled'] = FALSE;
foreach (array_keys($files[$name]->required_by) as $required_by) {
$modules[$required_by]['enabled'] = FALSE;
}
}
}
}
?>
Drupal 7 doesn't show as enabled the modules that depend on the module whose
hook_requirements()returns an error.Drupal 6 also has information about the modules that depend from another one; code similar to the one used by Drupal 7 could be written for Drupal 6.