Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I made a mistake when I was testing the pre-pm-enable hook - I was using a module that did not have any requirements. When I tried to make a pre-enable hook for git_deploy, I discovered that Drush is checking the requirements before the extension has a chance to download its dependencies. :(
The attached patch fixes this problem. With this patch applied, the following git_deploy Drush extension works:
git_deploy.drush.inc:
function drush_git_deploy_pre_pm_enable() {
// Get the list of modules being enabled; only download dependencies if our module name appears in the list
$modules = drush_get_context('PM_ENABLE_MODULES');
if (in_array('git_deploy', $modules) && !drush_get_option('skip')) {
$path = drush_get_context('DRUSH_DRUPAL_ROOT');
if (module_exists('libraries')) {
$path .= '/' . libraries_get_path('glip');
}
else {
$path .= '/'. drupal_get_path('module', 'git_deploy');
$path = realpath($path . '/../..') . '/libraries/glip';
}
if (is_dir($path . '/lib')) {
drush_log(dt("Found glip at !path; download not necessary.", array('!path' => $path)), 'ok');
}
else {
drush_log(dt("Checking out glip to !path.", array('!path' => $path)), 'ok');
drush_mkdir($path);
drush_shell_cd_and_exec($path . '/..', 'git clone git://github.com/halstead/glip.git');
drush_shell_cd_and_exec($path, 'git checkout 1.1');
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#4 | pm-enable-check-requirements-3.patch | 5.04 KB | greg.1.anderson |
#3 | pm-enable-check-requirements-2.patch | 5.03 KB | greg.1.anderson |
pm-enable-check-requirements.patch | 1.82 KB | greg.1.anderson |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedNot so sure about this. It is basically lying to move this requirements validation to the main callback. Maybe the policy needs to implement _init() hook or something.
Comment #2
greg.1.anderson CreditAttribution: greg.1.anderson commentedFair enough. I moved the extension-sorting and commandfile-enabling to pm_enable_init, and put the requirements check back in pm_enable_validate. Note, however, that the drush extension in the module being enabled is not eligible to be called until the _validate stage, because its .drush.inc file is not loaded until pm_enable_init adds it. Commandfiles added in one phase are not called until the start of the next phase, so the module will now need to implement the _validate hook. To make sure that the module that is being enabled will get to run its _validate hook before pm_enable_validate is called to check requirements, I added a high-priority mode to _drush_add_commandfiles. This causes the newly-added files to be placed at the start of the commandfile list, so they will get first shot at the next phase. The attached patch also updates the docs in drush.api.php to show the new, working recipe to download requirements in advance.
The example shown in #0 still works as written if you rename the function from drush_git_deploy_pre_pm_enable to drush_git_deploy_pm_enable_validate.
Comment #3
greg.1.anderson CreditAttribution: greg.1.anderson commentedHere's the patch.
Comment #4
greg.1.anderson CreditAttribution: greg.1.anderson commented... and again with whitespace error fixed.
Comment #5
greg.1.anderson CreditAttribution: greg.1.anderson commentedThe prioritized commandfile feature is not sitting well with me. I think that one of the following alternate solutions would be better:
A. Add a "hook_pre_validate" for all Drush commands. Maybe only pm-enable needs it.
B. Have pm_enable_validate call a pre-requirements hook just before it checks the requirements for the modules being enabled.
"B" was the original suggestion, and I think it's best.
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedI could go for either approach, but I think A could be genuinely useful in a number of situations where commandfiles have to alter args/options before validation starts.
Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedI just committed 4bb725c which adds a hook_pre_validate as per A in #5.
Assigning to Greg so he can change any code in Drush or git_deploy thats needs changing.
Comment #8
greg.1.anderson CreditAttribution: greg.1.anderson commentedSetting title for my future reference.
Comment #9
greg.1.anderson CreditAttribution: greg.1.anderson commentedgit_deploy 1.x stopped doing requirements checks, and implemented the automatic download in drush_hook_post_pm_enable, just like devel. In git_deploy 2.x, the git executable is used, removing the need for the library altogether.
I submitted #2082149: Automatically download jquery.imgareaselect on `drush pm-enable media_crop` to media_crop. Going to go ahead and mark this as 'fixed'; there are certainly other contrib modules in the world that could use this, but there's no point trying to track them here.
Comment #10
greg.1.anderson CreditAttribution: greg.1.anderson commentedThis issue was marked
closed (won't fix)
because Drush has moved to Github.If desired, you may copy this task to our Github project and then post a link here to the new issue. Please also change the status of this issue to
closed (duplicate)
.Please ask support questions on Drupal Answers.