Index: modules/project/release/project-release-create-history.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/release/project-release-create-history.php,v retrieving revision 1.4 diff -u -p -r1.4 project-release-create-history.php --- modules/project/release/project-release-create-history.php 13 Jul 2007 01:05:22 -0000 1.4 +++ modules/project/release/project-release-create-history.php 13 Jul 2007 01:23:46 -0000 @@ -80,7 +80,7 @@ if (!is_dir(BASE_DIRECTORY)) { /// @todo Add command-line args to only generate a given project/version. project_release_history_generate_all(); - +project_list_generate(); // ------------------------------------------------------------ // Functions: main work @@ -209,7 +209,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); } @@ -223,29 +223,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". @@ -262,12 +280,33 @@ 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() { + $query = db_query("SELECT n.title, n.nid, p.uri FROM {node} n INNER JOIN {project_projects} p ON n.nid = p.nid"); + 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 .= " \n"; + } + $xml .= "\n"; + project_release_history_write_xml($xml); +} + // ------------------------------------------------------------ // Functions: utility methods