function _drush_pm_releasenotes

4.x pm.drush.inc _drush_pm_releasenotes($requests, $print_status = TRUE, $tmpfile = NULL)

Internal function: prints release notes for given drupal projects.

Parameters

$requests: An array of drupal.org project names optionally with a version.

$print_status: Boolean. Used by pm-download to not print a informative note.

$tmpfile: If provided, a file that contains contents to show before the release notes.

See also

drush_pm_releasenotes()

4 calls to _drush_pm_releasenotes()
drush_pm_download in commands/pm/pm.drush.inc
Command callback. Download Drupal core or any project.
drush_pm_releasenotes in commands/pm/pm.drush.inc
Command callback. Show release notes for given project(s).
pm_update_packages in commands/pm/updatecode.pm.inc
Update projects according to an array of releases and print the release notes for each project, following interactive confirmation from the user.
_pm_update_core in commands/pm/updatecode.pm.inc
Update drupal core, following interactive confirmation from the user.

File

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

Code

function _drush_pm_releasenotes($requests, $print_status = TRUE, $tmpfile = NULL) {
  if ($tmpfile == NULL) {
    $tmpfile = drush_tempnam('rln-' . implode('-', $requests) . '.');
  }
  // Parse requests to strip versions.
  $requests = pm_parse_project_version($requests);
  // Get the releases.
  $info = _drush_pm_get_releases(array_keys($requests));
  if (!$info) {
    return drush_log(dt('No valid projects given.'), 'ok');
  }

  foreach ($info as $key => $project) {
    $selected_versions = array();
    // If the request included version, only show its release notes.
    if (isset($requests[$key]['version'])) {
      $selected_versions[] = $requests[$key]['version'];
    }
    else {
      // Special handling if the project is installed.
      if (isset($project['recommended'], $project['installed'])) {
        $releases = array_reverse($project['releases']);
        foreach ($releases as $version => $release) {
          if ($release['date'] >= $project['releases'][$project['installed']]['date']) {
            $release += array('version_extra' => '');
            $project['releases'][$project['installed']] += array('version_extra' => '');
            if ($release['version_extra'] == 'dev' && $project['releases'][$project['installed']]['version_extra'] != 'dev') {
              continue;
            }
            $selected_versions[] = $version;
          }
        }
      }
      else {
        // Project is not installed so we will show the release notes
        // for the recommended version, as the user did not specify one.
        $selected_versions[] = $project['recommended'];
      }
    }

    foreach ($selected_versions as $version) {
      // Stage of parsing.
      if (!isset($project['releases'][$version]['release_link'])) {
        // We avoid the cases where the URL of the release notes does not exist.
        drush_log(dt("Project !project does not have release notes for version !version.", array('!project' => $key, '!version' => $version)), 'warning');
        continue;
      }
      else {
        $release_page_url = $project['releases'][$version]['release_link'];
      }
      $release_page_url_parsed = parse_url($release_page_url);
      $release_url_path = $release_page_url_parsed['path'];
      if (!empty($release_url_path)) {
        if ($release_page_url_parsed['host'] == 'drupal.org') {
          $release_page_id = substr($release_url_path, strlen('/node/'));
          drush_log(dt("Release link for !project (!version) project was found.", array('!project' => $key, '!version' => $version)), 'notice');
        }
        else {
          drush_log(dt("Release notes' page for !project project is not hosted on drupal.org. See !url.", array('!project' => $key, '!url' => $release_page_url)), 'warning');
          continue;
        }
      }
      // We'll use drupal_http_request if available; it provides better error reporting.
      if (function_exists('drupal_http_request')) {
        $data = drupal_http_request($release_page_url);
        if (isset($data->error)) {
          drush_log(dt("Error (!error) while requesting the release notes page for !project project.", array('!error' => $data->error, '!project' => $key)), 'error');
          continue;
        }
        @$dom = DOMDocument::loadHTML($data->data);
      }
      else {
        $filename = _drush_download_file($release_page_url);
        @$dom = DOMDocument::loadHTMLFile($filename);
        @unlink($filename);
        if ($dom === FALSE) {
          drush_log(dt("Error while requesting the release notes page for !project project.", array('!project' => $key)), 'error');
          continue;
        }
      }
      if ($dom) {
        drush_log(dt("Successfully parsed and loaded the HTML contained in the release notes' page for !project (!version) project.", array('!project' => $key, '!version' => $version)), 'notice');
      }
      $xml = simplexml_import_dom($dom);
      $xpath_expression = '//*[@id="node-' . $release_page_id . '"]/div[@class="node-content"]';
      $node_content = $xml->xpath($xpath_expression);

      // We create the print format.
      $notes_last_update = $node_content[0]->div[1]->div[0]->asXML();
      unset($node_content[0]->div);
      $project_notes = $node_content[0]->asXML();

      // Build the status message from the info from _drush_pm_get_releases
      $status_msg = '> ' . implode(', ', $project['releases'][$version]['release_status']);
      $break = '<br>';
      $notes_header = dt("<hr>
 > RELEASE NOTES FOR '!name' PROJECT, VERSION !version:!break
 > !time.!break
 !status
<hr>
", array('!status' => $print_status ? $status_msg : '', '!name' => strtoupper($key), '!break' => $break, '!version' => $version, '!time' => $notes_last_update));
      // Finally we print the release notes for the requested project.
      if (drush_get_option('html', FALSE)) {
        $print = $notes_header . $project_notes;
      }
      else {
        $print = drush_html_to_text($notes_header . $project_notes . "\n", array('br', 'p', 'ul', 'ol', 'li', 'hr'));
        if (drush_drupal_major_version() < 7) {
          $print .= "\n";
        }
      }
      file_put_contents($tmpfile, $print, FILE_APPEND);
    }
  }
  drush_print_file($tmpfile);
}