Index: release/project-release-create-history.php
===================================================================
RCS file: /Users/wright/drupal/local_repo/contributions/modules/project/release/project-release-create-history.php,v
retrieving revision 1.30
diff -u -p -r1.30 project-release-create-history.php
--- release/project-release-create-history.php	8 Jul 2010 23:16:17 -0000	1.30
+++ release/project-release-create-history.php	23 Dec 2010 17:19:16 -0000
@@ -183,6 +183,9 @@ function project_release_history_generat
  */
 function project_release_history_generate_project_xml($project_nid, $api_tid = NULL) {
   $api_vid = _project_release_get_api_vid();
+  /// @todo: This is a drupal.org-specific hack.
+  /// @see http://drupal.org/node/1003764
+  $is_profile = FALSE;
 
   if (isset($api_tid)) {
     // Restrict output to a specific API compatibility term.
@@ -260,6 +263,11 @@ function project_release_history_generat
   $term_query = db_query("SELECT v.name AS vocab_name, v.vid, td.name AS term_name, td.tid FROM {term_node} tn INNER JOIN {term_data} td ON tn.tid = td.tid INNER JOIN {vocabulary} v ON td.vid = v.vid WHERE tn.vid = %d", $project->vid);
   $xml_terms = '';
   while ($term = db_fetch_object($term_query)) {
+    /// @todo: This is a drupal.org-specific hack.
+    /// @see http://drupal.org/node/1003764
+    if ($term->term_name == 'Installation profiles') {
+      $is_profile = TRUE;
+    }
     $xml_terms .= '   <term><name>'. check_plain($term->vocab_name) .'</name>';
     $xml_terms .= '<value>'. check_plain($term->term_name) ."</value></term>\n";
   }
@@ -271,14 +279,9 @@ function project_release_history_generat
   $joins = array();
   $where = array();
   $parameters = array();
-  // TODO: This is broken for N files per release node.
   $fields = array(
     'n.nid',
     'n.vid',
-    'f.filepath',
-    'f.filesize',
-    'f.timestamp',
-    'prf.filehash',
     'prn.rebuild',
     'prn.version',
     'prn.version_major',
@@ -291,8 +294,6 @@ function project_release_history_generat
   );
 
   $joins[] = "INNER JOIN {project_release_nodes} prn ON n.nid = prn.nid";
-  $joins[] = "INNER JOIN {project_release_file} prf ON n.nid = prf.nid";
-  $joins[] = "INNER JOIN {files} f ON prf.fid = f.fid";
   $where[] = "prn.pid = '%d'";
   $parameters[] = $project->nid;
 
@@ -341,12 +342,21 @@ function project_release_history_generat
         $xml .= "  <$vers_type>". check_plain($release->$vers_type) ."</$vers_type>\n";
       }
     }
+
+    // Need to fetch list of files for this release
+    $files_query = db_query("SELECT prf.filehash, f.filepath, f.filesize, f.timestamp FROM {project_release_file} prf INNER JOIN {files} f on prf.fid = f.fid WHERE prf.nid = %d ORDER BY prf.fid", $release->nid);
+
+    $files = array();
+    while ($file = db_fetch_object($files_query)) {
+      $files[] = $file;
+    }
+
     if ($release->status) {
       // Published, so we should include the links.
       $xml .= "  <status>published</status>\n";
       $xml .= '  <release_link>'. prch_url("node/$release->nid") ."</release_link>\n";
-      if (!empty($release->filepath)) {
-        $download_link = theme('project_release_download_link', $release->filepath, NULL, TRUE);
+      if (!empty($files[0]->filepath)) {
+        $download_link = theme('project_release_download_link', $files[0]->filepath, NULL, TRUE);
         $xml .= '  <download_link>'. $download_link['href'] ."</download_link>\n";
       }
     }
@@ -354,15 +364,67 @@ function project_release_history_generat
       $xml .= "  <status>unpublished</status>\n";
     }
     // We want to include the rest of these regardless of the status.
-    if (!empty($release->timestamp)) {
-      $xml .= '  <date>'. check_plain($release->timestamp) ."</date>\n";
+    if (!empty($files[0]->timestamp)) {
+      $xml .= '  <date>'. check_plain($files[0]->timestamp) ."</date>\n";
     }
-    if (!empty($release->filehash)) {
-      $xml .= '  <mdhash>'. check_plain($release->filehash) ."</mdhash>\n";
+    if (!empty($files[0]->filehash)) {
+      $xml .= '  <mdhash>'. check_plain($files[0]->filehash) ."</mdhash>\n";
     }
-    if (isset($release->filesize)) {
-      $xml .= '  <filesize>'. check_plain($release->filesize) ."</filesize>\n";
+    if (isset($files[0]->filesize)) {
+      $xml .= '  <filesize>'. check_plain($files[0]->filesize) ."</filesize>\n";
     }
+
+    $xml .= "  <files>\n";
+    foreach ($files as $file) {
+      $xml .= "   <file>\n";
+      if ($release->status && !empty($file->filepath)) {
+        $download_link = theme('project_release_download_link', $file->filepath, NULL, TRUE);
+        $xml .= '    <url>' . $download_link['href'] . "</url>\n";
+      }
+      if (!empty($file->filepath)) {
+        $file_parts = explode('.', basename($file->filepath));
+        $archive_type = array_pop($file_parts);
+        // See if the previous extension is '.tar' and if so, add that, so we
+        // see 'tar.gz' or 'tar.bz2' instead of just 'gz' or 'bz2'.
+        $previous_ext = array_pop($file_parts);
+        if ($previous_ext == 'tar') {
+          $archive_type = $previous_ext . '.' . $archive_type;
+        }
+        else {
+          // Put it back on the array, so our profile logic below still works.
+          array_push($file_parts, $previous_ext);
+        }
+        $xml .= '    <archive_type>' . $archive_type . "</archive_type>\n";
+
+        /// @todo: This is a drupal.org-specific hack.
+        /// @see http://drupal.org/node/1003764
+        if ($is_profile) {
+          $variant_chunk = array_pop($file_parts);
+          if (strrpos($variant_chunk, 'no-core') !== FALSE) {
+            $variant = 'projects';
+          }
+          elseif (strrpos($variant_chunk, 'core') !== FALSE) {
+            $variant = 'full';
+          }
+          else {
+            $variant = 'profile-only';
+          }
+          $xml .= '    <variant>' . $variant . "</variant>\n";
+        }
+      }
+      if (!empty($file->filehash)) {
+        $xml .= '    <md5>' . check_plain($file->filehash) . "</md5>\n";
+      }
+      if (isset($file->filesize)) {
+        $xml .= '    <size>' . check_plain($file->filesize) . "</size>\n";
+      }
+      if (!empty($file->timestamp)) {
+        $xml .= '    <filedate>' . check_plain($file->timestamp) . "</filedate>\n";
+      }
+      $xml .= "   </file>\n";
+    }
+    $xml .= "  </files>\n";
+
     $term_query = db_query("SELECT v.name AS vocab_name, v.vid, td.name AS term_name, td.tid FROM {term_node} tn INNER JOIN {term_data} td ON tn.tid = td.tid INNER JOIN {vocabulary} v ON td.vid = v.vid WHERE tn.vid = %d AND v.vid != %d", $release->vid, $api_vid);
     $xml_terms = '';
     while ($term = db_fetch_object($term_query)) {
