function drush_get_projects

8.0.x pm.drush.inc drush_get_projects(&$extensions = NULL)
6.x pm.drush.inc drush_get_projects(&$extensions = NULL)
7.x pm.drush.inc drush_get_projects(&$extensions = NULL)
3.x environment.inc drush_get_projects()
4.x pm.drush.inc drush_get_projects(&$extensions = NULL)
5.x pm.drush.inc drush_get_projects(&$extensions = NULL)
master pm.drush.inc drush_get_projects(&$extensions = NULL)

Obtain an array of installed projects off the extensions available.

A project is considered to be 'enabled' when any of its extensions is enabled. If any extension lacks project information and it is found that the extension was obtained from drupal.org's cvs or git repositories, a new 'vcs' attribute will be set on the extension. Example: $extensions[name]->vcs = 'cvs';

Parameters

array $extensions: Array of extensions as returned by drush_get_extensions().

Return value

Array of installed projects with info of version, status and provided extensions.

Related topics

9 calls to drush_get_projects()
drush_pm_download in commands/pm/download.pm.inc
Command callback. Download Drupal core or any project.
drush_pm_projectinfo in commands/pm/projectinfo.pm.inc
Implementation of drush_hook_COMMAND().
drush_pm_releasenotes in commands/pm/pm.drush.inc
Command callback. Show release notes for given project(s).
drush_pm_releases in commands/pm/pm.drush.inc
Command callback. Show available releases for given project(s).
drush_pm_updatestatus in commands/pm/updatestatus.pm.inc
Command callback. Displays update status info of installed projects.

... See full list

File

commands/pm/pm.drush.inc, line 658
The drush Project Manager

Code

function drush_get_projects(&$extensions = NULL) {
  if (!isset($extensions)) {
    $extensions = drush_get_extensions();
  }
  $projects = array(
    'drupal' => array(
      'label' => 'Drupal',
      'version' => drush_drupal_version(),
      'type' => 'core',
      'extensions' => array(),
    ),
  );
  if (isset($extensions['system']->info['datestamp'])) {
    $projects['drupal']['datestamp'] = $extensions['system']->info['datestamp'];
  }
  foreach ($extensions as $extension) {
    $extension_name = drush_extension_get_name($extension);
    $extension_path = drush_extension_get_path($extension);

    // Obtain the project name. It is not available in this cases:
    //   1. the extension is part of drupal core.
    //   2. the project was checked out from CVS/git and cvs_deploy/git_deploy
    //      is not installed.
    //   3. it is not a project hosted in drupal.org.
    if (empty($extension->info['project'])) {
      if (isset($extension->info['version']) && ($extension->info['version'] == drush_drupal_version())) {
        $project = 'drupal';
      }
      else {
        if (is_dir($extension_path . '/CVS') && (!drush_module_exists('cvs_deploy'))) {
          $extension->vcs = 'cvs';
          drush_log(dt('Extension !extension is fetched from cvs. Ignoring.', array('!extension' => $extension_name)), LogLevel::DEBUG);
        }
        elseif (is_dir($extension_path . '/.git') && (!drush_module_exists('git_deploy'))) {
          $extension->vcs = 'git';
          drush_log(dt('Extension !extension is fetched from git. Ignoring.', array('!extension' => $extension_name)), LogLevel::DEBUG);
        }
        continue;
      }
    }
    else {
      $project = $extension->info['project'];
    }

    // Create/update the project in $projects with the project data.
    if (!isset($projects[$project])) {
      $projects[$project] = array(
        
        // If there's an extension with matching name, pick its label.
        // Otherwise use just the project name. We avoid $extension->label
        // for the project label because the extension's label may have
        // no direct relation with the project name. For example,
        // "Text (text)" or "Number (number)" for the CCK project.
        'label' => isset($extensions[$project]) ? $extensions[$project]->label : $project,
        'type' => drush_extension_get_type($extension),
        'version' => $extension->info['version'],
        'status' => $extension->status,
        'extensions' => array(),
      );
      if (isset($extension->info['datestamp'])) {
        $projects[$project]['datestamp'] = $extension->info['datestamp'];
      }
      if (isset($extension->info['project status url'])) {
        $projects[$project]['status url'] = $extension->info['project status url'];
      }
    }
    else {
      // If any of the extensions is enabled, consider the project is enabled.
      if ($extension->status != 0) {
        $projects[$project]['status'] = $extension->status;
      }
    }
    $projects[$project]['extensions'][] = drush_extension_get_name($extension);
  }

  // Obtain each project's path and try to provide a better label for ones
  // with machine name.
  $reserved = array('modules', 'sites', 'themes');
  foreach ($projects as $name => $project) {
    if ($name == 'drupal') {
      continue;
    }

    // If this project has no human label, see if we can find
    // one "main" extension whose label we could use.
    if ($project['label'] == $name) {
      // If there is only one extension, construct a label based on
      // the extension name.
      if (count($project['extensions']) == 1) {
        $extension = $extensions[$project['extensions'][0]];
        $projects[$name]['label'] = $extension->info['name'] . ' (' . $name . ')';
      }
      else {
        // Make a list of all of the extensions in this project
        // that do not depend on any other extension in this
        // project.
        $candidates = array();
        foreach ($project['extensions'] as $e) {
          $has_project_dependency = FALSE;
          if (isset($extensions[$e]->info['dependencies']) && is_array($extensions[$e]->info['dependencies'])) {
            foreach ($extensions[$e]->info['dependencies'] as $dependent) {
              if (in_array($dependent, $project['extensions'])) {
                $has_project_dependency = TRUE;
              }
            }
          }
          if ($has_project_dependency === FALSE) {
            $candidates[] = $extensions[$e]->info['name'];
          }
        }
        // If only one of the modules is a candidate, use its name in the label
        if (count($candidates) == 1) {
          $projects[$name]['label'] = reset($candidates) . ' (' . $name . ')';
        }
      }
    }

    drush_log(dt('Obtaining !project project path.', array('!project' => $name)), LogLevel::DEBUG);
    $path = _drush_pm_find_common_path($project['type'], $project['extensions']);
    // Prevent from setting a reserved path. For example it may happen in a case
    // where a module and a theme are declared as part of a same project.
    // There's a special case, a project called "sites", this is the reason for
    // the second condition here.
    if ($path == '.' || (in_array(basename($path), $reserved) && !in_array($name, $reserved))) {
      drush_log(dt('Error while trying to find the common path for enabled extensions of project !project. Extensions are: !extensions.', array('!project' => $name, '!extensions' => implode(', ', $project['extensions']))), LogLevel::ERROR);
    }
    else {
      $projects[$name]['path'] = $path;
    }
  }

  return $projects;
}