Sorry if this is a noisy issue.
While working on #898768: D7: drush dis [module] can disable profile I've found that the "files" array returned by `system_rebuild_module_data()` provide 'dependents' along with 'dependencies' (that is just the array in the .info file).
It also provides `requires` and `required_by` that are respectively the dependencies array parsed and the reverse dependencies (or dependents), calculated by drupal. Consider this object for the color module in a site installed with standard profile:
stdClass Object
(
[uri] => modules/color/color.module
[filename] => modules/color/color.module
[name] => color
[info] => Array
(
[name] => Color
[description] => Allows administrators to change the color scheme of compatible themes.
[package] => Core
[version] => 7.0-dev
[core] => 7.x
[files] => Array
(
[0] => color.module
[1] => color.install
[2] => color.test
)
[dependencies] => Array
(
)
[dependents] => Array
(
)
[php] => 5.2.0
[bootstrap] => 0
)
[type] => module
[status] => 1
[schema_version] => 0
[weight] => 0
[required_by] => Array
(
[standard] => Array
(
[name] => color
)
)
[requires] => Array
(
)
[sort] => -1
)
dependents and required_by doesn't match. I've digged into the code to see where is this coming from... with a simple grep I see that dependents is not used in any place. It's just an initialized key that is never used.
$ rgrep dependents includes/* modules/*
includes/module.inc: * @param $disable_dependents
includes/module.inc:function module_disable($module_list, $disable_dependents = TRUE) {
includes/module.inc: if ($disable_dependents) {
includes/module.inc: // Get all module data so we can find dependents and sort.
includes/update.inc: 'dependents' => array(),
modules/system/system.module: 'dependents' => array(),
modules/system/system.install: 'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, dependents, and php.",
modules/system/system.install: 'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, dependents, and php.",
modules/system/system.admin.inc: // Mark dependents disabled so the user cannot remove required modules.
modules/system/system.admin.inc: $dependents = array();
It is said in a description that dependents is a valid key for .info files but I don't see any usage for that. It's also not explained in "Writing .info files (Drupal 7.x)" -> http://drupal.org/node/542202 so if it's not something to drop from the code is something to add to the handbook :)
Please enlighten me. I can provide a patch to remove it from code or can improve the handbook.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | drupal-908578.patch | 3.13 KB | jonhattan |
| #3 | drupal-908578.patch | 2.61 KB | jonhattan |
Comments
Comment #1
David_Rothstein commentedHm, interesting.
I'm not sure the mismatch itself (between 'dependents' and 'required_by') is technically a bug - I've noticed that 'dependencies' and 'requires' don't always match either, and I believe that is simply because 'dependencies' represents the immediate dependencies declared by the module, whereas 'requires' represents all modules that are (ultimately) required, i.e. including dependencies of the dependencies and so forth.
However, it does appear that 'dependents' is totally unused by core (for example, it's not taken into consideration at all in http://api.drupal.org/api/function/_module_build_dependencies/7), and plus, it doesn't make much sense. It's easy for a module to know (and declare) all the modules it depends on, but how can a module know all the modules that might possibly depend on it?
I'd agree with just removing it.
Comment #2
David_Rothstein commentedComment #3
jonhattanDavid fyi dependencies accepts modules in this form: 'menu (2.x)' and required_by is a parsed version of that.
Those files are recent additions to HEAD
they include dependents a ton of times. As I understand they're somehow a dump of d6 so I've left them out of this patch.
Comment #4
David_Rothstein commentedMaybe you're referring to a different use of 'requires' and 'required_by' (in the UI)? The ones I'm talking about come from http://api.drupal.org/api/function/_module_build_dependencies/7 and is the result of a deep search through the dependencies, so it contains all the ultimate dependencies (no matter whether it's a direct dependency or a dependency of a dependency, etc), whereas 'dependencies' just contains the direct ones listed in the module's info file.
Anyway, the patch looks good to me, but I think you missed one place: There is a line in system_update_7055() that should be fixed also. After that, I think this is RTBC.
Comment #5
jonhattanNew patch including the fix in system_update_7055().
David: you're right. What I tried to say is that 'dependencies' contain dependency strings (as in http://api.drupal.org/api/function/drupal_parse_dependency/7) and 'required' contains a parsed version of such dependency strings --in addition to the whole dependency chain.
Comment #6
dries commentedCommitted to CVS HEAD.