webmaster@1
|
1 <?php |
webmaster@1
|
2 // $Id: update.compare.inc,v 1.8 2008/02/03 19:34:02 goba Exp $ |
webmaster@1
|
3 |
webmaster@1
|
4 /** |
webmaster@1
|
5 * @file |
webmaster@1
|
6 * Code required only when comparing available updates to existing data. |
webmaster@1
|
7 */ |
webmaster@1
|
8 |
webmaster@1
|
9 /** |
webmaster@1
|
10 * Fetch an array of installed and enabled projects. |
webmaster@1
|
11 * |
webmaster@1
|
12 * This is only responsible for generating an array of projects (taking into |
webmaster@1
|
13 * account projects that include more than one module or theme). Other |
webmaster@1
|
14 * information like the specific version and install type (official release, |
webmaster@1
|
15 * dev snapshot, etc) is handled later in update_process_project_info() since |
webmaster@1
|
16 * that logic is only required when preparing the status report, not for |
webmaster@1
|
17 * fetching the available release data. |
webmaster@1
|
18 * |
webmaster@1
|
19 * @see update_process_project_info() |
webmaster@1
|
20 * @see update_calculate_project_data() |
webmaster@1
|
21 * |
webmaster@1
|
22 */ |
webmaster@1
|
23 function update_get_projects() { |
webmaster@1
|
24 static $projects = array(); |
webmaster@1
|
25 if (empty($projects)) { |
webmaster@1
|
26 // Retrieve the projects from cache, if present. |
webmaster@1
|
27 $projects = update_project_cache('update_project_projects'); |
webmaster@1
|
28 if (empty($projects)) { |
webmaster@1
|
29 // Still empty, so we have to rebuild the cache. |
webmaster@1
|
30 _update_process_info_list($projects, module_rebuild_cache(), 'module'); |
webmaster@1
|
31 _update_process_info_list($projects, system_theme_data(), 'theme'); |
webmaster@1
|
32 // Set the projects array into the cache table. |
webmaster@1
|
33 cache_set('update_project_projects', $projects, 'cache_update', time() + 3600); |
webmaster@1
|
34 } |
webmaster@1
|
35 } |
webmaster@1
|
36 return $projects; |
webmaster@1
|
37 } |
webmaster@1
|
38 |
webmaster@1
|
39 /** |
webmaster@1
|
40 * Populate an array of project data. |
webmaster@1
|
41 */ |
webmaster@1
|
42 function _update_process_info_list(&$projects, $list, $project_type) { |
webmaster@1
|
43 foreach ($list as $file) { |
webmaster@1
|
44 if (empty($file->status)) { |
webmaster@1
|
45 // Skip disabled modules or themes. |
webmaster@1
|
46 continue; |
webmaster@1
|
47 } |
webmaster@1
|
48 |
webmaster@1
|
49 // Skip if the .info file is broken. |
webmaster@1
|
50 if (empty($file->info)) { |
webmaster@1
|
51 continue; |
webmaster@1
|
52 } |
webmaster@1
|
53 |
webmaster@1
|
54 // If the .info doesn't define the 'project', try to figure it out. |
webmaster@1
|
55 if (!isset($file->info['project'])) { |
webmaster@1
|
56 $file->info['project'] = update_get_project_name($file); |
webmaster@1
|
57 } |
webmaster@1
|
58 |
webmaster@1
|
59 // If we still don't know the 'project', give up. |
webmaster@1
|
60 if (empty($file->info['project'])) { |
webmaster@1
|
61 continue; |
webmaster@1
|
62 } |
webmaster@1
|
63 |
webmaster@1
|
64 // If we don't already know it, grab the change time on the .info file |
webmaster@1
|
65 // itself. Note: we need to use the ctime, not the mtime (modification |
webmaster@1
|
66 // time) since many (all?) tar implementations will go out of their way to |
webmaster@1
|
67 // set the mtime on the files it creates to the timestamps recorded in the |
webmaster@1
|
68 // tarball. We want to see the last time the file was changed on disk, |
webmaster@1
|
69 // which is left alone by tar and correctly set to the time the .info file |
webmaster@1
|
70 // was unpacked. |
webmaster@1
|
71 if (!isset($file->info['_info_file_ctime'])) { |
webmaster@1
|
72 $info_filename = dirname($file->filename) .'/'. $file->name .'.info'; |
webmaster@1
|
73 $file->info['_info_file_ctime'] = filectime($info_filename); |
webmaster@1
|
74 } |
webmaster@1
|
75 |
webmaster@1
|
76 $project_name = $file->info['project']; |
webmaster@1
|
77 if (!isset($projects[$project_name])) { |
webmaster@1
|
78 // Only process this if we haven't done this project, since a single |
webmaster@1
|
79 // project can have multiple modules or themes. |
webmaster@1
|
80 $projects[$project_name] = array( |
webmaster@1
|
81 'name' => $project_name, |
webmaster@1
|
82 'info' => $file->info, |
webmaster@1
|
83 'datestamp' => isset($file->info['datestamp']) ? $file->info['datestamp'] : 0, |
webmaster@1
|
84 'includes' => array($file->name => $file->info['name']), |
webmaster@1
|
85 'project_type' => $project_name == 'drupal' ? 'core' : $project_type, |
webmaster@1
|
86 ); |
webmaster@1
|
87 } |
webmaster@1
|
88 else { |
webmaster@1
|
89 $projects[$project_name]['includes'][$file->name] = $file->info['name']; |
webmaster@1
|
90 $projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']); |
webmaster@1
|
91 } |
webmaster@1
|
92 } |
webmaster@1
|
93 } |
webmaster@1
|
94 |
webmaster@1
|
95 /** |
webmaster@1
|
96 * Given a $file object (as returned by system_get_files_database()), figure |
webmaster@1
|
97 * out what project it belongs to. |
webmaster@1
|
98 * |
webmaster@1
|
99 * @see system_get_files_database() |
webmaster@1
|
100 */ |
webmaster@1
|
101 function update_get_project_name($file) { |
webmaster@1
|
102 $project_name = ''; |
webmaster@1
|
103 if (isset($file->info['project'])) { |
webmaster@1
|
104 $project_name = $file->info['project']; |
webmaster@1
|
105 } |
webmaster@1
|
106 elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core -') !== FALSE)) { |
webmaster@1
|
107 $project_name = 'drupal'; |
webmaster@1
|
108 } |
webmaster@1
|
109 elseif (in_array($file->name, array('bluemarine', 'chameleon', 'garland', 'marvin', 'minnelli', 'pushbutton'))) { |
webmaster@1
|
110 // Unfortunately, there's no way to tell if a theme is part of core, |
webmaster@1
|
111 // so we must hard-code a list here. |
webmaster@1
|
112 $project_name = 'drupal'; |
webmaster@1
|
113 } |
webmaster@1
|
114 return $project_name; |
webmaster@1
|
115 } |
webmaster@1
|
116 |
webmaster@1
|
117 /** |
webmaster@1
|
118 * Process the list of projects on the system to figure out the currently |
webmaster@1
|
119 * installed versions, and other information that is required before we can |
webmaster@1
|
120 * compare against the available releases to produce the status report. |
webmaster@1
|
121 * |
webmaster@1
|
122 * @param $projects |
webmaster@1
|
123 * Array of project information from update_get_projects(). |
webmaster@1
|
124 */ |
webmaster@1
|
125 function update_process_project_info(&$projects) { |
webmaster@1
|
126 foreach ($projects as $key => $project) { |
webmaster@1
|
127 // Assume an official release until we see otherwise. |
webmaster@1
|
128 $install_type = 'official'; |
webmaster@1
|
129 |
webmaster@1
|
130 $info = $project['info']; |
webmaster@1
|
131 |
webmaster@1
|
132 if (isset($info['version'])) { |
webmaster@1
|
133 // Check for development snapshots |
webmaster@1
|
134 if (preg_match('@(dev|HEAD)@', $info['version'])) { |
webmaster@1
|
135 $install_type = 'dev'; |
webmaster@1
|
136 } |
webmaster@1
|
137 |
webmaster@1
|
138 // Figure out what the currently installed major version is. We need |
webmaster@1
|
139 // to handle both contribution (e.g. "5.x-1.3", major = 1) and core |
webmaster@1
|
140 // (e.g. "5.1", major = 5) version strings. |
webmaster@1
|
141 $matches = array(); |
webmaster@1
|
142 if (preg_match('/^(\d+\.x-)?(\d+)\..*$/', $info['version'], $matches)) { |
webmaster@1
|
143 $info['major'] = $matches[2]; |
webmaster@1
|
144 } |
webmaster@1
|
145 elseif (!isset($info['major'])) { |
webmaster@1
|
146 // This would only happen for version strings that don't follow the |
webmaster@1
|
147 // drupal.org convention. We let contribs define "major" in their |
webmaster@1
|
148 // .info in this case, and only if that's missing would we hit this. |
webmaster@1
|
149 $info['major'] = -1; |
webmaster@1
|
150 } |
webmaster@1
|
151 } |
webmaster@1
|
152 else { |
webmaster@1
|
153 // No version info available at all. |
webmaster@1
|
154 $install_type = 'unknown'; |
webmaster@1
|
155 $info['version'] = t('Unknown'); |
webmaster@1
|
156 $info['major'] = -1; |
webmaster@1
|
157 } |
webmaster@1
|
158 |
webmaster@1
|
159 // Finally, save the results we care about into the $projects array. |
webmaster@1
|
160 $projects[$key]['existing_version'] = $info['version']; |
webmaster@1
|
161 $projects[$key]['existing_major'] = $info['major']; |
webmaster@1
|
162 $projects[$key]['install_type'] = $install_type; |
webmaster@1
|
163 unset($projects[$key]['info']); |
webmaster@1
|
164 } |
webmaster@1
|
165 } |
webmaster@1
|
166 |
webmaster@1
|
167 /** |
webmaster@1
|
168 * Given the installed projects and the available release data retrieved from |
webmaster@1
|
169 * remote servers, calculate the current status. |
webmaster@1
|
170 * |
webmaster@1
|
171 * This function is the heart of the update status feature. It iterates over |
webmaster@1
|
172 * every currently installed project. For each one, it first checks if the |
webmaster@1
|
173 * project has been flagged with a special status like "unsupported" or |
webmaster@1
|
174 * "insecure", or if the project node itself has been unpublished. In any of |
webmaster@1
|
175 * those cases, the project is marked with an error and the next project is |
webmaster@1
|
176 * considered. |
webmaster@1
|
177 * |
webmaster@1
|
178 * If the project itself is valid, the function decides what major release |
webmaster@1
|
179 * series to consider. The project defines what the currently supported major |
webmaster@1
|
180 * versions are for each version of core, so the first step is to make sure |
webmaster@1
|
181 * the current version is still supported. If so, that's the target version. |
webmaster@1
|
182 * If the current version is unsupported, the project maintainer's recommended |
webmaster@1
|
183 * major version is used. There's also a check to make sure that this function |
webmaster@1
|
184 * never recommends an earlier release than the currently installed major |
webmaster@1
|
185 * version. |
webmaster@1
|
186 * |
webmaster@1
|
187 * Given a target major version, it scans the available releases looking for |
webmaster@1
|
188 * the specific release to recommend (avoiding beta releases and development |
webmaster@1
|
189 * snapshots if possible). This is complicated to describe, but an example |
webmaster@1
|
190 * will help clarify. For the target major version, find the highest patch |
webmaster@1
|
191 * level. If there is a release at that patch level with no extra ("beta", |
webmaster@1
|
192 * etc), then we recommend the release at that patch level with the most |
webmaster@1
|
193 * recent release date. If every release at that patch level has extra (only |
webmaster@1
|
194 * betas), then recommend the latest release from the previous patch |
webmaster@1
|
195 * level. For example: |
webmaster@1
|
196 * |
webmaster@1
|
197 * 1.6-bugfix <-- recommended version because 1.6 already exists. |
webmaster@1
|
198 * 1.6 |
webmaster@1
|
199 * |
webmaster@1
|
200 * or |
webmaster@1
|
201 * |
webmaster@1
|
202 * 1.6-beta |
webmaster@1
|
203 * 1.5 <-- recommended version because no 1.6 exists. |
webmaster@1
|
204 * 1.4 |
webmaster@1
|
205 * |
webmaster@1
|
206 * It also looks for the latest release from the same major version, even a |
webmaster@1
|
207 * beta release, to display to the user as the "Latest version" option. |
webmaster@1
|
208 * Additionally, it finds the latest official release from any higher major |
webmaster@1
|
209 * versions that have been released to provide a set of "Also available" |
webmaster@1
|
210 * options. |
webmaster@1
|
211 * |
webmaster@1
|
212 * Finally, and most importantly, it keeps scanning the release history until |
webmaster@1
|
213 * it gets to the currently installed release, searching for anything marked |
webmaster@1
|
214 * as a security update. If any security updates have been found between the |
webmaster@1
|
215 * recommended release and the installed version, all of the releases that |
webmaster@1
|
216 * included a security fix are recorded so that the site administrator can be |
webmaster@1
|
217 * warned their site is insecure, and links pointing to the release notes for |
webmaster@1
|
218 * each security update can be included (which, in turn, will link to the |
webmaster@1
|
219 * official security announcements for each vulnerability). |
webmaster@1
|
220 * |
webmaster@1
|
221 * This function relies on the fact that the .xml release history data comes |
webmaster@1
|
222 * sorted based on major version and patch level, then finally by release date |
webmaster@1
|
223 * if there are multiple releases such as betas from the same major.patch |
webmaster@1
|
224 * version (e.g. 5.x-1.5-beta1, 5.x-1.5-beta2, and 5.x-1.5). Development |
webmaster@1
|
225 * snapshots for a given major version are always listed last. |
webmaster@1
|
226 * |
webmaster@1
|
227 * @param $available |
webmaster@1
|
228 * Array of data about available project releases. |
webmaster@1
|
229 * |
webmaster@1
|
230 * @see update_get_available() |
webmaster@1
|
231 * @see update_get_projects() |
webmaster@1
|
232 * @see update_process_project_info() |
webmaster@1
|
233 */ |
webmaster@1
|
234 function update_calculate_project_data($available) { |
webmaster@1
|
235 // Retrieve the projects from cache, if present. |
webmaster@1
|
236 $projects = update_project_cache('update_project_data'); |
webmaster@1
|
237 // If $projects is empty, then the cache must be rebuilt. |
webmaster@1
|
238 // Otherwise, return the cached data and skip the rest of the function. |
webmaster@1
|
239 if (!empty($projects)) { |
webmaster@1
|
240 return $projects; |
webmaster@1
|
241 } |
webmaster@1
|
242 $projects = update_get_projects(); |
webmaster@1
|
243 update_process_project_info($projects); |
webmaster@1
|
244 foreach ($projects as $project => $project_info) { |
webmaster@1
|
245 if (isset($available[$project])) { |
webmaster@1
|
246 |
webmaster@1
|
247 // If the project status is marked as something bad, there's nothing |
webmaster@1
|
248 // else to consider. |
webmaster@1
|
249 if (isset($available[$project]['project_status'])) { |
webmaster@1
|
250 switch ($available[$project]['project_status']) { |
webmaster@1
|
251 case 'insecure': |
webmaster@1
|
252 $projects[$project]['status'] = UPDATE_NOT_SECURE; |
webmaster@1
|
253 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
254 $projects[$project]['extra'] = array(); |
webmaster@1
|
255 } |
webmaster@1
|
256 $projects[$project]['extra'][] = array( |
webmaster@1
|
257 'class' => 'project-not-secure', |
webmaster@1
|
258 'label' => t('Project not secure'), |
webmaster@1
|
259 'data' => t('This project has been labeled insecure by the Drupal security team, and is no longer available for download. Immediately disabling everything included by this project is strongly recommended!'), |
webmaster@1
|
260 ); |
webmaster@1
|
261 break; |
webmaster@1
|
262 case 'unpublished': |
webmaster@1
|
263 case 'revoked': |
webmaster@1
|
264 $projects[$project]['status'] = UPDATE_REVOKED; |
webmaster@1
|
265 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
266 $projects[$project]['extra'] = array(); |
webmaster@1
|
267 } |
webmaster@1
|
268 $projects[$project]['extra'][] = array( |
webmaster@1
|
269 'class' => 'project-revoked', |
webmaster@1
|
270 'label' => t('Project revoked'), |
webmaster@1
|
271 'data' => t('This project has been revoked, and is no longer available for download. Disabling everything included by this project is strongly recommended!'), |
webmaster@1
|
272 ); |
webmaster@1
|
273 break; |
webmaster@1
|
274 case 'unsupported': |
webmaster@1
|
275 $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; |
webmaster@1
|
276 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
277 $projects[$project]['extra'] = array(); |
webmaster@1
|
278 } |
webmaster@1
|
279 $projects[$project]['extra'][] = array( |
webmaster@1
|
280 'class' => 'project-not-supported', |
webmaster@1
|
281 'label' => t('Project not supported'), |
webmaster@1
|
282 'data' => t('This project is no longer supported, and is no longer available for download. Disabling everything included by this project is strongly recommended!'), |
webmaster@1
|
283 ); |
webmaster@1
|
284 break; |
webmaster@1
|
285 default: |
webmaster@1
|
286 // Assume anything else (e.g. 'published') is valid and we should |
webmaster@1
|
287 // perform the rest of the logic in this function. |
webmaster@1
|
288 break; |
webmaster@1
|
289 } |
webmaster@1
|
290 } |
webmaster@1
|
291 |
webmaster@1
|
292 if (!empty($projects[$project]['status'])) { |
webmaster@1
|
293 // We already know the status for this project, so there's nothing |
webmaster@1
|
294 // else to compute. Just record everything else we fetched from the |
webmaster@1
|
295 // XML file into our projects array and move to the next project. |
webmaster@1
|
296 $projects[$project] += $available[$project]; |
webmaster@1
|
297 continue; |
webmaster@1
|
298 } |
webmaster@1
|
299 |
webmaster@1
|
300 // Figure out the target major version. |
webmaster@1
|
301 $existing_major = $project_info['existing_major']; |
webmaster@1
|
302 $supported_majors = array(); |
webmaster@1
|
303 if (isset($available[$project]['supported_majors'])) { |
webmaster@1
|
304 $supported_majors = explode(',', $available[$project]['supported_majors']); |
webmaster@1
|
305 } |
webmaster@1
|
306 elseif (isset($available[$project]['default_major'])) { |
webmaster@1
|
307 // Older release history XML file without supported or recommended. |
webmaster@1
|
308 $supported_majors[] = $available[$project]['default_major']; |
webmaster@1
|
309 } |
webmaster@1
|
310 |
webmaster@1
|
311 if (in_array($existing_major, $supported_majors)) { |
webmaster@1
|
312 // Still supported, stay at the current major version. |
webmaster@1
|
313 $target_major = $existing_major; |
webmaster@1
|
314 } |
webmaster@1
|
315 elseif (isset($available[$project]['recommended_major'])) { |
webmaster@1
|
316 // Since 'recommended_major' is defined, we know this is the new XML |
webmaster@1
|
317 // format. Therefore, we know the current release is unsupported since |
webmaster@1
|
318 // its major version was not in the 'supported_majors' list. We should |
webmaster@1
|
319 // find the best release from the recommended major version. |
webmaster@1
|
320 $target_major = $available[$project]['recommended_major']; |
webmaster@1
|
321 $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; |
webmaster@1
|
322 } |
webmaster@1
|
323 elseif (isset($available[$project]['default_major'])) { |
webmaster@1
|
324 // Older release history XML file without recommended, so recommend |
webmaster@1
|
325 // the currently defined "default_major" version. |
webmaster@1
|
326 $target_major = $available[$project]['default_major']; |
webmaster@1
|
327 } |
webmaster@1
|
328 else { |
webmaster@1
|
329 // Malformed XML file? Stick with the current version. |
webmaster@1
|
330 $target_major = $existing_major; |
webmaster@1
|
331 } |
webmaster@1
|
332 |
webmaster@1
|
333 // Make sure we never tell the admin to downgrade. If we recommended an |
webmaster@1
|
334 // earlier version than the one they're running, they'd face an |
webmaster@1
|
335 // impossible data migration problem, since Drupal never supports a DB |
webmaster@1
|
336 // downgrade path. In the unfortunate case that what they're running is |
webmaster@1
|
337 // unsupported, and there's nothing newer for them to upgrade to, we |
webmaster@1
|
338 // can't print out a "Recommended version", but just have to tell them |
webmaster@1
|
339 // what they have is unsupported and let them figure it out. |
webmaster@1
|
340 $target_major = max($existing_major, $target_major); |
webmaster@1
|
341 |
webmaster@1
|
342 $version_patch_changed = ''; |
webmaster@1
|
343 $patch = ''; |
webmaster@1
|
344 |
webmaster@1
|
345 // Defend ourselves from XML history files that contain no releases. |
webmaster@1
|
346 if (empty($available[$project]['releases'])) { |
webmaster@1
|
347 $projects[$project]['status'] = UPDATE_UNKNOWN; |
webmaster@1
|
348 $projects[$project]['reason'] = t('No available releases found'); |
webmaster@1
|
349 continue; |
webmaster@1
|
350 } |
webmaster@1
|
351 foreach ($available[$project]['releases'] as $version => $release) { |
webmaster@1
|
352 // First, if this is the existing release, check a few conditions. |
webmaster@1
|
353 if ($projects[$project]['existing_version'] == $version) { |
webmaster@1
|
354 if (isset($release['terms']['Release type']) && |
webmaster@1
|
355 in_array('Insecure', $release['terms']['Release type'])) { |
webmaster@1
|
356 $projects[$project]['status'] = UPDATE_NOT_SECURE; |
webmaster@1
|
357 } |
webmaster@1
|
358 elseif ($release['status'] == 'unpublished') { |
webmaster@1
|
359 $projects[$project]['status'] = UPDATE_REVOKED; |
webmaster@1
|
360 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
361 $projects[$project]['extra'] = array(); |
webmaster@1
|
362 } |
webmaster@1
|
363 $projects[$project]['extra'][] = array( |
webmaster@1
|
364 'class' => 'release-revoked', |
webmaster@1
|
365 'label' => t('Release revoked'), |
webmaster@1
|
366 'data' => t('Your currently installed release has been revoked, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), |
webmaster@1
|
367 ); |
webmaster@1
|
368 } |
webmaster@1
|
369 elseif (isset($release['terms']['Release type']) && |
webmaster@1
|
370 in_array('Unsupported', $release['terms']['Release type'])) { |
webmaster@1
|
371 $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; |
webmaster@1
|
372 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
373 $projects[$project]['extra'] = array(); |
webmaster@1
|
374 } |
webmaster@1
|
375 $projects[$project]['extra'][] = array( |
webmaster@1
|
376 'class' => 'release-not-supported', |
webmaster@1
|
377 'label' => t('Release not supported'), |
webmaster@1
|
378 'data' => t('Your currently installed release is now unsupported, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), |
webmaster@1
|
379 ); |
webmaster@1
|
380 } |
webmaster@1
|
381 } |
webmaster@1
|
382 |
webmaster@1
|
383 // Otherwise, ignore unpublished, insecure, or unsupported releases. |
webmaster@1
|
384 if ($release['status'] == 'unpublished' || |
webmaster@1
|
385 (isset($release['terms']['Release type']) && |
webmaster@1
|
386 (in_array('Insecure', $release['terms']['Release type']) || |
webmaster@1
|
387 in_array('Unsupported', $release['terms']['Release type'])))) { |
webmaster@1
|
388 continue; |
webmaster@1
|
389 } |
webmaster@1
|
390 |
webmaster@1
|
391 // See if this is a higher major version than our target and yet still |
webmaster@1
|
392 // supported. If so, record it as an "Also available" release. |
webmaster@1
|
393 if ($release['version_major'] > $target_major) { |
webmaster@1
|
394 if (in_array($release['version_major'], $supported_majors)) { |
webmaster@1
|
395 if (!isset($available[$project]['also'])) { |
webmaster@1
|
396 $available[$project]['also'] = array(); |
webmaster@1
|
397 } |
webmaster@1
|
398 if (!isset($available[$project]['also'][$release['version_major']])) { |
webmaster@1
|
399 $available[$project]['also'][$release['version_major']] = $version; |
webmaster@1
|
400 } |
webmaster@1
|
401 } |
webmaster@1
|
402 // Otherwise, this release can't matter to us, since it's neither |
webmaster@1
|
403 // from the release series we're currently using nor the recommended |
webmaster@1
|
404 // release. We don't even care about security updates for this |
webmaster@1
|
405 // branch, since if a project maintainer puts out a security release |
webmaster@1
|
406 // at a higher major version and not at the lower major version, |
webmaster@1
|
407 // they must remove the lower version from the supported major |
webmaster@1
|
408 // versions at the same time, in which case we won't hit this code. |
webmaster@1
|
409 continue; |
webmaster@1
|
410 } |
webmaster@1
|
411 |
webmaster@1
|
412 // Look for the 'latest version' if we haven't found it yet. Latest is |
webmaster@1
|
413 // defined as the most recent version for the target major version. |
webmaster@1
|
414 if (!isset($available[$project]['latest_version']) |
webmaster@1
|
415 && $release['version_major'] == $target_major) { |
webmaster@1
|
416 $available[$project]['latest_version'] = $version; |
webmaster@1
|
417 } |
webmaster@1
|
418 |
webmaster@1
|
419 // Look for the development snapshot release for this branch. |
webmaster@1
|
420 if (!isset($available[$project]['dev_version']) |
webmaster@1
|
421 && $release['version_major'] == $target_major |
webmaster@1
|
422 && isset($release['version_extra']) |
webmaster@1
|
423 && $release['version_extra'] == 'dev') { |
webmaster@1
|
424 $available[$project]['dev_version'] = $version; |
webmaster@1
|
425 } |
webmaster@1
|
426 |
webmaster@1
|
427 // Look for the 'recommended' version if we haven't found it yet (see |
webmaster@1
|
428 // phpdoc at the top of this function for the definition). |
webmaster@1
|
429 if (!isset($available[$project]['recommended']) |
webmaster@1
|
430 && $release['version_major'] == $target_major |
webmaster@1
|
431 && isset($release['version_patch'])) { |
webmaster@1
|
432 if ($patch != $release['version_patch']) { |
webmaster@1
|
433 $patch = $release['version_patch']; |
webmaster@1
|
434 $version_patch_changed = $release['version']; |
webmaster@1
|
435 } |
webmaster@1
|
436 if (empty($release['version_extra']) && $patch == $release['version_patch']) { |
webmaster@1
|
437 $available[$project]['recommended'] = $version_patch_changed; |
webmaster@1
|
438 } |
webmaster@1
|
439 } |
webmaster@1
|
440 |
webmaster@1
|
441 // Stop searching once we hit the currently installed version. |
webmaster@1
|
442 if ($projects[$project]['existing_version'] == $version) { |
webmaster@1
|
443 break; |
webmaster@1
|
444 } |
webmaster@1
|
445 |
webmaster@1
|
446 // If we're running a dev snapshot and have a timestamp, stop |
webmaster@1
|
447 // searching for security updates once we hit an official release |
webmaster@1
|
448 // older than what we've got. Allow 100 seconds of leeway to handle |
webmaster@1
|
449 // differences between the datestamp in the .info file and the |
webmaster@1
|
450 // timestamp of the tarball itself (which are usually off by 1 or 2 |
webmaster@1
|
451 // seconds) so that we don't flag that as a new release. |
webmaster@1
|
452 if ($projects[$project]['install_type'] == 'dev') { |
webmaster@1
|
453 if (empty($projects[$project]['datestamp'])) { |
webmaster@1
|
454 // We don't have current timestamp info, so we can't know. |
webmaster@1
|
455 continue; |
webmaster@1
|
456 } |
webmaster@1
|
457 elseif (isset($release['date']) && ($projects[$project]['datestamp'] + 100 > $release['date'])) { |
webmaster@1
|
458 // We're newer than this, so we can skip it. |
webmaster@1
|
459 continue; |
webmaster@1
|
460 } |
webmaster@1
|
461 } |
webmaster@1
|
462 |
webmaster@1
|
463 // See if this release is a security update. |
webmaster@1
|
464 if (isset($release['terms']['Release type']) |
webmaster@1
|
465 && in_array('Security update', $release['terms']['Release type'])) { |
webmaster@1
|
466 $projects[$project]['security updates'][] = $release; |
webmaster@1
|
467 } |
webmaster@1
|
468 } |
webmaster@1
|
469 |
webmaster@1
|
470 // If we were unable to find a recommended version, then make the latest |
webmaster@1
|
471 // version the recommended version if possible. |
webmaster@1
|
472 if (!isset($available[$project]['recommended']) && isset($available[$project]['latest_version'])) { |
webmaster@1
|
473 $available[$project]['recommended'] = $available[$project]['latest_version']; |
webmaster@1
|
474 } |
webmaster@1
|
475 |
webmaster@1
|
476 // Stash the info about available releases into our $projects array. |
webmaster@1
|
477 $projects[$project] += $available[$project]; |
webmaster@1
|
478 |
webmaster@1
|
479 // |
webmaster@1
|
480 // Check to see if we need an update or not. |
webmaster@1
|
481 // |
webmaster@1
|
482 |
webmaster@1
|
483 if (!empty($projects[$project]['security updates'])) { |
webmaster@1
|
484 // If we found security updates, that always trumps any other status. |
webmaster@1
|
485 $projects[$project]['status'] = UPDATE_NOT_SECURE; |
webmaster@1
|
486 } |
webmaster@1
|
487 |
webmaster@1
|
488 if (isset($projects[$project]['status'])) { |
webmaster@1
|
489 // If we already know the status, we're done. |
webmaster@1
|
490 continue; |
webmaster@1
|
491 } |
webmaster@1
|
492 |
webmaster@1
|
493 // If we don't know what to recommend, there's nothing we can report. |
webmaster@1
|
494 // Bail out early. |
webmaster@1
|
495 if (!isset($projects[$project]['recommended'])) { |
webmaster@1
|
496 $projects[$project]['status'] = UPDATE_UNKNOWN; |
webmaster@1
|
497 $projects[$project]['reason'] = t('No available releases found'); |
webmaster@1
|
498 continue; |
webmaster@1
|
499 } |
webmaster@1
|
500 |
webmaster@1
|
501 // If we're running a dev snapshot, compare the date of the dev snapshot |
webmaster@1
|
502 // with the latest official version, and record the absolute latest in |
webmaster@1
|
503 // 'latest_dev' so we can correctly decide if there's a newer release |
webmaster@1
|
504 // than our current snapshot. |
webmaster@1
|
505 if ($projects[$project]['install_type'] == 'dev') { |
webmaster@1
|
506 if (isset($available[$project]['dev_version']) && $available[$project]['releases'][$available[$project]['dev_version']]['date'] > $available[$project]['releases'][$available[$project]['latest_version']]['date']) { |
webmaster@1
|
507 $projects[$project]['latest_dev'] = $available[$project]['dev_version']; |
webmaster@1
|
508 } |
webmaster@1
|
509 else { |
webmaster@1
|
510 $projects[$project]['latest_dev'] = $available[$project]['latest_version']; |
webmaster@1
|
511 } |
webmaster@1
|
512 } |
webmaster@1
|
513 |
webmaster@1
|
514 // Figure out the status, based on what we've seen and the install type. |
webmaster@1
|
515 switch ($projects[$project]['install_type']) { |
webmaster@1
|
516 case 'official': |
webmaster@1
|
517 if ($projects[$project]['existing_version'] == $projects[$project]['recommended'] || $projects[$project]['existing_version'] == $projects[$project]['latest_version']) { |
webmaster@1
|
518 $projects[$project]['status'] = UPDATE_CURRENT; |
webmaster@1
|
519 } |
webmaster@1
|
520 else { |
webmaster@1
|
521 $projects[$project]['status'] = UPDATE_NOT_CURRENT; |
webmaster@1
|
522 } |
webmaster@1
|
523 break; |
webmaster@1
|
524 |
webmaster@1
|
525 case 'dev': |
webmaster@1
|
526 $latest = $available[$project]['releases'][$projects[$project]['latest_dev']]; |
webmaster@1
|
527 if (empty($projects[$project]['datestamp'])) { |
webmaster@1
|
528 $projects[$project]['status'] = UPDATE_NOT_CHECKED; |
webmaster@1
|
529 $projects[$project]['reason'] = t('Unknown release date'); |
webmaster@1
|
530 } |
webmaster@1
|
531 elseif (($projects[$project]['datestamp'] + 100 > $latest['date'])) { |
webmaster@1
|
532 $projects[$project]['status'] = UPDATE_CURRENT; |
webmaster@1
|
533 } |
webmaster@1
|
534 else { |
webmaster@1
|
535 $projects[$project]['status'] = UPDATE_NOT_CURRENT; |
webmaster@1
|
536 } |
webmaster@1
|
537 break; |
webmaster@1
|
538 |
webmaster@1
|
539 default: |
webmaster@1
|
540 $projects[$project]['status'] = UPDATE_UNKNOWN; |
webmaster@1
|
541 $projects[$project]['reason'] = t('Invalid info'); |
webmaster@1
|
542 } |
webmaster@1
|
543 } |
webmaster@1
|
544 else { |
webmaster@1
|
545 $projects[$project]['status'] = UPDATE_UNKNOWN; |
webmaster@1
|
546 $projects[$project]['reason'] = t('No available releases found'); |
webmaster@1
|
547 } |
webmaster@1
|
548 } |
webmaster@1
|
549 // Give other modules a chance to alter the status (for example, to allow a |
webmaster@1
|
550 // contrib module to provide fine-grained settings to ignore specific |
webmaster@1
|
551 // projects or releases). |
webmaster@1
|
552 drupal_alter('update_status', $projects); |
webmaster@1
|
553 |
webmaster@1
|
554 // Set the projects array into the cache table. |
webmaster@1
|
555 cache_set('update_project_data', $projects, 'cache_update', time() + 3600); |
webmaster@1
|
556 return $projects; |
webmaster@1
|
557 } |
webmaster@1
|
558 |
webmaster@1
|
559 /** |
webmaster@1
|
560 * Retrieve data from {cache_update} or empty the cache when necessary. |
webmaster@1
|
561 * |
webmaster@1
|
562 * Two very expensive arrays computed by this module are the list of all |
webmaster@1
|
563 * installed modules and themes (and .info data, project associations, etc), |
webmaster@1
|
564 * and the current status of the site relative to the currently available |
webmaster@1
|
565 * releases. These two arrays are cached in the {cache_update} table and used |
webmaster@1
|
566 * whenever possible. The cache is cleared whenever the administrator visits |
webmaster@1
|
567 * the status report, available updates report, or the module or theme |
webmaster@1
|
568 * administration pages, since we should always recompute the most current |
webmaster@1
|
569 * values on any of those pages. |
webmaster@1
|
570 * |
webmaster@1
|
571 * @param $cid |
webmaster@1
|
572 * The cache id of data to return from the cache. Valid options are |
webmaster@1
|
573 * 'update_project_data' and 'update_project_projects'. |
webmaster@1
|
574 * |
webmaster@1
|
575 * @return |
webmaster@1
|
576 * The cached value of the $projects array generated by |
webmaster@1
|
577 * update_calculate_project_data() or update_get_projects(), or an empty |
webmaster@1
|
578 * array when the cache is cleared. |
webmaster@1
|
579 */ |
webmaster@1
|
580 function update_project_cache($cid) { |
webmaster@1
|
581 $projects = array(); |
webmaster@1
|
582 |
webmaster@1
|
583 // In some cases, we must clear the cache. Rather than do so on a time |
webmaster@1
|
584 // basis, we check for specific paths. |
webmaster@1
|
585 $q = $_GET['q']; |
webmaster@1
|
586 $paths = array('admin/build/modules', 'admin/build/themes', 'admin/reports', 'admin/reports/updates', 'admin/reports/status', 'admin/reports/updates/check'); |
webmaster@1
|
587 if (in_array($q, $paths)) { |
webmaster@1
|
588 cache_clear_all($cid, 'cache_update'); |
webmaster@1
|
589 } |
webmaster@1
|
590 else { |
webmaster@1
|
591 $cache = cache_get($cid, 'cache_update'); |
webmaster@1
|
592 if (!empty($cache->data) && $cache->expire > time()) { |
webmaster@1
|
593 $projects = $cache->data; |
webmaster@1
|
594 } |
webmaster@1
|
595 } |
webmaster@1
|
596 return $projects; |
webmaster@1
|
597 } |