/[drupal]/contributions/profiles/drupalorg_testing/drupalorg_testing_build_release_info.php
ViewVC logotype

Contents of /contributions/profiles/drupalorg_testing/drupalorg_testing_build_release_info.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Fri Mar 20 06:37:51 2009 UTC (8 months, 1 week ago) by thehunmonkgroup
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +14 -12 lines
File MIME type: text/x-php
273586 by hunmonk: Port Drupal.org testing profile to D6.  basically working.  needs to be converted to batch api, and more conversion to install profile api.
1 <?php
2 // $Id: drupalorg_testing_build_release_info.php,v 1.2 2009/03/17 22:38:07 thehunmonkgroup Exp $
3
4 /**
5 * @file
6 *
7 * This file uses the XML data from updates.drupal.org and parses
8 * those feeds to create the drupalorg_testing_release_info.inc file.
9 *
10 * This file is intended to be used from the command line and will
11 * not be called in the presence of a bootstrapped instance of drupal.
12 *
13 * The assumed workflow is that periodically someone will run this
14 * file from the command line and then provide a patch of the
15 * drupalorg_testing_release_info.inc file to the Drupal.org testing
16 * profile project at http://drupal.org/project/drupalorg_testing
17 *
18 * Alternately, if a user wants to create a test installation site
19 * with the most recent releases data, he can manually run
20 * this file himself, as doing so will update the
21 * drupalorg_testing_release_info.inc file.
22 *
23 * *** THIS SCRIPT REQUIRES PHP 5 OR ABOVE ***
24 */
25
26 // Ensure that the SimpleXML PHP extension is enabled. It is only available
27 // in PHP 5 or greater but is enabled by default.
28 if (!phpversion('SimpleXML')) {
29 exit(wordwrap("PHP 5 or greater is required to use this script. The SimpleXML extension must also be enabled. See http://us2.php.net/manual/en/book.simplexml.php for more information.\n"));
30 }
31
32 // URL to check updates at. This value should probably be the same
33 // as the UPDATE_STATUS_DEFAULT_URL in the update_status module on
34 // drupal.org.
35 define('BASE_URL', 'http://updates.drupal.org/release-history');
36
37 // An array of all project uris included in the drupalorg_testing
38 // profile for which releases should be created.
39 // NOTE: This array needs to be manually modified if a project
40 // is added to the Drupal.org testing profile.
41 $projects = array(
42 'drupal', 'drupalorg_testing', 'phptal', 'zen', 'af',
43 'project', 'project_issue', 'cvslog', 'subscribe', 'user_status',
44 );
45
46 // An array of all API compatability version taxonomy terms
47 // (as used on drupal.org) to create releases for.
48 // NOTE: When a new major version of Drupal is released,
49 // this array should be manually modified.
50 $api_terms = array('4.7.x', '5.x', '6.x');
51
52 $releases = array();
53 $supported_releases = array();
54
55 foreach ($projects as $project) {
56 foreach ($api_terms as $api_term) {
57 dot_get_releases($project, $api_term, $releases, $supported_releases);
58 }
59 }
60
61 // Build the string of text that will actually be written to the file.
62 $output = get_file_header();
63 $output .= "\n\n/**\n * Array of information about releases.\n */\n";
64 $output .= "\$releases = " . var_export($releases, TRUE) . ";\n";
65 $output .= "\n\n/**\n * Array of information about supported branches.\n */\n";
66 $output .= "\$supported_releases = " . var_export($supported_releases, TRUE) . ";\n";
67 $output .= "// End of file.";
68
69 // Write the drupalorg_testing_release_info.inc file.
70 $testing_releases = fopen('drupalorg_testing_release_info.inc', "w");
71 fwrite($testing_releases, $output);
72 fclose($testing_releases);
73
74 /**
75 * Retrieves the XML of releases for a given project
76 * and API compatability term and returns an array of
77 * releases.
78 *
79 * @param $project
80 * The uri (project short name) of the project to get releases for.
81 * @param $api_term
82 * The API compatability term to find releases for. eg. '4.7.x' or '5.x'.
83 * @param $releases
84 * An array containing information about each release of all projects.
85 * @param $supported_releases
86 * A nested array containing information about supported versions of
87 * each release series for each project.
88 *
89 * @return
90 * Nothing. The data is added to the $releases and $supported_releases
91 * arrays which are passed in by reference.
92 */
93 function dot_get_releases($project, $api_term, &$releases, &$supported_releases) {
94 // Get the XML for the given project and API term pair.
95 $url = BASE_URL ."/$project/$api_term";
96 $xmlstr = file_get_contents($url);
97 if (!empty($xmlstr)) {
98 $xml = new SimpleXMLElement($xmlstr);
99 if (!empty($xml->releases->release)) {
100 foreach ($xml->releases->release as $key => $value) {
101 $parsed_file_url = parse_url((string) $value->download_link);
102 $releases[] = array(
103 'title' => (string) $value->name,
104 'project_uri' => $project,
105 'categories' => get_categories($api_term, $value->terms),
106 'filename' => isset($parsed_file_url['path']) ? pathinfo($parsed_file_url['path'], PATHINFO_BASENAME) : '',
107 'filehash' => (string) $value->mdhash,
108 'filedate' => (int) $value->date,
109 'status' => (string) $value->status == 'published' ? 1 : 0,
110 'project_release' => array(
111 'version' => (string) $value->version,
112 'version_major' => (int) $value->version_major,
113 'version_minor' => isset($value->version_minor) ? (int) $value->version_minor : NULL,
114 'version_patch' => (int) $value->version_patch,
115 'version_extra' => (string) $value->version_extra,
116 'tag' => (string) $value->tag,
117 'rebuild' => (string) $value->version_extra == 'dev' ? 1 : 0,
118 ),
119 );
120 }
121 }
122
123 // Store supported versions information
124 $properties = array('project_status', 'recommended_major', 'supported_majors', 'default_major');
125 foreach ($properties as $property) {
126 $supported_releases[$project][$api_term][$property] = isset($xml->$property) ? (string) $xml->$property : NULL;
127 }
128 }
129 }
130
131 /**
132 * Build an array with all categories assigned to the release.
133 *
134 * @param $api_term
135 * The text value of the API term associated with the release.
136 * @param $terms
137 * A SimpleXML object representing the terms attribute of the release.
138 *
139 * @return
140 * An array with the text values of all terms associated with the release.
141 */
142 function get_categories($api_term, $terms) {
143 $all_terms = array();
144
145 // The API term does not come as part of $terms, so add that separately.
146 $all_terms[] = $api_term;
147
148 // Because $terms is a SimpleXML object containing SimpleXML objects
149 // it's necessary to cast it and its children parts to an array
150 // to handle them.
151 $terms = (array)$terms;
152 if (isset($terms['term'])) {
153 $terms = (array)$terms['term'];
154 foreach ($terms as $key => $value) {
155 if (is_numeric($key)) {
156 $value = (array)$value;
157 $all_terms[] = $value['value'];
158 }
159 elseif ($key == 'value') {
160 if (!empty($value)) {
161 $all_terms[] = $value;
162 }
163 }
164 }
165 }
166 return $all_terms;
167 }
168
169 /**
170 * Returns the text that goes at the top of drupalorg_testing_release_info.inc.
171 */
172 function get_file_header() {
173 $output = "<?php\n";
174 // Use a gratuitous string concatenation to fool CVS into leaving this keyword alone.
175 $output .= '// $Id: drupalorg_testing_build_release_info.php,v 1.2 2009/03/17 22:38:07 thehunmonkgroup Exp $'."\n\n";
176 $output .= '// Generated with: '. basename(__FILE__) ."\n";
177 $output .= '// Generated on: '. date('r') ."\n\n";
178 $file_phpdoc = <<<EOF
179 /**
180 * @file
181 *
182 * This file defines two arrays of information about project release nodes
183 * that should be created.
184 *
185 * This file is separate from the rest of the drupalorg_testing profile so
186 * that it can be easily regenerated by a script that uses the XML feed from
187 * updates.drupal.org to get actual data about project releases from
188 * drupal.org.
189 */
190
191 EOF;
192 $output .= $file_phpdoc;
193 return $output;
194 }

  ViewVC Help
Powered by ViewVC 1.1.2