webmaster@1
|
1 <?php |
webmaster@11
|
2 // $Id: update.compare.inc,v 1.8.2.2 2008/08/28 08:14:56 dries 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 } |
webmaster@1
|
164 } |
webmaster@1
|
165 |
webmaster@1
|
166 /** |
webmaster@1
|
167 * Given the installed projects and the available release data retrieved from |
webmaster@1
|
168 * remote servers, calculate the current status. |
webmaster@1
|
169 * |
webmaster@1
|
170 * This function is the heart of the update status feature. It iterates over |
webmaster@1
|
171 * every currently installed project. For each one, it first checks if the |
webmaster@1
|
172 * project has been flagged with a special status like "unsupported" or |
webmaster@1
|
173 * "insecure", or if the project node itself has been unpublished. In any of |
webmaster@1
|
174 * those cases, the project is marked with an error and the next project is |
webmaster@1
|
175 * considered. |
webmaster@1
|
176 * |
webmaster@1
|
177 * If the project itself is valid, the function decides what major release |
webmaster@1
|
178 * series to consider. The project defines what the currently supported major |
webmaster@1
|
179 * versions are for each version of core, so the first step is to make sure |
webmaster@1
|
180 * the current version is still supported. If so, that's the target version. |
webmaster@1
|
181 * If the current version is unsupported, the project maintainer's recommended |
webmaster@1
|
182 * major version is used. There's also a check to make sure that this function |
webmaster@1
|
183 * never recommends an earlier release than the currently installed major |
webmaster@1
|
184 * version. |
webmaster@1
|
185 * |
webmaster@1
|
186 * Given a target major version, it scans the available releases looking for |
webmaster@1
|
187 * the specific release to recommend (avoiding beta releases and development |
webmaster@1
|
188 * snapshots if possible). This is complicated to describe, but an example |
webmaster@1
|
189 * will help clarify. For the target major version, find the highest patch |
webmaster@1
|
190 * level. If there is a release at that patch level with no extra ("beta", |
webmaster@1
|
191 * etc), then we recommend the release at that patch level with the most |
webmaster@1
|
192 * recent release date. If every release at that patch level has extra (only |
webmaster@1
|
193 * betas), then recommend the latest release from the previous patch |
webmaster@1
|
194 * level. For example: |
webmaster@1
|
195 * |
webmaster@1
|
196 * 1.6-bugfix <-- recommended version because 1.6 already exists. |
webmaster@1
|
197 * 1.6 |
webmaster@1
|
198 * |
webmaster@1
|
199 * or |
webmaster@1
|
200 * |
webmaster@1
|
201 * 1.6-beta |
webmaster@1
|
202 * 1.5 <-- recommended version because no 1.6 exists. |
webmaster@1
|
203 * 1.4 |
webmaster@1
|
204 * |
webmaster@1
|
205 * It also looks for the latest release from the same major version, even a |
webmaster@1
|
206 * beta release, to display to the user as the "Latest version" option. |
webmaster@1
|
207 * Additionally, it finds the latest official release from any higher major |
webmaster@1
|
208 * versions that have been released to provide a set of "Also available" |
webmaster@1
|
209 * options. |
webmaster@1
|
210 * |
webmaster@1
|
211 * Finally, and most importantly, it keeps scanning the release history until |
webmaster@1
|
212 * it gets to the currently installed release, searching for anything marked |
webmaster@1
|
213 * as a security update. If any security updates have been found between the |
webmaster@1
|
214 * recommended release and the installed version, all of the releases that |
webmaster@1
|
215 * included a security fix are recorded so that the site administrator can be |
webmaster@1
|
216 * warned their site is insecure, and links pointing to the release notes for |
webmaster@1
|
217 * each security update can be included (which, in turn, will link to the |
webmaster@1
|
218 * official security announcements for each vulnerability). |
webmaster@1
|
219 * |
webmaster@1
|
220 * This function relies on the fact that the .xml release history data comes |
webmaster@1
|
221 * sorted based on major version and patch level, then finally by release date |
webmaster@1
|
222 * if there are multiple releases such as betas from the same major.patch |
webmaster@1
|
223 * version (e.g. 5.x-1.5-beta1, 5.x-1.5-beta2, and 5.x-1.5). Development |
webmaster@1
|
224 * snapshots for a given major version are always listed last. |
webmaster@1
|
225 * |
webmaster@1
|
226 * @param $available |
webmaster@1
|
227 * Array of data about available project releases. |
webmaster@1
|
228 * |
webmaster@1
|
229 * @see update_get_available() |
webmaster@1
|
230 * @see update_get_projects() |
webmaster@1
|
231 * @see update_process_project_info() |
webmaster@1
|
232 */ |
webmaster@1
|
233 function update_calculate_project_data($available) { |
webmaster@1
|
234 // Retrieve the projects from cache, if present. |
webmaster@1
|
235 $projects = update_project_cache('update_project_data'); |
webmaster@1
|
236 // If $projects is empty, then the cache must be rebuilt. |
webmaster@1
|
237 // Otherwise, return the cached data and skip the rest of the function. |
webmaster@1
|
238 if (!empty($projects)) { |
webmaster@1
|
239 return $projects; |
webmaster@1
|
240 } |
webmaster@1
|
241 $projects = update_get_projects(); |
webmaster@1
|
242 update_process_project_info($projects); |
webmaster@1
|
243 foreach ($projects as $project => $project_info) { |
webmaster@1
|
244 if (isset($available[$project])) { |
webmaster@1
|
245 |
webmaster@1
|
246 // If the project status is marked as something bad, there's nothing |
webmaster@1
|
247 // else to consider. |
webmaster@1
|
248 if (isset($available[$project]['project_status'])) { |
webmaster@1
|
249 switch ($available[$project]['project_status']) { |
webmaster@1
|
250 case 'insecure': |
webmaster@1
|
251 $projects[$project]['status'] = UPDATE_NOT_SECURE; |
webmaster@1
|
252 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
253 $projects[$project]['extra'] = array(); |
webmaster@1
|
254 } |
webmaster@1
|
255 $projects[$project]['extra'][] = array( |
webmaster@1
|
256 'class' => 'project-not-secure', |
webmaster@1
|
257 'label' => t('Project not secure'), |
webmaster@1
|
258 '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
|
259 ); |
webmaster@1
|
260 break; |
webmaster@1
|
261 case 'unpublished': |
webmaster@1
|
262 case 'revoked': |
webmaster@1
|
263 $projects[$project]['status'] = UPDATE_REVOKED; |
webmaster@1
|
264 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
265 $projects[$project]['extra'] = array(); |
webmaster@1
|
266 } |
webmaster@1
|
267 $projects[$project]['extra'][] = array( |
webmaster@1
|
268 'class' => 'project-revoked', |
webmaster@1
|
269 'label' => t('Project revoked'), |
webmaster@1
|
270 '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
|
271 ); |
webmaster@1
|
272 break; |
webmaster@1
|
273 case 'unsupported': |
webmaster@1
|
274 $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; |
webmaster@1
|
275 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
276 $projects[$project]['extra'] = array(); |
webmaster@1
|
277 } |
webmaster@1
|
278 $projects[$project]['extra'][] = array( |
webmaster@1
|
279 'class' => 'project-not-supported', |
webmaster@1
|
280 'label' => t('Project not supported'), |
webmaster@1
|
281 '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
|
282 ); |
webmaster@1
|
283 break; |
webmaster@1
|
284 default: |
webmaster@1
|
285 // Assume anything else (e.g. 'published') is valid and we should |
webmaster@1
|
286 // perform the rest of the logic in this function. |
webmaster@1
|
287 break; |
webmaster@1
|
288 } |
webmaster@1
|
289 } |
webmaster@1
|
290 |
webmaster@1
|
291 if (!empty($projects[$project]['status'])) { |
webmaster@1
|
292 // We already know the status for this project, so there's nothing |
webmaster@1
|
293 // else to compute. Just record everything else we fetched from the |
webmaster@1
|
294 // XML file into our projects array and move to the next project. |
webmaster@1
|
295 $projects[$project] += $available[$project]; |
webmaster@1
|
296 continue; |
webmaster@1
|
297 } |
webmaster@1
|
298 |
webmaster@1
|
299 // Figure out the target major version. |
webmaster@1
|
300 $existing_major = $project_info['existing_major']; |
webmaster@1
|
301 $supported_majors = array(); |
webmaster@1
|
302 if (isset($available[$project]['supported_majors'])) { |
webmaster@1
|
303 $supported_majors = explode(',', $available[$project]['supported_majors']); |
webmaster@1
|
304 } |
webmaster@1
|
305 elseif (isset($available[$project]['default_major'])) { |
webmaster@1
|
306 // Older release history XML file without supported or recommended. |
webmaster@1
|
307 $supported_majors[] = $available[$project]['default_major']; |
webmaster@1
|
308 } |
webmaster@1
|
309 |
webmaster@1
|
310 if (in_array($existing_major, $supported_majors)) { |
webmaster@1
|
311 // Still supported, stay at the current major version. |
webmaster@1
|
312 $target_major = $existing_major; |
webmaster@1
|
313 } |
webmaster@1
|
314 elseif (isset($available[$project]['recommended_major'])) { |
webmaster@1
|
315 // Since 'recommended_major' is defined, we know this is the new XML |
webmaster@1
|
316 // format. Therefore, we know the current release is unsupported since |
webmaster@1
|
317 // its major version was not in the 'supported_majors' list. We should |
webmaster@1
|
318 // find the best release from the recommended major version. |
webmaster@1
|
319 $target_major = $available[$project]['recommended_major']; |
webmaster@1
|
320 $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; |
webmaster@1
|
321 } |
webmaster@1
|
322 elseif (isset($available[$project]['default_major'])) { |
webmaster@1
|
323 // Older release history XML file without recommended, so recommend |
webmaster@1
|
324 // the currently defined "default_major" version. |
webmaster@1
|
325 $target_major = $available[$project]['default_major']; |
webmaster@1
|
326 } |
webmaster@1
|
327 else { |
webmaster@1
|
328 // Malformed XML file? Stick with the current version. |
webmaster@1
|
329 $target_major = $existing_major; |
webmaster@1
|
330 } |
webmaster@1
|
331 |
webmaster@1
|
332 // Make sure we never tell the admin to downgrade. If we recommended an |
webmaster@1
|
333 // earlier version than the one they're running, they'd face an |
webmaster@1
|
334 // impossible data migration problem, since Drupal never supports a DB |
webmaster@1
|
335 // downgrade path. In the unfortunate case that what they're running is |
webmaster@1
|
336 // unsupported, and there's nothing newer for them to upgrade to, we |
webmaster@1
|
337 // can't print out a "Recommended version", but just have to tell them |
webmaster@1
|
338 // what they have is unsupported and let them figure it out. |
webmaster@1
|
339 $target_major = max($existing_major, $target_major); |
webmaster@1
|
340 |
webmaster@1
|
341 $version_patch_changed = ''; |
webmaster@1
|
342 $patch = ''; |
webmaster@1
|
343 |
webmaster@1
|
344 // Defend ourselves from XML history files that contain no releases. |
webmaster@1
|
345 if (empty($available[$project]['releases'])) { |
webmaster@1
|
346 $projects[$project]['status'] = UPDATE_UNKNOWN; |
webmaster@1
|
347 $projects[$project]['reason'] = t('No available releases found'); |
webmaster@1
|
348 continue; |
webmaster@1
|
349 } |
webmaster@1
|
350 foreach ($available[$project]['releases'] as $version => $release) { |
webmaster@1
|
351 // First, if this is the existing release, check a few conditions. |
webmaster@11
|
352 if ($projects[$project]['existing_version'] === $version) { |
webmaster@1
|
353 if (isset($release['terms']['Release type']) && |
webmaster@1
|
354 in_array('Insecure', $release['terms']['Release type'])) { |
webmaster@1
|
355 $projects[$project]['status'] = UPDATE_NOT_SECURE; |
webmaster@1
|
356 } |
webmaster@1
|
357 elseif ($release['status'] == 'unpublished') { |
webmaster@1
|
358 $projects[$project]['status'] = UPDATE_REVOKED; |
webmaster@1
|
359 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
360 $projects[$project]['extra'] = array(); |
webmaster@1
|
361 } |
webmaster@1
|
362 $projects[$project]['extra'][] = array( |
webmaster@1
|
363 'class' => 'release-revoked', |
webmaster@1
|
364 'label' => t('Release revoked'), |
webmaster@1
|
365 '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
|
366 ); |
webmaster@1
|
367 } |
webmaster@1
|
368 elseif (isset($release['terms']['Release type']) && |
webmaster@1
|
369 in_array('Unsupported', $release['terms']['Release type'])) { |
webmaster@1
|
370 $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; |
webmaster@1
|
371 if (empty($projects[$project]['extra'])) { |
webmaster@1
|
372 $projects[$project]['extra'] = array(); |
webmaster@1
|
373 } |
webmaster@1
|
374 $projects[$project]['extra'][] = array( |
webmaster@1
|
375 'class' => 'release-not-supported', |
webmaster@1
|
376 'label' => t('Release not supported'), |
webmaster@1
|
377 '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
|
378 ); |
webmaster@1
|
379 } |
webmaster@1
|
380 } |
webmaster@1
|
381 |
webmaster@1
|
382 // Otherwise, ignore unpublished, insecure, or unsupported releases. |
webmaster@1
|
383 if ($release['status'] == 'unpublished' || |
webmaster@1
|
384 (isset($release['terms']['Release type']) && |
webmaster@1
|
385 (in_array('Insecure', $release['terms']['Release type']) || |
webmaster@1
|
386 in_array('Unsupported', $release['terms']['Release type'])))) { |
webmaster@1
|
387 continue; |
webmaster@1
|
388 } |
webmaster@1
|
389 |
webmaster@1
|
390 // See if this is a higher major version than our target and yet still |
webmaster@1
|
391 // supported. If so, record it as an "Also available" release. |
webmaster@1
|
392 if ($release['version_major'] > $target_major) { |
webmaster@1
|
393 if (in_array($release['version_major'], $supported_majors)) { |
webmaster@1
|
394 if (!isset($available[$project]['also'])) { |
webmaster@1
|
395 $available[$project]['also'] = array(); |
webmaster@1
|
396 } |
webmaster@1
|
397 if (!isset($available[$project]['also'][$release['version_major']])) { |
webmaster@1
|
398 $available[$project]['also'][$release['version_major']] = $version; |
webmaster@1
|
399 } |
webmaster@1
|
400 } |
webmaster@1
|
401 // Otherwise, this release can't matter to us, since it's neither |
webmaster@1
|
402 // from the release series we're currently using nor the recommended |
webmaster@1
|
403 // release. We don't even care about security updates for this |
webmaster@1
|
404 // branch, since if a project maintainer puts out a security release |
webmaster@1
|
405 // at a higher major version and not at the lower major version, |
webmaster@1
|
406 // they must remove the lower version from the supported major |
webmaster@1
|
407 // versions at the same time, in which case we won't hit this code. |
webmaster@1
|
408 continue; |
webmaster@1
|
409 } |
webmaster@1
|
410 |
webmaster@1
|
411 // Look for the 'latest version' if we haven't found it yet. Latest is |
webmaster@1
|
412 // defined as the most recent version for the target major version. |
webmaster@1
|
413 if (!isset($available[$project]['latest_version']) |
webmaster@1
|
414 && $release['version_major'] == $target_major) { |
webmaster@1
|
415 $available[$project]['latest_version'] = $version; |
webmaster@1
|
416 } |
webmaster@1
|
417 |
webmaster@1
|
418 // Look for the development snapshot release for this branch. |
webmaster@1
|
419 if (!isset($available[$project]['dev_version']) |
webmaster@1
|
420 && $release['version_major'] == $target_major |
webmaster@1
|
421 && isset($release['version_extra']) |
webmaster@1
|
422 && $release['version_extra'] == 'dev') { |
webmaster@1
|
423 $available[$project]['dev_version'] = $version; |
webmaster@1
|
424 } |
webmaster@1
|
425 |
webmaster@1
|
426 // Look for the 'recommended' version if we haven't found it yet (see |
webmaster@1
|
427 // phpdoc at the top of this function for the definition). |
webmaster@1
|
428 if (!isset($available[$project]['recommended']) |
webmaster@1
|
429 && $release['version_major'] == $target_major |
webmaster@1
|
430 && isset($release['version_patch'])) { |
webmaster@1
|
431 if ($patch != $release['version_patch']) { |
webmaster@1
|
432 $patch = $release['version_patch']; |
webmaster@1
|
433 $version_patch_changed = $release['version']; |
webmaster@1
|
434 } |
webmaster@1
|
435 if (empty($release['version_extra']) && $patch == $release['version_patch']) { |
webmaster@1
|
436 $available[$project]['recommended'] = $version_patch_changed; |
webmaster@1
|
437 } |
webmaster@1
|
438 } |
webmaster@1
|
439 |
webmaster@1
|
440 // Stop searching once we hit the currently installed version. |
webmaster@11
|
441 if ($projects[$project]['existing_version'] === $version) { |
webmaster@1
|
442 break; |
webmaster@1
|
443 } |
webmaster@1
|
444 |
webmaster@1
|
445 // If we're running a dev snapshot and have a timestamp, stop |
webmaster@1
|
446 // searching for security updates once we hit an official release |
webmaster@1
|
447 // older than what we've got. Allow 100 seconds of leeway to handle |
webmaster@1
|
448 // differences between the datestamp in the .info file and the |
webmaster@1
|
449 // timestamp of the tarball itself (which are usually off by 1 or 2 |
webmaster@1
|
450 // seconds) so that we don't flag that as a new release. |
webmaster@1
|
451 if ($projects[$project]['install_type'] == 'dev') { |
webmaster@1
|
452 if (empty($projects[$project]['datestamp'])) { |
webmaster@1
|
453 // We don't have current timestamp info, so we can't know. |
webmaster@1
|
454 continue; |
webmaster@1
|
455 } |
webmaster@1
|
456 elseif (isset($release['date']) && ($projects[$project]['datestamp'] + 100 > $release['date'])) { |
webmaster@1
|
457 // We're newer than this, so we can skip it. |
webmaster@1
|
458 continue; |
webmaster@1
|
459 } |
webmaster@1
|
460 } |
webmaster@1
|
461 |
webmaster@1
|
462 // See if this release is a security update. |
webmaster@1
|
463 if (isset($release['terms']['Release type']) |
webmaster@1
|
464 && in_array('Security update', $release['terms']['Release type'])) { |
webmaster@1
|
465 $projects[$project]['security updates'][] = $release; |
webmaster@1
|
466 } |
webmaster@1
|
467 } |
webmaster@1
|
468 |
webmaster@1
|
469 // If we were unable to find a recommended version, then make the latest |
webmaster@1
|
470 // version the recommended version if possible. |
webmaster@1
|
471 if (!isset($available[$project]['recommended']) && isset($available[$project]['latest_version'])) { |
webmaster@1
|
472 $available[$project]['recommended'] = $available[$project]['latest_version']; |
webmaster@1
|
473 } |
webmaster@1
|
474 |
webmaster@1
|
475 // Stash the info about available releases into our $projects array. |
webmaster@1
|
476 $projects[$project] += $available[$project]; |
webmaster@1
|
477 |
webmaster@1
|
478 // |
webmaster@1
|
479 // Check to see if we need an update or not. |
webmaster@1
|
480 // |
webmaster@1
|
481 |
webmaster@1
|
482 if (!empty($projects[$project]['security updates'])) { |
webmaster@1
|
483 // If we found security updates, that always trumps any other status. |
webmaster@1
|
484 $projects[$project]['status'] = UPDATE_NOT_SECURE; |
webmaster@1
|
485 } |
webmaster@1
|
486 |
webmaster@1
|
487 if (isset($projects[$project]['status'])) { |
webmaster@1
|
488 // If we already know the status, we're done. |
webmaster@1
|
489 continue; |
webmaster@1
|
490 } |
webmaster@1
|
491 |
webmaster@1
|
492 // If we don't know what to recommend, there's nothing we can report. |
webmaster@1
|
493 // Bail out early. |
webmaster@1
|
494 if (!isset($projects[$project]['recommended'])) { |
webmaster@1
|
495 $projects[$project]['status'] = UPDATE_UNKNOWN; |
webmaster@1
|
496 $projects[$project]['reason'] = t('No available releases found'); |
webmaster@1
|
497 continue; |
webmaster@1
|
498 } |
webmaster@1
|
499 |
webmaster@1
|
500 // If we're running a dev snapshot, compare the date of the dev snapshot |
webmaster@1
|
501 // with the latest official version, and record the absolute latest in |
webmaster@1
|
502 // 'latest_dev' so we can correctly decide if there's a newer release |
webmaster@1
|
503 // than our current snapshot. |
webmaster@1
|
504 if ($projects[$project]['install_type'] == 'dev') { |
webmaster@1
|
505 if (isset($available[$project]['dev_version']) && $available[$project]['releases'][$available[$project]['dev_version']]['date'] > $available[$project]['releases'][$available[$project]['latest_version']]['date']) { |
webmaster@1
|
506 $projects[$project]['latest_dev'] = $available[$project]['dev_version']; |
webmaster@1
|
507 } |
webmaster@1
|
508 else { |
webmaster@1
|
509 $projects[$project]['latest_dev'] = $available[$project]['latest_version']; |
webmaster@1
|
510 } |
webmaster@1
|
511 } |
webmaster@1
|
512 |
webmaster@1
|
513 // Figure out the status, based on what we've seen and the install type. |
webmaster@1
|
514 switch ($projects[$project]['install_type']) { |
webmaster@1
|
515 case 'official': |
webmaster@11
|
516 if ($projects[$project]['existing_version'] === $projects[$project]['recommended'] || $projects[$project]['existing_version'] === $projects[$project]['latest_version']) { |
webmaster@1
|
517 $projects[$project]['status'] = UPDATE_CURRENT; |
webmaster@1
|
518 } |
webmaster@1
|
519 else { |
webmaster@1
|
520 $projects[$project]['status'] = UPDATE_NOT_CURRENT; |
webmaster@1
|
521 } |
webmaster@1
|
522 break; |
webmaster@1
|
523 |
webmaster@1
|
524 case 'dev': |
webmaster@1
|
525 $latest = $available[$project]['releases'][$projects[$project]['latest_dev']]; |
webmaster@1
|
526 if (empty($projects[$project]['datestamp'])) { |
webmaster@1
|
527 $projects[$project]['status'] = UPDATE_NOT_CHECKED; |
webmaster@1
|
528 $projects[$project]['reason'] = t('Unknown release date'); |
webmaster@1
|
529 } |
webmaster@1
|
530 elseif (($projects[$project]['datestamp'] + 100 > $latest['date'])) { |
webmaster@1
|
531 $projects[$project]['status'] = UPDATE_CURRENT; |
webmaster@1
|
532 } |
webmaster@1
|
533 else { |
webmaster@1
|
534 $projects[$project]['status'] = UPDATE_NOT_CURRENT; |
webmaster@1
|
535 } |
webmaster@1
|
536 break; |
webmaster@1
|
537 |
webmaster@1
|
538 default: |
webmaster@1
|
539 $projects[$project]['status'] = UPDATE_UNKNOWN; |
webmaster@1
|
540 $projects[$project]['reason'] = t('Invalid info'); |
webmaster@1
|
541 } |
webmaster@1
|
542 } |
webmaster@1
|
543 else { |
webmaster@1
|
544 $projects[$project]['status'] = UPDATE_UNKNOWN; |
webmaster@1
|
545 $projects[$project]['reason'] = t('No available releases found'); |
webmaster@1
|
546 } |
webmaster@1
|
547 } |
webmaster@1
|
548 // Give other modules a chance to alter the status (for example, to allow a |
webmaster@1
|
549 // contrib module to provide fine-grained settings to ignore specific |
webmaster@1
|
550 // projects or releases). |
webmaster@1
|
551 drupal_alter('update_status', $projects); |
webmaster@1
|
552 |
webmaster@1
|
553 // Set the projects array into the cache table. |
webmaster@1
|
554 cache_set('update_project_data', $projects, 'cache_update', time() + 3600); |
webmaster@1
|
555 return $projects; |
webmaster@1
|
556 } |
webmaster@1
|
557 |
webmaster@1
|
558 /** |
webmaster@1
|
559 * Retrieve data from {cache_update} or empty the cache when necessary. |
webmaster@1
|
560 * |
webmaster@1
|
561 * Two very expensive arrays computed by this module are the list of all |
webmaster@1
|
562 * installed modules and themes (and .info data, project associations, etc), |
webmaster@1
|
563 * and the current status of the site relative to the currently available |
webmaster@1
|
564 * releases. These two arrays are cached in the {cache_update} table and used |
webmaster@1
|
565 * whenever possible. The cache is cleared whenever the administrator visits |
webmaster@1
|
566 * the status report, available updates report, or the module or theme |
webmaster@1
|
567 * administration pages, since we should always recompute the most current |
webmaster@1
|
568 * values on any of those pages. |
webmaster@1
|
569 * |
webmaster@1
|
570 * @param $cid |
webmaster@1
|
571 * The cache id of data to return from the cache. Valid options are |
webmaster@1
|
572 * 'update_project_data' and 'update_project_projects'. |
webmaster@1
|
573 * |
webmaster@1
|
574 * @return |
webmaster@1
|
575 * The cached value of the $projects array generated by |
webmaster@1
|
576 * update_calculate_project_data() or update_get_projects(), or an empty |
webmaster@1
|
577 * array when the cache is cleared. |
webmaster@1
|
578 */ |
webmaster@1
|
579 function update_project_cache($cid) { |
webmaster@1
|
580 $projects = array(); |
webmaster@1
|
581 |
webmaster@1
|
582 // In some cases, we must clear the cache. Rather than do so on a time |
webmaster@1
|
583 // basis, we check for specific paths. |
webmaster@1
|
584 $q = $_GET['q']; |
webmaster@1
|
585 $paths = array('admin/build/modules', 'admin/build/themes', 'admin/reports', 'admin/reports/updates', 'admin/reports/status', 'admin/reports/updates/check'); |
webmaster@1
|
586 if (in_array($q, $paths)) { |
webmaster@1
|
587 cache_clear_all($cid, 'cache_update'); |
webmaster@1
|
588 } |
webmaster@1
|
589 else { |
webmaster@1
|
590 $cache = cache_get($cid, 'cache_update'); |
webmaster@1
|
591 if (!empty($cache->data) && $cache->expire > time()) { |
webmaster@1
|
592 $projects = $cache->data; |
webmaster@1
|
593 } |
webmaster@1
|
594 } |
webmaster@1
|
595 return $projects; |
webmaster@1
|
596 } |