drush_invoke automatically generates callbacks based on the command that is being run, but it is possible to step over drupal's own API.
In Hosting, I have several existing Drupal modules which have their own *.drush.inc files, but in these same modules i also have implementations of Drupal's hook_update. When I try to use drush.php update on the site with the hosting module, it attempts to run the drupal hook_update as if it was part of the drush command. This of course results in a big mess.
The solution to this is to make sure drush commands are in their own namespace, and can't interfere with Drupal's API. My first attempt was to have the format : $commandfile_drush_$command , but i soon realized this caused drush to venture into it's own namespace. For instance, the 'core_drush_help' implementation was thought to be an extension to the drush.php help function.
Now I am working to change the format to : 'drush_$commandfile_$command' , which will ensure that drush_invoke doesn't step over any other namespaces.
I'll post a patch shortly.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | invoke.drush_.inc_.txt | 1.98 KB | adrian |
Comments
Comment #1
adrian commentedI wrote a drush command which uses the API itself and reflection to find all the possibly afflicted functions, and replace them using sed.
I also did function_exists checks to make sure i'm not messing up any other namespaces. The script also does php -l on the replaced files.
To pick up the new function names, I am going to add a new parameter to drush_commandfile_implements and drush_command_hook called namespace, which defaults to null, but if set, will prepend the namespace to the module name.
Heres the changes across drush, provision and hosting (all the commands I have), but the script should work for any command file (i'll add it to the issue when i've finished it).
Comment #2
adrian commentedfixed in http://drupal.org/cvs?commit=208468
Attached is the drush commandfile to help with conversion. It needs to bootstrap to drupal_full, so you should run it on an active site / drupal dir.
Copy the file to ~/.drush/invoke.drush.inc
if you find any files you want to exclude, it accepts the --exclude option, which is a comma separated list of basenames , ie:
Once you're happy, the --pipe option will generate a shell script for you :
Of course your mileage may vary, but this worked for hosting and provision (which is a _lot_ of drush code).
Comment #3
moshe weitzman commentedThats a pretty nifty use of drush and drush_print_pipe() and sed. wow - nice.
Comment #4
adrian commentedYeah, i sure as hell wasn't going to edit it all by hand.
the pattern should be re-usable too.