function release_info_print_releasenotes

6.x updatexml.inc release_info_print_releasenotes($requests, $print_status = TRUE, $tmpfile = NULL)
5.x updatexml.inc release_info_print_releasenotes($requests, $print_status = TRUE, $tmpfile = NULL)

Prints release notes for given 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.

4 calls to release_info_print_releasenotes()
drush_pm_download in commands/pm/download.pm.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/release_info/updatexml.inc, line 134
Drush release info engine for update.drupal.org and compatible services.

Code

function release_info_print_releasenotes($requests, $print_status = TRUE, $tmpfile = NULL) {
  $info = release_info_get_releases($requests);
  if (!$info) {
    return drush_log(dt('No valid projects given.'), 'ok');
  }

  if (is_null($tmpfile)) {
    $tmpfile = drush_tempnam('rln-' . implode('-', array_keys($requests)) . '.');
  }

  // Select versions to show.
  foreach ($info as $name => $project) {
    $selected_versions = array();
    // If the request includes version, show the release notes for this version.
    if (isset($requests[$name]['version'])) {
      $selected_versions[] = $requests[$name]['version'];
    }
    else {
      // If requested project is installed,
      // show release notes for the installed version and all newer versions.
      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 and user did not specify a version,
        // so show the release notes for the recommended version.
        $selected_versions[] = $project['recommended'];
      }
    }

    foreach ($selected_versions as $version) {
      if (!isset($project['releases'][$version]['release_link'])) {
        drush_log(dt("Project !project does not have release notes for version !version.", array('!project' => $name, '!version' => $version)), 'warning');
        continue;
      }

      // Download the release node page and get the html as xml to explore it.
      $release_link = $project['releases'][$version]['release_link'];
      $filename = drush_download_file($release_link, drush_tempnam($name));
      @$dom = DOMDocument::loadHTMLFile($filename);
      if ($dom) {
        drush_log(dt("Successfully parsed and loaded the HTML contained in the release notes' page for !project (!version) project.", array('!project' => $name, '!version' => $version)), 'notice');
      }
      else {
        drush_log(dt("Error while requesting the release notes page for !project project.", array('!project' => $name)), 'error');
        continue;
      }
      $xml = simplexml_import_dom($dom);

      // Extract last update time and the notes.
      $last_updated = $xml->xpath('//div[@class="last-updated"]');
      $last_updated = $last_updated[]->asXML();
      $notes = $xml->xpath('//div[contains(@class,"field-name-body")]');
      $notes = $notes[]->asXML();

      // Build the notes header.
      $header = array();
      $header[] = '<hr>';
      $header[] = dt("> RELEASE NOTES FOR '!name' PROJECT, VERSION !version:", array('!name' => strtoupper($name), '!version' => $version));
      $header[] = dt("> !last_updated.", array('!last_updated' => $last_updated));
      if ($print_status) {
        $header[] = '> ' . implode(', ', $project['releases'][$version]['release_status']);
      }
      $header[] = '<hr>';

      // Finally add the release notes for the requested project to the tmpfile.
      $content = implode("\n", $header) . "\n" . $notes . "\n";
      #TODO# accept $html as a method argument
      if (!drush_get_option('html', FALSE)) {
        $content = drush_html_to_text($content, array('br', 'p', 'ul', 'ol', 'li', 'hr'));
      }
      file_put_contents($tmpfile, $content, FILE_APPEND);
    }
  }
  drush_print_file($tmpfile);
}