Example #1
0
 /**
  * Check that a command has its declared dependencies available or have no
  * dependencies.
  *
  * @param $command
  *   Command to check. Any errors  will be added to the 'bootstrap_errors' element.
  *
  * @return
  *   TRUE if command is valid.
  */
 function drush_enforce_requirement_drupal_dependencies(&$command)
 {
     // If the command bootstrap is DRUSH_BOOTSTRAP_MAX, then we will
     // allow the requirements to pass if we have not successfully
     // bootstrapped Drupal.  The combination of DRUSH_BOOTSTRAP_MAX
     // and 'drupal dependencies' indicates that the drush command
     // will use the dependent modules only if they are available.
     if ($command['bootstrap'] == DRUSH_BOOTSTRAP_MAX) {
         // If we have not bootstrapped, then let the dependencies pass;
         // if we have bootstrapped, then enforce them.
         if (drush_get_context('DRUSH_BOOTSTRAP_PHASE') < DRUSH_BOOTSTRAP_DRUPAL_FULL) {
             return TRUE;
         }
     }
     // If there are no drupal dependencies, then do nothing
     if (!empty($command['drupal dependencies'])) {
         foreach ($command['drupal dependencies'] as $dependency) {
             drush_include_engine('drupal', 'environment');
             if (!drush_module_exists($dependency)) {
                 $command['bootstrap_errors']['DRUSH_COMMAND_DEPENDENCY_ERROR'] = dt('Command !command needs the following modules installed/enabled to run: !dependencies.', array('!command' => $command['command'], '!dependencies' => implode(', ', $command['drupal dependencies'])));
                 return FALSE;
             }
         }
     }
     return TRUE;
 }
Example #2
0
/**
 * 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.
 */
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');
        drush_include_engine('drupal', 'environment');
        if (drush_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);
    }
}