Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

drush_pm_install_package

Definition

drush_pm_install_package()
contributions/drush/drush_pm/drush_pm.module, line 122

Description

Command callback. Installs one or more packages (so far only modules).

Code

<?php
function drush_pm_install_package() {
  $projects = func_get_args();
  if (empty($projects)) {
    drush_die(t("No project specified.\n\nRun drush help pm install for more information."));
  }
  
  // Parse out project name and version
  $projects = drush_pm_parse_package_name($projects);
  
  // If a URI is provided then we install to that specific site, otherwise we install to sites/all/modules
  if (DRUSH_URI) {
    $path = conf_path();
    $modulepath = DRUSH_DRUPAL_ROOT .'/'. $path .'/modules/';
  }
  
  if (!isset($modulepath) || !file_exists($modulepath)) {
    $modulepath = DRUSH_DRUPAL_ROOT .'/sites/all/modules/';
  }

  // Get the module info from drupal.org via xml-rpc
  $info = drush_pm_get_project_info($projects);
  if (!$info) {
    drush_die(t("None of the given projects exists or has releases that are compatible with your Drupal version."));
  }
  
  $startdir = getcwd();

  $package_handler = drush_pm_get_package_handler() .'_install_project';
  if (!function_exists($package_handler)) {
  	drush_die(t("The $package_handler package handler does not handle installs."));
  }

  // Download and install each module
  foreach($projects as $project_name => $project) {
    if (isset($info[$project_name]) && $release = drush_pm_get_release($project, $info[$project_name])) {
      if (is_dir($modulepath . $project_name)) {
        drush_error(t('Project !project is already installed. Skipping.', array('!project' => $project_name)));
      }
      elseif ($package_handler($project_name, $release, $modulepath)) {
        drush_print(t("Project !project successfully installed (version !version).",
          array('!project' => $project_name, '!version' => $release['version'])));
      }
    }
    else {
      drush_error(t('Project !project doesn\' exist or has no releases that are compatible with your Drupal version. Skipping.', array('!project' => $project_name)));
    }
  }

  drush_op('chdir', $startdir);
}
?>