function drush_hook_pre_pm_enable

8.0.x drush.api.php drush_hook_pre_pm_enable()
6.x drush.api.php drush_hook_pre_pm_enable()
7.x drush.api.php drush_hook_pre_pm_enable()
5.x drush.api.php drush_hook_pre_pm_enable()
master drush.api.php drush_hook_pre_pm_enable()

Automatically download project dependencies at pm-enable time. Use a pre-pm_enable hook to download before your module is enabled, or a post-pm_enable hook (drush_hook_post_pm_enable) to run after your module is enabled.

Your hook will be called every time pm-enable is executed; you should only download dependencies when your module is being enabled. Respect the --skip flag, and take no action if it is present.

File

docs/drush.api.php, line 246
Documentation of the Drush API.

Code

function drush_hook_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('hook', $modules) && !drush_get_option('skip')) {
    $url = 'http://server.com/path/MyLibraryName.tgz';
    $path = drush_get_context('DRUSH_DRUPAL_ROOT');
    if (module_exists('libraries')) {
      $path .= '/' . libraries_get_path('MyLibraryName') . '/MyLibraryName.tgz';
    }
    else {
      $path .= '/' . drupal_get_path('module', 'hook') . '/MyLibraryName.tgz';
    }
    drush_download_file($url, $path) && drush_tarball_extract($path);
  }
}