/[drupal]/contributions/modules/cvslog/cvs_local.example.inc
ViewVC logotype

Contents of /contributions/modules/cvslog/cvs_local.example.inc

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


Revision 1.11 - (show annotations) (download) (as text)
Tue Mar 3 19:55:58 2009 UTC (8 months, 3 weeks ago) by dww
Branch: MAIN
Changes since 1.10: +5 -8 lines
File MIME type: text/x-php
#390032 by dww: Fixed a bug where non-admins could no longer edit a
HEAD release node to move the "CVS branch" field to a more specific
branch (e.g. moving a HEAD node called "6.x-1.x-dev" to DRUPAL-6--1).
1 <?php
2 // $Id: cvs_local.example.inc,v 1.10 2009/01/29 18:57:45 dww Exp $
3
4 /**
5 * @file
6 * Site-specific code that needs to be customized. The really
7 * egregious hacks for running on drupal.org are all in here.
8 * So, if you're setting up the cvs.module on another site, chances
9 * are good you'll want to modify or replace the functions in here
10 * with something appropriate for your needs.
11 *
12 */
13
14 /**
15 * Returns an object of version number values based on the given tag.
16 */
17 function cvs_local_get_version_from_tag($tag, $project) {
18 // First, split on '--', if it's there, that tells us API vs. regular
19 list($first_ver, $second_ver) = explode('--', $tag->tag);
20 $first = explode('-', $first_ver, 5);
21 $second = empty($second_ver) ? array() : explode('-', $second_ver, 3);
22
23 if ($project->nid == 3060) {
24 if ($first[1] >= 5) {
25 $version->version_major = $first[1];
26 if (isset($first[2])) {
27 $version->version_patch = $first[2];
28 $version->version_extra = _cvs_get_extra($first[3].$first[4]);
29 }
30 else {
31 $version->version_patch = 'x';
32 $version->version_extra = 'dev';
33 }
34 }
35 else {
36 if (isset($first[3])) {
37 // Looks like "DRUPAL-X-Y-Z". Ignore the 'DRUPAL' part in $first[0].
38 $version->version_major = $first[1];
39 $version->version_minor = $first[2];
40 $version->version_patch = $first[3];
41 $version->version_extra = _cvs_get_extra($first[4]);
42 }
43 else {
44 // Looks like "DRUPAL-X-Y", must be like "DRUPAL-4-7" (branch)
45 $version->version_major = $first[1];
46 $version->version_minor = $first[2];
47 $version->version_patch = 'x';
48 $version->version_extra = 'dev';
49 }
50 }
51 }
52 else {
53 // Contrib tags don't need any special cases. If there's nothing
54 // after the '--' (the default stable branch), we want "-1.x-dev".
55 $version->version_major = isset($second[0]) ? $second[0] : 1;
56 $version->version_patch = isset($second[1]) ? $second[1] : 'x';
57 $version->version_extra = $tag->branch ? 'dev' : _cvs_get_extra($second[2]);
58 }
59 if ($tree = project_release_get_api_taxonomy()) {
60 // If we're using the compatibility taxonomy, find the right tid.
61 // For both core and contrib, it's set by what we saw before the '--',
62 // namely, the stuff in the $first array...
63 if (!isset($first[2]) || ($project->nid == 3060 && $first[1] >= 5)) {
64 $target = "$first[1].x";
65 }
66 else {
67 $target = "$first[1].$first[2].x";
68 }
69 foreach ($tree as $i => $term) {
70 if ($term->name == $target) {
71 $version->version_api_tid = $term->tid;
72 break;
73 }
74 }
75 }
76 // TODO: add code to validate we parsed something reasonable, and ignore bad tags.
77 return $version;
78 }
79
80 /**
81 * Returns the CVS tag that should match the given version information
82 */
83 function cvs_local_get_tag_from_version($version, $project) {
84 $tag = 'DRUPAL-'; // all tags start with this.
85 $parts[] = $version->version_major;
86 if (isset($version->version_minor)) {
87 $parts[] = $version->version_minor;
88 }
89 if (isset($version->version_patch)) {
90 $parts[] = $version->version_patch;
91 }
92 else {
93 $is_branch = TRUE;
94 }
95 if (isset($version->version_extra)) {
96 if ($version->version_extra != 'dev') {
97 $parts[] = strtoupper($version->version_extra);
98 // sadly, this will be wrong, since we strip out '_' and '-',
99 // but we don't really care that much, since this is primarily
100 // going to be used for branches, not tags.
101 }
102 else {
103 $is_branch = TRUE;
104 }
105 }
106 if ($project->nid != 3060) {
107 // For contrib, we have to prepend the Drupal core compatibility.
108 if (!empty($version->version_api_tid)) {
109 $term = taxonomy_get_term($version->version_api_tid);
110 $api = preg_replace(array('/\.x/', '/\./'), array('', '-'), $term->name);
111 $tag .= $api;
112 }
113 if ($is_branch && $api < 6 && $version->version_major == 1) {
114 // Evil special-case, we're done.
115 return $tag;
116 }
117 $tag .= '--';
118 }
119 $tag .= implode('-', $parts);
120 return $tag;
121 }
122
123 function _cvs_get_extra($str) {
124 return preg_replace('/[_-]/', '', strtolower($str));
125 }
126
127 /**
128 * drupal.org specific customizations of the release node form
129 */
130 function cvs_local_alter_project_release_form(&$form, &$form_state) {
131 $node = $form['#node'];
132 if (isset($node->project_release['tag'])) {
133 $tag = $node->project_release['tag'];
134 }
135 elseif (isset($form_state['values']['cvs_tag']['tag'])) {
136 $tag = $form_state['values']['cvs_tag']['tag'];
137 }
138 if (isset($tag) && $tag === 'HEAD') {
139 $form['version']['num']['#description'] = t('For releases being rebuilt from the trunk of the CVS repository (HEAD), you must use "x" for the %patch version and "dev" in the %extra to indicate it is a development snapshot. Furthermore, you should probably use "1" for the %major version to indicate that this is the initial version compatible with the selected version of Drupal core, unless you are using HEAD as a place to develop new features still compatible with a previous version of core, in which case you should use "2" or higher, as appropriate.', array('%major' => t('Major'), '%patch' => t('Patch-level'), '%extra' => t('Extra identifier')));
140 unset($form['project_release']['version_extra']['#description']);
141 }
142 }
143
144 function cvs_local_project_release_form_pre_render(&$form) {
145 $form['version']['num']['version_major']['#required'] = TRUE;
146 $form['version']['num']['version_patch']['#required'] = TRUE;
147 }
148
149 /**
150 * Decides if the given version object has enough information for
151 * us to move on to the next page.
152 */
153 function cvs_local_version_is_valid($version, $tag, $project) {
154 if (empty($version)) {
155 return FALSE;
156 }
157 $is_valid = TRUE;
158 if ($project->nid == 3060) {
159 // Core is obvious: we just need to ensure we've got major and patch.
160 // Everything else is optional.
161 if (!isset($version->version_major)) {
162 $is_valid = FALSE;
163 form_set_error('version_major', t('Major version number is required.'));
164 }
165 elseif ($version->version_major >= 5 && isset($version->version_minor)) {
166 form_set_error('version_minor', t('You should not specify a minor version number if the major version is greater than or equal to 5.'));
167 $is_valid = FALSE;
168 }
169 if (!isset($version->version_patch)) {
170 $is_valid = FALSE;
171 form_set_error('version_patch', t('Patch-level version number is required.'));
172 }
173 }
174 else {
175 if (!isset($version->version_api_tid)) {
176 $is_valid = FALSE;
177 $vid = _project_release_get_api_vid();
178 if (isset($_POST['taxonomy'][$vid])) {
179 // We only want to flag an error if they've tried to advance
180 form_set_error($vid, t('You must select what version of Drupal core this release is compatible with.'));
181 }
182 }
183 if (!isset($version->version_major)) {
184 $is_valid = FALSE;
185 form_set_error('version_major', t('Major version number is required, and must be a number.'));
186 }
187 if (!isset($version->version_patch)) {
188 $is_valid = FALSE;
189 form_set_error('version_patch', t('Patch-level version number is required, and must be either a number or the letter "x".'));
190 }
191 }
192 if ($tag->branch) {
193 if ($version->version_patch != 'x') {
194 $is_valid = FALSE;
195 form_set_error('version_patch', t('The %patch must be "x" for snapshot releases from a branch (or HEAD).', array('%patch' => 'Patch-level')));
196 }
197 if ($version->version_extra != 'dev') {
198 $is_valid = FALSE;
199 form_set_error('version_extra', t('The %extra must be "dev" for snapshot releases from a branch (or HEAD).', array('%extra' => 'Extra identifier')));
200 }
201 }
202 if ($is_valid) {
203 $version->pid = $project->nid;
204 if (project_release_exists($version)) {
205 // TODO: is there a better form element to mark with this error?
206 form_set_error('version_patch', t('This version already exists for this project.'));
207 $is_valid = FALSE;
208 }
209 }
210 return $is_valid;
211 }
212

  ViewVC Help
Powered by ViewVC 1.1.2