Index: project-release-create-history.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/release/project-release-create-history.php,v
retrieving revision 1.9
diff -u -F^f -r1.9 project-release-create-history.php
--- project-release-create-history.php 22 Aug 2007 16:30:52 -0000 1.9
+++ project-release-create-history.php 27 Aug 2007 15:55:16 -0000
@@ -80,7 +80,7 @@ foreach ($vars as $name => $val) {
/// @todo Add command-line args to only generate a given project/version.
project_release_history_generate_all();
-
+project_list_generate();
// ------------------------------------------------------------
// Functions: main work
@@ -131,7 +131,7 @@ function project_release_history_generat
*/
function project_release_history_generate_project_xml($project_nid, $api_tid = NULL) {
$api_vid = _project_release_get_api_vid();
-
+
if (isset($api_tid)) {
// Restrict output to a specific API compatibility term.
$api_terms = project_release_compatibility_list();
@@ -142,7 +142,7 @@ function project_release_history_generat
$api_version = $api_terms[$api_tid];
// Get project-wide data:
- $sql = "SELECT n.title, n.nid, p.uri, prdv.major FROM {node} n INNER JOIN {project_projects} p ON n.nid = p.nid LEFT JOIN {project_release_default_versions} prdv ON prdv.nid = n.nid AND prdv.tid = %d WHERE p.nid = %d";
+ $sql = "SELECT n.title, n.nid, p.uri, prdv.major, u.name FROM {node} n INNER JOIN {project_projects} p ON n.nid = p.nid LEFT JOIN {project_release_default_versions} prdv ON prdv.nid = n.nid AND prdv.tid = %d INNER JOIN {users} u ON n.uid=u.uid WHERE p.nid = %d";
$query = db_query($sql, $api_tid, $project_nid);
if (!db_num_rows($query)) {
wd_err(t('Project ID %pid not found', array('%pid' => $project_nid)));
@@ -157,7 +157,7 @@ function project_release_history_generat
else {
// Consider all API compatibility terms.
$api_version = 'all';
- $sql = "SELECT n.title, n.nid, p.uri, prdv.major FROM {node} n INNER JOIN {project_projects} p ON n.nid = p.nid LEFT JOIN {project_release_default_versions} prdv ON prdv.nid = n.nid WHERE p.nid = %d";
+ $sql = "SELECT n.title, n.nid, p.uri, prdv.major, u.name FROM {node} n INNER JOIN {project_projects} p ON n.nid = p.nid LEFT JOIN {project_release_default_versions} prdv ON prdv.nid = n.nid INNER JOIN {users} u ON n.uid=u.uid WHERE p.nid = %d";
$query = db_query($sql, $project_nid);
if (!db_num_rows($query)) {
wd_err(t('Project ID %pid not found', array('%pid' => $project_nid)));
@@ -174,6 +174,12 @@ function project_release_history_generat
$xml .= '
'. check_plain($project->title) ."\n";
$xml .= ''. check_plain($project->uri) ."\n";
$xml .= ''. url("node/$project->nid", NULL, NULL, TRUE) ."\n";
+ $xml .= "$project->name\n";
+ $terms = taxonomy_node_get_terms_by_vocabulary($project->nid, _project_get_vid());
+ foreach ($terms as $term) {
+ $taxonomy_url = url("taxonomy/$term->tid", NULL, NULL, TRUE);
+ $xml .= "$term->name\n";
+ }
$xml .= ''. check_plain($api_version) ."\n";
$xml .= "$project->major\n";
$xml .= "\n";
@@ -273,7 +279,7 @@ function project_release_history_generat
$xml .= " \n";
}
$xml .= "\n\n";
- project_release_history_write_xml($project, $api_version, $xml);
+ project_release_history_write_xml($xml, $project, $api_version);
}
@@ -287,29 +293,47 @@ function project_release_history_generat
* @param $xml
* String containing the XML representation of the history.
*/
-function project_release_history_write_xml($project, $api_version, $xml) {
+function project_release_history_write_xml($xml, $project = NULL, $api_version = NULL) {
- // Setup the filenames we'll be using. Normally, we'd have to be
- // extra careful with $project->uri to avoid malice here, however,
- // that's validated on the project edit form to prevent any funny
- // characters, so that much is safe. The rest of these paths are
- // just from the global variables at the top of this script, so we
- // can trust those. The only one we should be careful of is the
- // taxonomy term for the API compatibility.
- $safe_api_vers = strtr($api_version, '/', '_');
- $project_dir = BASE_DIRECTORY .'/'. $project->uri;
- $project_id = $project->uri .'-'. $safe_api_vers .'.xml';
- $filename = $project_dir .'/'. $project_id;
- $tmp_filename = $filename .'.new';
+ if (!isset($project)) {
+ // We are outputting a global project list.
+ $project_dir = BASE_DIRECTORY .'/project-list';
+ $filename = $project_dir .'/project-list-all.xml';
+ $tmp_filename = $filename .'.new';
+ $errors = array(
+ 'mkdir' => t("ERROR: mkdir(@dir) failed, can't write project list.", array('@dir' => $project_dir)),
+ 'unlink' => t("ERROR: unlink(@file) failed, can't write project list.", array('@file' => $tmp_filename)),
+ 'rename' => t("ERROR: rename(@old, @new) failed, can't write project list.", array('@old' => $tmp_filename, '@new' => $filename))
+ );
+ }
+ else {
+ // Setup the filenames we'll be using. Normally, we'd have to be
+ // extra careful with $project->uri to avoid malice here, however,
+ // that's validated on the project edit form to prevent any funny
+ // characters, so that much is safe. The rest of these paths are
+ // just from the global variables at the top of this script, so we
+ // can trust those. The only one we should be careful of is the
+ // taxonomy term for the API compatibility.
+ $safe_api_vers = strtr($api_version, '/', '_');
+ $project_dir = BASE_DIRECTORY .'/'. $project->uri;
+ $project_id = $project->uri .'-'. $safe_api_vers .'.xml';
+ $filename = $project_dir .'/'. $project_id;
+ $tmp_filename = $filename .'.new';
+ $errors = array(
+ 'mkdir' => t("ERROR: mkdir(@dir) failed, can't write history for %project.", array('@dir' => $project_dir, '%project' => $project->title)),
+ 'unlink' => t("ERROR: unlink(@file) failed, can't write history for %project.", array('@file' => $tmp_filename, '%project' => $project->title)),
+ 'rename' => t("ERROR: rename(@old, @new) failed, can't write history for %project.", array('@old' => $tmp_filename, '@new' => $filename, '%project' => $project->title))
+ );
+ }
// Make sure we've got the right project-specific subdirectory.
if (!is_dir($project_dir) && !mkdir($project_dir)) {
- wd_err(t("ERROR: mkdir(@dir) failed, can't write history for %project.", array('@dir' => $project_dir, '%project' => $project->title)));
+ wd_err($errors['mkdir']);
return FALSE;
}
// Make sure the "[project]-[version].xml.new" file doesn't exist.
if (is_file($tmp_filename) && !unlink($tmp_filename)) {
- wd_err(t("ERROR: unlink(@file) failed, can't write history for %project.", array('@file' => $tmp_filename, '%project' => $project->title)));
+ wd_err($errors['unlink']);
return FALSE;
}
// Write the XML history to "[project]-[version].xml.new".
@@ -326,12 +350,51 @@ function project_release_history_write_x
// Now we can atomically rename the .new into place in the "live" spot.
if (!_rename($tmp_filename, $filename)) {
- wd_err(t("ERROR: rename(@old, @new) failed, can't write history for %project.", array('@old' => $tmp_filename, '@new' => $filename, '%project' => $project->title)));
+ wd_err($errors['rename']);
return FALSE;
}
return TRUE;
}
+/**
+ * Generate a list of all projects available on this server.
+ */
+function project_list_generate() {
+ $api_vid = _project_release_get_api_vid();
+
+ $query = db_query("SELECT n.title, n.nid, p.uri, u.name FROM {node} n INNER JOIN {project_projects} p ON n.nid = p.nid INNER JOIN {users} u ON n.uid=u.uid WHERE n.status = 1");
+ if (!db_num_rows($query)) {
+ wd_err(t('No projects found on this server.'));
+ return FALSE;
+ }
+ $xml = "\n";
+ while ($project = db_fetch_object($query)) {
+ $xml .= " \n";
+ $xml .= ' '. check_plain($project->title) ."\n";
+ $xml .= ' '. check_plain($project->uri) ."\n";
+ $xml .= ' '. url("node/$project->nid", NULL, NULL, TRUE) ."\n";
+ $xml .= " $project->name\n";
+ $terms = taxonomy_node_get_terms_by_vocabulary($project->nid, _project_get_vid());
+ foreach ($terms as $term) {
+ $taxonomy_url = url("taxonomy/$term->tid", NULL, NULL, TRUE);
+ $xml .= "$term->name\n";
+ }
+
+ // Include a list of API terms if available.
+ $term_query = db_query("SELECT DISTINCT(td.tid), td.name AS term_name FROM {project_release_nodes} prn INNER JOIN {term_node} tn ON prn.nid = tn.nid INNER JOIN {term_data} td ON tn.tid = td.tid WHERE prn.pid = %d AND td.vid = %d ORDER BY td.weight ASC", $project->nid, $api_vid);
+ $xml_api_terms = '';
+ while ($api_term = db_fetch_object($term_query)) {
+ $xml_api_terms .= ' '. check_plain($api_term->term_name) ."\n";
+ }
+ if (!empty($xml_api_terms)) {
+ $xml .= " \n". $xml_api_terms ." \n";
+ }
+
+ $xml .= " \n";
+ }
+ $xml .= "\n";
+ project_release_history_write_xml($xml);
+}
// ------------------------------------------------------------
// Functions: utility methods