Index: drupalorg_project/drupalorg_project.install
===================================================================
RCS file: /Users/wright/drupal/local_repo/contributions/modules/drupalorg/drupalorg_project/drupalorg_project.install,v
retrieving revision 1.2
diff -u -p -r1.2 drupalorg_project.install
--- drupalorg_project/drupalorg_project.install	26 Oct 2010 21:51:44 -0000	1.2
+++ drupalorg_project/drupalorg_project.install	24 Dec 2010 13:49:01 -0000
@@ -35,3 +35,71 @@ function drupalorg_project_update_6000()
   return $ret;
 }
 
+/**
+ * Properly initialize the {project_release_file}.weight column.
+ *
+ * On drupal.org, for installation profiles with multiple files per
+ * release (fully packaged distributions), we want the full profile
+ * (including core and all required projects) to have the lightest
+ * weight and float to the top. We want the projects + profile
+ * versions to be heavier and sink a bit, and the profile-only
+ * versions to sink to the bottom.
+ */
+function drupalorg_project_update_6001() {
+  $ret = array();
+
+  // We can't run these updates via a subselect, since the subselect
+  // needs to JOIN on {project_release_file}, too. There aren't *that*
+  // many records, so we just query them first, store the fids in RAM,
+  // then manually update those via separate queries.
+
+  // First, find all the files (and nids) of releases from install profile
+  // projects that includes the string '-no-core.tar'. All of these fids need
+  // to have a weight of 6, and we'll use the nids to know all the fully
+  // packaged distro releases so we can set the plain profile-only files to a
+  // heavier weight.
+  $query = db_query("SELECT prf.fid, prf.nid FROM {project_release_file} prf INNER JOIN {files} f ON prf.fid = f.fid INNER JOIN {project_release_nodes} prn ON prf.nid = prn.nid INNER JOIN {term_node} tn ON prn.pid = tn.nid WHERE tn.tid = 96 AND f.filename RLIKE '-no-core.tar'");
+
+  // Stash these fids (and nids) in a nested PHP array. We chunk them into
+  // arrays of 100 so that we can do reasonable IN queries when running the
+  // updates.
+  $i = 0;
+  $bucket_id = 0;
+  $fids = array();
+  $nids = array();
+  while ($file = db_fetch_object($query)) {
+    if (empty($nids[$bucket_id])) {
+      $fids[$bucket_id] = array();
+      $nids[$bucket_id] = array();
+    }
+    $fids[$bucket_id][] = $file->fid;
+    $nids[$bucket_id][] = $file->nid;
+    if ($i >= 100) {
+      $bucket_id++;
+    }
+  }
+
+  // Now that we've got all the fids and nids we're looking for, we can first
+  // update all the fids to set the -no-core packages to weight 6.
+  foreach ($fids as $fid_array) {
+    $placeholders = db_placeholders($fid_array);
+    db_query("UPDATE {project_release_file} SET weight = 6 WHERE fid IN (" . $placeholders .")", $fid_array);
+  }
+
+  // Then, using our array of nids of packaged distribution releases, find all
+  // the profile-only files and set those to weight 10.
+  foreach ($nids as $nid_array) {
+    // Run a new query to find the fids we need to update for this batch. We
+    // just make sure the nid is in the nid_array, and that the filename
+    // doesn't include '-core.tar' since that will exclude both -no-core.tar
+    // and -core.tar.
+    $query = db_query("SELECT prf.fid FROM {project_release_file} prf INNER JOIN {files} f ON prf.fid = f.fid WHERE f.filename NOT RLIKE '-core.tar' AND prf.nid IN (" . db_placeholders($nid_array) . ")", $nid_array);
+    $profile_only_fids = array();
+    while ($file = db_fetch_object($query)) {
+      $profile_only_fids[] = $file->fid;
+    }
+    db_query("UPDATE {project_release_file} SET weight = 10 WHERE fid IN (" . db_placeholders($profile_only_fids) .")", $profile_only_fids);
+  }
+
+  return $ret;
+}
