? dot_generate_releases.patch ? dot_generate_releases_2.patch ? dot_generate_releases_3.patch ? dot_pr_type_multiple.patch ? test.txt Index: /Applications/MAMP/htdocs/rg/drupal/profiles/drupalorg_testing/drupalorg_testing.profile =================================================================== RCS file: /cvs/drupal-contrib/contributions/profiles/drupalorg_testing/drupalorg_testing.profile,v retrieving revision 1.40 diff -u -p -r1.40 drupalorg_testing.profile --- drupalorg_testing.profile 21 Mar 2008 02:03:42 -0000 1.40 +++ drupalorg_testing.profile 1 Apr 2008 03:03:41 -0000 @@ -569,6 +569,7 @@ function _drupalorg_testing_create_conte devel_generate_content(100, 200, 8, TRUE, array('page', 'story', 'forum')); _drupalorg_testing_create_content_project(); + _drupalorg_testing_create_content_project_release(); } /** @@ -674,11 +675,9 @@ function _drupalorg_testing_create_issue * Generates sample project content. */ function _drupalorg_testing_create_content_project() { - // Disable comments and file attachments on project_project and project_release nodes. + // Disable comments and file attachments on project_project nodes. variable_set('comment_project_project', COMMENT_NODE_DISABLED); variable_set('upload_project_project', 0); - variable_set('comment_project_release', COMMENT_NODE_DISABLED); - variable_set('upload_project_release', 0); // First, add one of each type of project. $values[t('Drupal project')] = array( @@ -814,6 +813,99 @@ The first case is especially useful for } /** + * Generates sample project release nodes. + */ +function _drupalorg_testing_create_content_project_release() { + // Disable comments and file attachments on project_release nodes. + variable_set('comment_project_release', COMMENT_NODE_DISABLED); + variable_set('upload_project_release', 0); + + // Create the project directory under the files directory so that + // files for releases can later be created there. + $directory = variable_get('file_directory_path', 'files') . '/project'; + file_check_directory($directory, FILE_CREATE_DIRECTORY); + + $file = drupal_get_path('profile', 'drupalorg_testing') .'/drupalorg_testing_releases.inc'; + if (file_exists($file)) { + require_once($file); + + // Retrieve a list of projects on the site. + $result = db_query("SELECT n.nid, pp.uri, u.name FROM {node} n INNER JOIN {project_projects} pp ON n.nid = pp.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.type = 'project_project'"); + $projects = array(); + while ($project = db_fetch_array($result)) { + $projects[$project['uri']] = $project; + } + + // Grab an array of information on releases used in this profile. + $releases = drupalorg_testing_get_releases(); + + foreach ($releases as $release) { + // Some fields of the release node haven't been set yet, so set those here. + $release['pid'] = $projects[$release['project_uri']]['nid']; + + // All releases will be created by the same user who created the parent project. + $release['name'] = $projects[$release['project_uri']]['name']; + + // Set the date/time of the release to be the same as that of the file. + $release['date'] = format_date($release['file_date'], 'custom', 'Y-m-d H:i:s O'); + + $release['body'] = "Ideally this would be some random text or the actual body of the release node on drupal.org."; + + // Build the full file path of the file associated with the release. + $full_path = $directory .'/'. $release['file_name']; + $release['file_path'] = $full_path; + + // Determine the tids of all categories associated with the release. + $categories = array(); + foreach ($release['categories'] as $category) { + $categories[] = _drupalorg_testing_get_tid_by_term($category); + } + $release['type'] = 'project_release'; + drupal_execute('project_release_node_form', $release, $release); + + // CHEESY HACK: Because Drupal is not fully bootstrapped at install time, + // we have to do raw DB manipulation to add the terms and cvs related stuff. Sigh... + $node = node_load(array('title' => $release['title'])); + foreach ($categories as $tid) { + db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $node->nid, $tid); + } + // Put an entry for this tag/branch in {cvs_tags} + db_query("INSERT INTO {cvs_tags} (nid, tag, branch) VALUES (%d, '%s', %d)", $node->nid, $release['tag'], $release['rebuild']); + + // Automatically create an empty file for each release. + touch($release['file_path'], $release['file_date']); + drupal_set_message(t('A file for the release titled %title was created at %full_path.', array('%title' => $release['title'], '%full_path' => $release['file_path']))); + + // Manually put file and version info into db since drupal_execute() doesn't seem to add this information. + db_query("UPDATE {project_release_nodes} SET file_path = '%s', file_date = %d, file_hash = '%s', rebuild = %d, version_major = %d, version_minor = %d, version_patch = %d, version_extra = '%s' WHERE nid = %d", $release['file_path'], $release['file_date'], $release['file_hash'], $release['rebuild'], $release['major'], $release['minor'], $release['patch'], $release['extra'], $node->nid); + } + + // Grab an array of information about which releases for projects used in + // this profile are supported, recommended, or unsupported. + // Then add this information to the {project_release_supported_versions} table. + $supported_releases = drupalorg_testing_get_supported_releases(); + foreach ($supported_releases as $uri => $version) { + $pid = $projects[$uri]['nid']; + foreach ($version as $term => $data) { + $tid = _drupalorg_testing_get_tid_by_term($term); + if (!empty($data['supported_majors'])) { + $supported_majors = explode(',', $data['supported_majors']); + foreach ($supported_majors as $major) { + if (!empty($data['recommended_major']) && ($major == $data['recommended_major'])) { + $recommended = 1; + } + else { + $recommended = 0; + } + db_query('INSERT INTO {project_release_supported_versions} (nid, tid, major, supported, recommended, snapshot) VALUES (%d, %d, %d, %d, %d, %d)', $pid, $tid, $major, 1, $recommended, 1); + } + } + } + } + } +} + +/** * Setup menus to match drupal.org. */ function _drupalorg_testing_create_menus() { Index: /Applications/MAMP/htdocs/rg/drupal/profiles/drupalorg_testing/drupalorg_testing_build_releases.php =================================================================== RCS file: drupalorg_testing_build_releases.php diff -N drupalorg_testing_build_releases.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ drupalorg_testing_build_releases.php 1 Apr 2008 03:03:41 -0000 @@ -0,0 +1,223 @@ +releases->release)) { + foreach ($xml->releases->release as $key => $value) { + $releases[] = array( + 'title' => (string) $value->name, + 'version' => (string) $value->version, + 'project_uri' => $project, + 'major' => (int) $value->version_major, + 'patch' => (int) $value->version_patch, + 'extra' => (string) $value->version_extra, + 'categories' => get_categories($api_term, $value->terms), + 'tag' => (string) $value->tag, + 'rebuild' => (string) $value->version_extra == 'dev' ? 1 : 0, + 'file_name' => get_file_name((string) $value->download_link), + 'file_hash' => (string) $value->mdhash, + 'file_date' => (int) $value->date, + 'status' => (string) $value->status == 'published' ? 1 : 0, + ); + } + } + + // Store supported versions information + $properties = array('project_status', 'recommended_major', 'supported_majors', 'default_major'); + foreach ($properties as $property) { + $supported_releases[$project][$api_term][$property] = isset($xml->$property) ? (string) $xml->$property : NULL; + } + } + return $releases; +} + +/** + * Extract the file name from the download URL of the file. + * + * @param $download_link + * A link to the file. For example, ftp://ftp.example.com/path/to/file/drupal-5.6.tar.gz + * + * @return + * The name of the file. For example, drupal-5.6.tar.gz. + */ +function get_file_name($download_link) { + return substr($download_link, (strripos($download_link, '/') + 1)); +} + +/** + * Build an array with all categories assigned to the release. + * + * @param $api_term + * The text value of the API term associated with the release. + * @param $terms + * A SimpleXML object representing the terms attribute of the release. + * + * @return + * An array with the text values of all terms associated with the release. + */ +function get_categories($api_term, $terms) { + $all_terms = array(); + + // The API term does not come as part of $terms, so add that separately. + $all_terms[] = $api_term; + + $terms = object_to_array($terms); + foreach ($terms['term'] as $key => $value) { + if (is_numeric($key)) { + $all_terms[] = $value['value']; + } + elseif ($key == 'value') { + if (!empty($value)) { + $all_terms[] = $value; + } + } + } + + return $all_terms; +} + +/** + * Converts an object into an array. + */ +function object_to_array($object) { + $return = NULL; + + if(is_array($object)) { + foreach($object as $key => $value) { + $return[$key] = object_to_array($value); + } + } + else { + $var = get_object_vars($object); + + if($var) { + foreach($var as $key => $value) { + $return[$key] = object_to_array($value); + } + } + else { + return strval($object); + } + } + return $return; +} + +/** + * Returns the text that goes at the top of drupalorg_testing_releases.inc. + */ +function get_file_header() { + $output = "