Closed (fixed)
Project:
Drush
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
7 Jan 2010 at 12:08 UTC
Updated:
3 Feb 2010 at 16:40 UTC
Jump to comment: Most recent file
pm_module_manage gets called when disabling, enabling, or just getting statusmodules.
This means the first half of the function is data gathering, after which there's some logic to go to either pm_module_status() or does the enabling/disabling.
I think the code would be easier to follow due to less spaghetti and less indentation if the data gathering were farmed out to another function: from the top of pm_module_manage() down to "if (empty($modules)) {", and the statusmodules command got its own callback that called that too.
Are you interested in a patch?
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | environment_5.inc_.txt | 1.09 KB | jonhattan |
| #15 | 677894.patch | 11.9 KB | jonhattan |
| #13 | 677894.patch | 11.9 KB | jonhattan |
| #11 | 677894.patch | 12.7 KB | jonhattan |
| #8 | 677894-8.tgz | 10.58 KB | jonhattan |
Comments
Comment #1
jonhattanI think it is of interest now that some other issues are willing to touch that big function. See:
* #654682: drush statusmodule --package: Package column and grouping for the statusmodules list
* #679020: Extend `pm-list` to list modules, themes and profiles and filter by project status (enabled|disabled|uninstalled...)
Comment #2
jonhattanI bet for a refactor including:
0. pm_module_status() first argument ($enabled modules array) is not used. I'd rename pm_module_status() to drush_pm_list() and be the callback for `pm-list` it jsut need to do drupal_get_modules() in the first line.
1. a new environment_5.inc with:
2. new function drush_get_modules_enabled() in includes/environment.inc
3. move code of
module_load_include('inc', 'system', 'system.admin');anddrupal_form_submitto a new function.4. move disable/enable code to drush_pm_enable/disable and finally remove pm_module_manage()
joachim: I can do the patch if your busy as I want this to land before starting with the integration of #530780: drush commands to administer themes with pm commands suite.
Comment #3
joachim commentedNot quite as easy as I first though: that section of code produces two variables!
Not sure how best to proceed as I don't know what sort of pattern the maintainer would prefer to use here, so leaving it for now.
Comment #4
moshe weitzman commentedYes, it is certain that we need to untangle this a bit, and make use of our version specific include feature. Note that updatedb is almost entirely version specific and thats actually helpful sometimes ... I'd love a patch from anyone, really. I have no preconceived notion of how it should lay out. Fire away.
Comment #5
joachim commentedI remembered Crell's presentation on patterns in Paris ;) -- instead of nesting calls, make them sequential and pass information on.
So: first get the list of all modules, then pass that list along to the second helper function which makes the array of enabled modules.
Here is a patch with that in mind -- move out code to two helper functions, and give
drush smits own callback. I assume from the lack of 'callback' key on many items that the callback function may follow a standard pattern if the key is omitted; so I've renamed that function drush_pm_list() too.Big patch, but most of it is a whopping big else{} clause whose indentation has changed because the if {} part was handling the special case for the drush sm command.
I don't know about doing version-specific stuff; I'll leave that for a subsequent patch. This at least breaks the functions up into more manageable chunks as a precursor to that.
I am getting
at the end of a module listing, but I get that without my patch too, so I reckon it's not my problem ;)
Comment #6
moshe weitzman commentedGood start
pm_get_module_info()- unneeded $enabled = array();
- I think can do away with pm_get_module_info_enabled() and instead use array_filter and a tiny callback function. I don't think Crell would mind :)
Comment #7
joachim commentedRight, yes, that looks neater.
Though $enabled is expected to be a flat array of names, so:
Comment #8
jonhattanChanges I propose can't be provided as a patch because they include new files and renaming:
1. rename commands/core/drupal/environment.inc to commands/core/drupal/environment_6.inc
2. New file commands/core/drupal/environment_5.inc based on environment_6.inc with this change:
3. `drush_module_status()` renamed to `drush_pm_list()` that is the callback for pm-list. It just needs `drush_get_modules()`. Don't need $enabled.
4. drop `pm_module_manage()` and move enable/disable code to corresponding `pm_module_enable/disable()`.
5. new function `pm_system_modules_form_submit()` used by `pm_module_enable()` and `pm_module_disable()`. This function encapsulates all the system things needed to trigger form submit on enable/disable modules.
Other possible changes:
a) in D7 `module_enable()` can enable dependencies so some of our logic could be simplified. I dont know the exact difference for D5 and D6. I think some improvement can be done here. Also moving to general functions in environments. ej: drush_enable_modules();
b) in D7 `module_disable()` can disable dependents.
Also attached a tgz with the three files affected for easy review. To be untarred in a drush root folder.
Comment #9
jonhattanLast minute error found: `drupal_install_modules()` is not available for D7 so `pm-enable` is not working for D7. Dunno if there's an open issue about this. Can be fixed here btw.
Comment #10
moshe weitzman commentedLooking *much* better.
Yeah, lets fix that D7 drupal_install_modules problem here. We just need to use module_enable, AFAICT. I can commit before we tackle this, if you prefer.
CVS has no easy way to do rename so we just treat that as a delete and a new file. If you want to make it a tiny bit easier on reviewers, you can represent new files in your diff. You can use fakeadd (see http://wimleers.com/blog/cvs-diff-new-files-fakeadd) or you can use git/bzr built-in diff feature. those let you add a file in the diff without having commit access to drupal.org. I will delete old files manually in cvs. Ideally wou would remind me about manual steps when you post the diff (as you did here).
Comment #11
jonhattanAttached patch powered by fakeadd. Just remove commands/core/drupal/environment.inc from CVS.
I think it's better to review/commit this and open a new issue to fix some more D7 incompatibilities. I've found:
* $module->info['dependencies'] is not always present (it is no mandatory for .info files).
* even worst: `dependencies[] = cck (2.x)` is possible for D7. So we must go through `_module_build_dependencies`. This implies hardly changing `pm_dependencies()` for D7..
Comment #12
moshe weitzman commentedCode looks good.
I'm seeing a bunch of minor errors and warnings with sm and pm-emable commands. Can you try turning on notice reporting and run through the command again. http://drupal.org/node/676360 and make sure your CLI PHP is set to error_reporting E_ALL.
Also see a debug line: + print_r($module_info[$module]);
Comment #13
jonhattandebug and notices cleaned.
Comment #14
moshe weitzman commentedStill a couple notices for in D6. Didn't try other versions yet.
Comment #15
jonhattanI can't see the reason I dont have those errors logged. Perhaps some other option than error_reporting in php.ini.
Comment #16
jonhattanComment #17
moshe weitzman commentedCommitted. many thanks.
FYI, I have 'write errors to log and screen' at admin/settings/error-reporting in drupal. Could be clue for the unreported notices.
I think I got the file changes in a second commit as you detailed. Seems that fakeadd never actually added anything.
Comment #18
jonhattanwhooops, cvs diff shows
... and they're not included in the diff. Sorry for not testing that.
OTOH, you miss environment_5.inc. Next time I'll try git.
on the error messaging: I have the same setting in my drupal.
Comment #19
jonhattanComment #20
moshe weitzman commentedGrr. I put the file in the right place but forgot to cvs add. Not even a git diff can help that.