1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Code required only when comparing available updates to existing data.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Fetches an array of installed and enabled projects.
|
10
|
*
|
11
|
* This is only responsible for generating an array of projects (taking into
|
12
|
* account projects that include more than one module or theme). Other
|
13
|
* information like the specific version and install type (official release,
|
14
|
* dev snapshot, etc) is handled later in update_process_project_info() since
|
15
|
* that logic is only required when preparing the status report, not for
|
16
|
* fetching the available release data.
|
17
|
*
|
18
|
* This array is fairly expensive to construct, since it involves a lot of disk
|
19
|
* I/O, so we cache the results into the {cache_update} table using the
|
20
|
* 'update_project_projects' cache ID. However, since this is not the data about
|
21
|
* available updates fetched from the network, it is acceptable to invalidate it
|
22
|
* somewhat quickly. If we keep this data for very long, site administrators are
|
23
|
* more likely to see incorrect results if they upgrade to a newer version of a
|
24
|
* module or theme but do not visit certain pages that automatically clear this
|
25
|
* cache.
|
26
|
*
|
27
|
* @return
|
28
|
* An associative array of currently enabled projects keyed by the
|
29
|
* machine-readable project short name. Each project contains:
|
30
|
* - name: The machine-readable project short name.
|
31
|
* - info: An array with values from the main .info file for this project.
|
32
|
* - name: The human-readable name of the project.
|
33
|
* - package: The package that the project is grouped under.
|
34
|
* - version: The version of the project.
|
35
|
* - project: The Drupal.org project name.
|
36
|
* - datestamp: The date stamp of the project's main .info file.
|
37
|
* - _info_file_ctime: The maximum file change time for all of the .info
|
38
|
* files included in this project.
|
39
|
* - datestamp: The date stamp when the project was released, if known.
|
40
|
* - includes: An associative array containing all projects included with this
|
41
|
* project, keyed by the machine-readable short name with the human-readable
|
42
|
* name as value.
|
43
|
* - project_type: The type of project. Allowed values are 'module' and
|
44
|
* 'theme'.
|
45
|
* - project_status: This indicates if the project is enabled and will always
|
46
|
* be TRUE, as the function only returns enabled projects.
|
47
|
* - sub_themes: If the project is a theme it contains an associative array of
|
48
|
* all sub-themes.
|
49
|
* - base_themes: If the project is a theme it contains an associative array
|
50
|
* of all base-themes.
|
51
|
*
|
52
|
* @see update_process_project_info()
|
53
|
* @see update_calculate_project_data()
|
54
|
* @see update_project_cache()
|
55
|
*/
|
56
|
function update_get_projects() {
|
57
|
$projects = &drupal_static(__FUNCTION__, array());
|
58
|
if (empty($projects)) {
|
59
|
// Retrieve the projects from cache, if present.
|
60
|
$projects = update_project_cache('update_project_projects');
|
61
|
if (empty($projects)) {
|
62
|
// Still empty, so we have to rebuild the cache.
|
63
|
$module_data = system_rebuild_module_data();
|
64
|
$theme_data = system_rebuild_theme_data();
|
65
|
_update_process_info_list($projects, $module_data, 'module', TRUE);
|
66
|
_update_process_info_list($projects, $theme_data, 'theme', TRUE);
|
67
|
if (variable_get('update_check_disabled', FALSE)) {
|
68
|
_update_process_info_list($projects, $module_data, 'module', FALSE);
|
69
|
_update_process_info_list($projects, $theme_data, 'theme', FALSE);
|
70
|
}
|
71
|
// Allow other modules to alter projects before fetching and comparing.
|
72
|
drupal_alter('update_projects', $projects);
|
73
|
// Cache the site's project data for at most 1 hour.
|
74
|
_update_cache_set('update_project_projects', $projects, REQUEST_TIME + 3600);
|
75
|
}
|
76
|
}
|
77
|
return $projects;
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* Populates an array of project data.
|
82
|
*
|
83
|
* This iterates over a list of the installed modules or themes and groups them
|
84
|
* by project and status. A few parts of this function assume that enabled
|
85
|
* modules and themes are always processed first, and if disabled modules or
|
86
|
* themes are being processed (there is a setting to control if disabled code
|
87
|
* should be included or not in the 'Available updates' report), those are only
|
88
|
* processed after $projects has been populated with information about the
|
89
|
* enabled code. Modules and themes set as hidden are always ignored. This
|
90
|
* function also records the latest change time on the .info files for each
|
91
|
* module or theme, which is important data which is used when deciding if the
|
92
|
* cached available update data should be invalidated.
|
93
|
*
|
94
|
* @param $projects
|
95
|
* Reference to the array of project data of what's installed on this site.
|
96
|
* @param $list
|
97
|
* Array of data to process to add the relevant info to the $projects array.
|
98
|
* @param $project_type
|
99
|
* The kind of data in the list. Can be 'module' or 'theme'.
|
100
|
* @param $status
|
101
|
* Boolean that controls what status (enabled or disabled) to process out of
|
102
|
* the $list and add to the $projects array.
|
103
|
*
|
104
|
* @see update_get_projects()
|
105
|
*/
|
106
|
function _update_process_info_list(&$projects, $list, $project_type, $status) {
|
107
|
foreach ($list as $file) {
|
108
|
// A disabled base theme of an enabled sub-theme still has all of its code
|
109
|
// run by the sub-theme, so we include it in our "enabled" projects list.
|
110
|
if ($status && !$file->status && !empty($file->sub_themes)) {
|
111
|
foreach ($file->sub_themes as $key => $name) {
|
112
|
// Build a list of enabled sub-themes.
|
113
|
if ($list[$key]->status) {
|
114
|
$file->enabled_sub_themes[$key] = $name;
|
115
|
}
|
116
|
}
|
117
|
// If there are no enabled subthemes, we should ignore this base theme
|
118
|
// for the enabled case. If the site is trying to display disabled
|
119
|
// themes, we'll catch it then.
|
120
|
if (empty($file->enabled_sub_themes)) {
|
121
|
continue;
|
122
|
}
|
123
|
}
|
124
|
// Otherwise, just add projects of the proper status to our list.
|
125
|
elseif ($file->status != $status) {
|
126
|
continue;
|
127
|
}
|
128
|
|
129
|
// Skip if the .info file is broken.
|
130
|
if (empty($file->info)) {
|
131
|
continue;
|
132
|
}
|
133
|
|
134
|
// Skip if it's a hidden module or theme.
|
135
|
if (!empty($file->info['hidden'])) {
|
136
|
continue;
|
137
|
}
|
138
|
|
139
|
// If the .info doesn't define the 'project', try to figure it out.
|
140
|
if (!isset($file->info['project'])) {
|
141
|
$file->info['project'] = update_get_project_name($file);
|
142
|
}
|
143
|
|
144
|
// If we still don't know the 'project', give up.
|
145
|
if (empty($file->info['project'])) {
|
146
|
continue;
|
147
|
}
|
148
|
|
149
|
// If we don't already know it, grab the change time on the .info file
|
150
|
// itself. Note: we need to use the ctime, not the mtime (modification
|
151
|
// time) since many (all?) tar implementations will go out of their way to
|
152
|
// set the mtime on the files it creates to the timestamps recorded in the
|
153
|
// tarball. We want to see the last time the file was changed on disk,
|
154
|
// which is left alone by tar and correctly set to the time the .info file
|
155
|
// was unpacked.
|
156
|
if (!isset($file->info['_info_file_ctime'])) {
|
157
|
$info_filename = dirname($file->uri) . '/' . $file->name . '.info';
|
158
|
$file->info['_info_file_ctime'] = filectime($info_filename);
|
159
|
}
|
160
|
|
161
|
if (!isset($file->info['datestamp'])) {
|
162
|
$file->info['datestamp'] = 0;
|
163
|
}
|
164
|
|
165
|
$project_name = $file->info['project'];
|
166
|
|
167
|
// Figure out what project type we're going to use to display this module
|
168
|
// or theme. If the project name is 'drupal', we don't want it to show up
|
169
|
// under the usual "Modules" section, we put it at a special "Drupal Core"
|
170
|
// section at the top of the report.
|
171
|
if ($project_name == 'drupal') {
|
172
|
$project_display_type = 'core';
|
173
|
}
|
174
|
else {
|
175
|
$project_display_type = $project_type;
|
176
|
}
|
177
|
if (empty($status) && empty($file->enabled_sub_themes)) {
|
178
|
// If we're processing disabled modules or themes, append a suffix.
|
179
|
// However, we don't do this to a a base theme with enabled
|
180
|
// subthemes, since we treat that case as if it is enabled.
|
181
|
$project_display_type .= '-disabled';
|
182
|
}
|
183
|
// Add a list of sub-themes that "depend on" the project and a list of base
|
184
|
// themes that are "required by" the project.
|
185
|
if ($project_name == 'drupal') {
|
186
|
// Drupal core is always required, so this extra info would be noise.
|
187
|
$sub_themes = array();
|
188
|
$base_themes = array();
|
189
|
}
|
190
|
else {
|
191
|
// Add list of enabled sub-themes.
|
192
|
$sub_themes = !empty($file->enabled_sub_themes) ? $file->enabled_sub_themes : array();
|
193
|
// Add list of base themes.
|
194
|
$base_themes = !empty($file->base_themes) ? $file->base_themes : array();
|
195
|
}
|
196
|
if (!isset($projects[$project_name])) {
|
197
|
// Only process this if we haven't done this project, since a single
|
198
|
// project can have multiple modules or themes.
|
199
|
$projects[$project_name] = array(
|
200
|
'name' => $project_name,
|
201
|
// Only save attributes from the .info file we care about so we do not
|
202
|
// bloat our RAM usage needlessly.
|
203
|
'info' => update_filter_project_info($file->info),
|
204
|
'datestamp' => $file->info['datestamp'],
|
205
|
'includes' => array($file->name => $file->info['name']),
|
206
|
'project_type' => $project_display_type,
|
207
|
'project_status' => $status,
|
208
|
'sub_themes' => $sub_themes,
|
209
|
'base_themes' => $base_themes,
|
210
|
);
|
211
|
}
|
212
|
elseif ($projects[$project_name]['project_type'] == $project_display_type) {
|
213
|
// Only add the file we're processing to the 'includes' array for this
|
214
|
// project if it is of the same type and status (which is encoded in the
|
215
|
// $project_display_type). This prevents listing all the disabled
|
216
|
// modules included with an enabled project if we happen to be checking
|
217
|
// for disabled modules, too.
|
218
|
$projects[$project_name]['includes'][$file->name] = $file->info['name'];
|
219
|
$projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']);
|
220
|
$projects[$project_name]['datestamp'] = max($projects[$project_name]['datestamp'], $file->info['datestamp']);
|
221
|
if (!empty($sub_themes)) {
|
222
|
$projects[$project_name]['sub_themes'] += $sub_themes;
|
223
|
}
|
224
|
if (!empty($base_themes)) {
|
225
|
$projects[$project_name]['base_themes'] += $base_themes;
|
226
|
}
|
227
|
}
|
228
|
elseif (empty($status)) {
|
229
|
// If we have a project_name that matches, but the project_display_type
|
230
|
// does not, it means we're processing a disabled module or theme that
|
231
|
// belongs to a project that has some enabled code. In this case, we add
|
232
|
// the disabled thing into a separate array for separate display.
|
233
|
$projects[$project_name]['disabled'][$file->name] = $file->info['name'];
|
234
|
}
|
235
|
}
|
236
|
}
|
237
|
|
238
|
/**
|
239
|
* Determines what project a given file object belongs to.
|
240
|
*
|
241
|
* @param $file
|
242
|
* A file object as returned by system_get_files_database().
|
243
|
*
|
244
|
* @return
|
245
|
* The canonical project short name.
|
246
|
*
|
247
|
* @see system_get_files_database()
|
248
|
*/
|
249
|
function update_get_project_name($file) {
|
250
|
$project_name = '';
|
251
|
if (isset($file->info['project'])) {
|
252
|
$project_name = $file->info['project'];
|
253
|
}
|
254
|
elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core') === 0)) {
|
255
|
$project_name = 'drupal';
|
256
|
}
|
257
|
return $project_name;
|
258
|
}
|
259
|
|
260
|
/**
|
261
|
* Determines version and type information for currently installed projects.
|
262
|
*
|
263
|
* Processes the list of projects on the system to figure out the currently
|
264
|
* installed versions, and other information that is required before we can
|
265
|
* compare against the available releases to produce the status report.
|
266
|
*
|
267
|
* @param $projects
|
268
|
* Array of project information from update_get_projects().
|
269
|
*/
|
270
|
function update_process_project_info(&$projects) {
|
271
|
foreach ($projects as $key => $project) {
|
272
|
// Assume an official release until we see otherwise.
|
273
|
$install_type = 'official';
|
274
|
|
275
|
$info = $project['info'];
|
276
|
|
277
|
if (isset($info['version'])) {
|
278
|
// Check for development snapshots
|
279
|
if (preg_match('@(dev|HEAD)@', $info['version'])) {
|
280
|
$install_type = 'dev';
|
281
|
}
|
282
|
|
283
|
// Figure out what the currently installed major version is. We need
|
284
|
// to handle both contribution (e.g. "5.x-1.3", major = 1) and core
|
285
|
// (e.g. "5.1", major = 5) version strings.
|
286
|
$matches = array();
|
287
|
if (preg_match('/^(\d+\.x-)?(\d+)\..*$/', $info['version'], $matches)) {
|
288
|
$info['major'] = $matches[2];
|
289
|
}
|
290
|
elseif (!isset($info['major'])) {
|
291
|
// This would only happen for version strings that don't follow the
|
292
|
// drupal.org convention. We let contribs define "major" in their
|
293
|
// .info in this case, and only if that's missing would we hit this.
|
294
|
$info['major'] = -1;
|
295
|
}
|
296
|
}
|
297
|
else {
|
298
|
// No version info available at all.
|
299
|
$install_type = 'unknown';
|
300
|
$info['version'] = t('Unknown');
|
301
|
$info['major'] = -1;
|
302
|
}
|
303
|
|
304
|
// Finally, save the results we care about into the $projects array.
|
305
|
$projects[$key]['existing_version'] = $info['version'];
|
306
|
$projects[$key]['existing_major'] = $info['major'];
|
307
|
$projects[$key]['install_type'] = $install_type;
|
308
|
}
|
309
|
}
|
310
|
|
311
|
/**
|
312
|
* Calculates the current update status of all projects on the site.
|
313
|
*
|
314
|
* The results of this function are expensive to compute, especially on sites
|
315
|
* with lots of modules or themes, since it involves a lot of comparisons and
|
316
|
* other operations. Therefore, we cache the results into the {cache_update}
|
317
|
* table using the 'update_project_data' cache ID. However, since this is not
|
318
|
* the data about available updates fetched from the network, it is ok to
|
319
|
* invalidate it somewhat quickly. If we keep this data for very long, site
|
320
|
* administrators are more likely to see incorrect results if they upgrade to a
|
321
|
* newer version of a module or theme but do not visit certain pages that
|
322
|
* automatically clear this cache.
|
323
|
*
|
324
|
* @param array $available
|
325
|
* Data about available project releases.
|
326
|
*
|
327
|
* @return
|
328
|
* An array of installed projects with current update status information.
|
329
|
*
|
330
|
* @see update_get_available()
|
331
|
* @see update_get_projects()
|
332
|
* @see update_process_project_info()
|
333
|
* @see update_project_cache()
|
334
|
*/
|
335
|
function update_calculate_project_data($available) {
|
336
|
// Retrieve the projects from cache, if present.
|
337
|
$projects = update_project_cache('update_project_data');
|
338
|
// If $projects is empty, then the cache must be rebuilt.
|
339
|
// Otherwise, return the cached data and skip the rest of the function.
|
340
|
if (!empty($projects)) {
|
341
|
return $projects;
|
342
|
}
|
343
|
$projects = update_get_projects();
|
344
|
update_process_project_info($projects);
|
345
|
foreach ($projects as $project => $project_info) {
|
346
|
if (isset($available[$project])) {
|
347
|
update_calculate_project_update_status($project, $projects[$project], $available[$project]);
|
348
|
}
|
349
|
else {
|
350
|
$projects[$project]['status'] = UPDATE_UNKNOWN;
|
351
|
$projects[$project]['reason'] = t('No available releases found');
|
352
|
}
|
353
|
}
|
354
|
// Give other modules a chance to alter the status (for example, to allow a
|
355
|
// contrib module to provide fine-grained settings to ignore specific
|
356
|
// projects or releases).
|
357
|
drupal_alter('update_status', $projects);
|
358
|
|
359
|
// Cache the site's update status for at most 1 hour.
|
360
|
_update_cache_set('update_project_data', $projects, REQUEST_TIME + 3600);
|
361
|
return $projects;
|
362
|
}
|
363
|
|
364
|
/**
|
365
|
* Calculates the current update status of a specific project.
|
366
|
*
|
367
|
* This function is the heart of the update status feature. For each project it
|
368
|
* is invoked with, it first checks if the project has been flagged with a
|
369
|
* special status like "unsupported" or "insecure", or if the project node
|
370
|
* itself has been unpublished. In any of those cases, the project is marked
|
371
|
* with an error and the next project is considered.
|
372
|
*
|
373
|
* If the project itself is valid, the function decides what major release
|
374
|
* series to consider. The project defines what the currently supported major
|
375
|
* versions are for each version of core, so the first step is to make sure the
|
376
|
* current version is still supported. If so, that's the target version. If the
|
377
|
* current version is unsupported, the project maintainer's recommended major
|
378
|
* version is used. There's also a check to make sure that this function never
|
379
|
* recommends an earlier release than the currently installed major version.
|
380
|
*
|
381
|
* Given a target major version, the available releases are scanned looking for
|
382
|
* the specific release to recommend (avoiding beta releases and development
|
383
|
* snapshots if possible). For the target major version, the highest patch level
|
384
|
* is found. If there is a release at that patch level with no extra ("beta",
|
385
|
* etc.), then the release at that patch level with the most recent release date
|
386
|
* is recommended. If every release at that patch level has extra (only betas),
|
387
|
* then the latest release from the previous patch level is recommended. For
|
388
|
* example:
|
389
|
*
|
390
|
* - 1.6-bugfix <-- recommended version because 1.6 already exists.
|
391
|
* - 1.6
|
392
|
*
|
393
|
* or
|
394
|
*
|
395
|
* - 1.6-beta
|
396
|
* - 1.5 <-- recommended version because no 1.6 exists.
|
397
|
* - 1.4
|
398
|
*
|
399
|
* Also, the latest release from the same major version is looked for, even beta
|
400
|
* releases, to display to the user as the "Latest version" option.
|
401
|
* Additionally, the latest official release from any higher major versions that
|
402
|
* have been released is searched for to provide a set of "Also available"
|
403
|
* options.
|
404
|
*
|
405
|
* Finally, and most importantly, the release history continues to be scanned
|
406
|
* until the currently installed release is reached, searching for anything
|
407
|
* marked as a security update. If any security updates have been found between
|
408
|
* the recommended release and the installed version, all of the releases that
|
409
|
* included a security fix are recorded so that the site administrator can be
|
410
|
* warned their site is insecure, and links pointing to the release notes for
|
411
|
* each security update can be included (which, in turn, will link to the
|
412
|
* official security announcements for each vulnerability).
|
413
|
*
|
414
|
* This function relies on the fact that the .xml release history data comes
|
415
|
* sorted based on major version and patch level, then finally by release date
|
416
|
* if there are multiple releases such as betas from the same major.patch
|
417
|
* version (e.g., 5.x-1.5-beta1, 5.x-1.5-beta2, and 5.x-1.5). Development
|
418
|
* snapshots for a given major version are always listed last.
|
419
|
*
|
420
|
* @param $unused
|
421
|
* Input is not being used, but remains in function for API compatibility
|
422
|
* reasons.
|
423
|
* @param $project_data
|
424
|
* An array containing information about a specific project.
|
425
|
* @param $available
|
426
|
* Data about available project releases of a specific project.
|
427
|
*/
|
428
|
function update_calculate_project_update_status($unused, &$project_data, $available) {
|
429
|
foreach (array('title', 'link') as $attribute) {
|
430
|
if (!isset($project_data[$attribute]) && isset($available[$attribute])) {
|
431
|
$project_data[$attribute] = $available[$attribute];
|
432
|
}
|
433
|
}
|
434
|
|
435
|
// If the project status is marked as something bad, there's nothing else
|
436
|
// to consider.
|
437
|
if (isset($available['project_status'])) {
|
438
|
switch ($available['project_status']) {
|
439
|
case 'insecure':
|
440
|
$project_data['status'] = UPDATE_NOT_SECURE;
|
441
|
if (empty($project_data['extra'])) {
|
442
|
$project_data['extra'] = array();
|
443
|
}
|
444
|
$project_data['extra'][] = array(
|
445
|
'class' => array('project-not-secure'),
|
446
|
'label' => t('Project not secure'),
|
447
|
'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!'),
|
448
|
);
|
449
|
break;
|
450
|
case 'unpublished':
|
451
|
case 'revoked':
|
452
|
$project_data['status'] = UPDATE_REVOKED;
|
453
|
if (empty($project_data['extra'])) {
|
454
|
$project_data['extra'] = array();
|
455
|
}
|
456
|
$project_data['extra'][] = array(
|
457
|
'class' => array('project-revoked'),
|
458
|
'label' => t('Project revoked'),
|
459
|
'data' => t('This project has been revoked, and is no longer available for download. Disabling everything included by this project is strongly recommended!'),
|
460
|
);
|
461
|
break;
|
462
|
case 'unsupported':
|
463
|
$project_data['status'] = UPDATE_NOT_SUPPORTED;
|
464
|
if (empty($project_data['extra'])) {
|
465
|
$project_data['extra'] = array();
|
466
|
}
|
467
|
$project_data['extra'][] = array(
|
468
|
'class' => array('project-not-supported'),
|
469
|
'label' => t('Project not supported'),
|
470
|
'data' => t('This project is no longer supported, and is no longer available for download. Disabling everything included by this project is strongly recommended!'),
|
471
|
);
|
472
|
break;
|
473
|
case 'not-fetched':
|
474
|
$project_data['status'] = UPDATE_NOT_FETCHED;
|
475
|
$project_data['reason'] = t('Failed to get available update data.');
|
476
|
break;
|
477
|
|
478
|
default:
|
479
|
// Assume anything else (e.g. 'published') is valid and we should
|
480
|
// perform the rest of the logic in this function.
|
481
|
break;
|
482
|
}
|
483
|
}
|
484
|
|
485
|
if (!empty($project_data['status'])) {
|
486
|
// We already know the status for this project, so there's nothing else to
|
487
|
// compute. Record the project status into $project_data and we're done.
|
488
|
$project_data['project_status'] = $available['project_status'];
|
489
|
return;
|
490
|
}
|
491
|
|
492
|
// Figure out the target major version.
|
493
|
$existing_major = $project_data['existing_major'];
|
494
|
$supported_majors = array();
|
495
|
if (isset($available['supported_majors'])) {
|
496
|
$supported_majors = explode(',', $available['supported_majors']);
|
497
|
}
|
498
|
elseif (isset($available['default_major'])) {
|
499
|
// Older release history XML file without supported or recommended.
|
500
|
$supported_majors[] = $available['default_major'];
|
501
|
}
|
502
|
|
503
|
if (in_array($existing_major, $supported_majors)) {
|
504
|
// Still supported, stay at the current major version.
|
505
|
$target_major = $existing_major;
|
506
|
}
|
507
|
elseif (isset($available['recommended_major'])) {
|
508
|
// Since 'recommended_major' is defined, we know this is the new XML
|
509
|
// format. Therefore, we know the current release is unsupported since
|
510
|
// its major version was not in the 'supported_majors' list. We should
|
511
|
// find the best release from the recommended major version.
|
512
|
$target_major = $available['recommended_major'];
|
513
|
$project_data['status'] = UPDATE_NOT_SUPPORTED;
|
514
|
}
|
515
|
elseif (isset($available['default_major'])) {
|
516
|
// Older release history XML file without recommended, so recommend
|
517
|
// the currently defined "default_major" version.
|
518
|
$target_major = $available['default_major'];
|
519
|
}
|
520
|
else {
|
521
|
// Malformed XML file? Stick with the current version.
|
522
|
$target_major = $existing_major;
|
523
|
}
|
524
|
|
525
|
// Make sure we never tell the admin to downgrade. If we recommended an
|
526
|
// earlier version than the one they're running, they'd face an
|
527
|
// impossible data migration problem, since Drupal never supports a DB
|
528
|
// downgrade path. In the unfortunate case that what they're running is
|
529
|
// unsupported, and there's nothing newer for them to upgrade to, we
|
530
|
// can't print out a "Recommended version", but just have to tell them
|
531
|
// what they have is unsupported and let them figure it out.
|
532
|
$target_major = max($existing_major, $target_major);
|
533
|
|
534
|
$release_patch_changed = '';
|
535
|
$patch = '';
|
536
|
|
537
|
// If the project is marked as UPDATE_FETCH_PENDING, it means that the
|
538
|
// data we currently have (if any) is stale, and we've got a task queued
|
539
|
// up to (re)fetch the data. In that case, we mark it as such, merge in
|
540
|
// whatever data we have (e.g. project title and link), and move on.
|
541
|
if (!empty($available['fetch_status']) && $available['fetch_status'] == UPDATE_FETCH_PENDING) {
|
542
|
$project_data['status'] = UPDATE_FETCH_PENDING;
|
543
|
$project_data['reason'] = t('No available update data');
|
544
|
$project_data['fetch_status'] = $available['fetch_status'];
|
545
|
return;
|
546
|
}
|
547
|
|
548
|
// Defend ourselves from XML history files that contain no releases.
|
549
|
if (empty($available['releases'])) {
|
550
|
$project_data['status'] = UPDATE_UNKNOWN;
|
551
|
$project_data['reason'] = t('No available releases found');
|
552
|
return;
|
553
|
}
|
554
|
foreach ($available['releases'] as $version => $release) {
|
555
|
// First, if this is the existing release, check a few conditions.
|
556
|
if ($project_data['existing_version'] === $version) {
|
557
|
if (isset($release['terms']['Release type']) &&
|
558
|
in_array('Insecure', $release['terms']['Release type'])) {
|
559
|
$project_data['status'] = UPDATE_NOT_SECURE;
|
560
|
}
|
561
|
elseif ($release['status'] == 'unpublished') {
|
562
|
$project_data['status'] = UPDATE_REVOKED;
|
563
|
if (empty($project_data['extra'])) {
|
564
|
$project_data['extra'] = array();
|
565
|
}
|
566
|
$project_data['extra'][] = array(
|
567
|
'class' => array('release-revoked'),
|
568
|
'label' => t('Release revoked'),
|
569
|
'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!'),
|
570
|
);
|
571
|
}
|
572
|
elseif (isset($release['terms']['Release type']) &&
|
573
|
in_array('Unsupported', $release['terms']['Release type'])) {
|
574
|
$project_data['status'] = UPDATE_NOT_SUPPORTED;
|
575
|
if (empty($project_data['extra'])) {
|
576
|
$project_data['extra'] = array();
|
577
|
}
|
578
|
$project_data['extra'][] = array(
|
579
|
'class' => array('release-not-supported'),
|
580
|
'label' => t('Release not supported'),
|
581
|
'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!'),
|
582
|
);
|
583
|
}
|
584
|
}
|
585
|
|
586
|
// Otherwise, ignore unpublished, insecure, or unsupported releases.
|
587
|
if ($release['status'] == 'unpublished' ||
|
588
|
(isset($release['terms']['Release type']) &&
|
589
|
(in_array('Insecure', $release['terms']['Release type']) ||
|
590
|
in_array('Unsupported', $release['terms']['Release type'])))) {
|
591
|
continue;
|
592
|
}
|
593
|
|
594
|
// See if this is a higher major version than our target and yet still
|
595
|
// supported. If so, record it as an "Also available" release.
|
596
|
// Note: some projects have a HEAD release from CVS days, which could
|
597
|
// be one of those being compared. They would not have version_major
|
598
|
// set, so we must call isset first.
|
599
|
if (isset($release['version_major']) && $release['version_major'] > $target_major) {
|
600
|
if (in_array($release['version_major'], $supported_majors)) {
|
601
|
if (!isset($project_data['also'])) {
|
602
|
$project_data['also'] = array();
|
603
|
}
|
604
|
if (!isset($project_data['also'][$release['version_major']])) {
|
605
|
$project_data['also'][$release['version_major']] = $version;
|
606
|
$project_data['releases'][$version] = $release;
|
607
|
}
|
608
|
}
|
609
|
// Otherwise, this release can't matter to us, since it's neither
|
610
|
// from the release series we're currently using nor the recommended
|
611
|
// release. We don't even care about security updates for this
|
612
|
// branch, since if a project maintainer puts out a security release
|
613
|
// at a higher major version and not at the lower major version,
|
614
|
// they must remove the lower version from the supported major
|
615
|
// versions at the same time, in which case we won't hit this code.
|
616
|
continue;
|
617
|
}
|
618
|
|
619
|
// Look for the 'latest version' if we haven't found it yet. Latest is
|
620
|
// defined as the most recent version for the target major version.
|
621
|
if (!isset($project_data['latest_version'])
|
622
|
&& $release['version_major'] == $target_major) {
|
623
|
$project_data['latest_version'] = $version;
|
624
|
$project_data['releases'][$version] = $release;
|
625
|
}
|
626
|
|
627
|
// Look for the development snapshot release for this branch.
|
628
|
if (!isset($project_data['dev_version'])
|
629
|
&& $release['version_major'] == $target_major
|
630
|
&& isset($release['version_extra'])
|
631
|
&& $release['version_extra'] == 'dev') {
|
632
|
$project_data['dev_version'] = $version;
|
633
|
$project_data['releases'][$version] = $release;
|
634
|
}
|
635
|
|
636
|
// Look for the 'recommended' version if we haven't found it yet (see
|
637
|
// phpdoc at the top of this function for the definition).
|
638
|
if (!isset($project_data['recommended'])
|
639
|
&& $release['version_major'] == $target_major
|
640
|
&& isset($release['version_patch'])) {
|
641
|
if ($patch != $release['version_patch']) {
|
642
|
$patch = $release['version_patch'];
|
643
|
$release_patch_changed = $release;
|
644
|
}
|
645
|
if (empty($release['version_extra']) && $patch == $release['version_patch']) {
|
646
|
$project_data['recommended'] = $release_patch_changed['version'];
|
647
|
$project_data['releases'][$release_patch_changed['version']] = $release_patch_changed;
|
648
|
}
|
649
|
}
|
650
|
|
651
|
// Stop searching once we hit the currently installed version.
|
652
|
if ($project_data['existing_version'] === $version) {
|
653
|
break;
|
654
|
}
|
655
|
|
656
|
// If we're running a dev snapshot and have a timestamp, stop
|
657
|
// searching for security updates once we hit an official release
|
658
|
// older than what we've got. Allow 100 seconds of leeway to handle
|
659
|
// differences between the datestamp in the .info file and the
|
660
|
// timestamp of the tarball itself (which are usually off by 1 or 2
|
661
|
// seconds) so that we don't flag that as a new release.
|
662
|
if ($project_data['install_type'] == 'dev') {
|
663
|
if (empty($project_data['datestamp'])) {
|
664
|
// We don't have current timestamp info, so we can't know.
|
665
|
continue;
|
666
|
}
|
667
|
elseif (isset($release['date']) && ($project_data['datestamp'] + 100 > $release['date'])) {
|
668
|
// We're newer than this, so we can skip it.
|
669
|
continue;
|
670
|
}
|
671
|
}
|
672
|
|
673
|
// See if this release is a security update.
|
674
|
if (isset($release['terms']['Release type'])
|
675
|
&& in_array('Security update', $release['terms']['Release type'])) {
|
676
|
$project_data['security updates'][] = $release;
|
677
|
}
|
678
|
}
|
679
|
|
680
|
// If we were unable to find a recommended version, then make the latest
|
681
|
// version the recommended version if possible.
|
682
|
if (!isset($project_data['recommended']) && isset($project_data['latest_version'])) {
|
683
|
$project_data['recommended'] = $project_data['latest_version'];
|
684
|
}
|
685
|
|
686
|
//
|
687
|
// Check to see if we need an update or not.
|
688
|
//
|
689
|
|
690
|
if (!empty($project_data['security updates'])) {
|
691
|
// If we found security updates, that always trumps any other status.
|
692
|
$project_data['status'] = UPDATE_NOT_SECURE;
|
693
|
}
|
694
|
|
695
|
if (isset($project_data['status'])) {
|
696
|
// If we already know the status, we're done.
|
697
|
return;
|
698
|
}
|
699
|
|
700
|
// If we don't know what to recommend, there's nothing we can report.
|
701
|
// Bail out early.
|
702
|
if (!isset($project_data['recommended'])) {
|
703
|
$project_data['status'] = UPDATE_UNKNOWN;
|
704
|
$project_data['reason'] = t('No available releases found');
|
705
|
return;
|
706
|
}
|
707
|
|
708
|
// If we're running a dev snapshot, compare the date of the dev snapshot
|
709
|
// with the latest official version, and record the absolute latest in
|
710
|
// 'latest_dev' so we can correctly decide if there's a newer release
|
711
|
// than our current snapshot.
|
712
|
if ($project_data['install_type'] == 'dev') {
|
713
|
if (isset($project_data['dev_version']) && $available['releases'][$project_data['dev_version']]['date'] > $available['releases'][$project_data['latest_version']]['date']) {
|
714
|
$project_data['latest_dev'] = $project_data['dev_version'];
|
715
|
}
|
716
|
else {
|
717
|
$project_data['latest_dev'] = $project_data['latest_version'];
|
718
|
}
|
719
|
}
|
720
|
|
721
|
// Figure out the status, based on what we've seen and the install type.
|
722
|
switch ($project_data['install_type']) {
|
723
|
case 'official':
|
724
|
if ($project_data['existing_version'] === $project_data['recommended'] || $project_data['existing_version'] === $project_data['latest_version']) {
|
725
|
$project_data['status'] = UPDATE_CURRENT;
|
726
|
}
|
727
|
else {
|
728
|
$project_data['status'] = UPDATE_NOT_CURRENT;
|
729
|
}
|
730
|
break;
|
731
|
|
732
|
case 'dev':
|
733
|
$latest = $available['releases'][$project_data['latest_dev']];
|
734
|
if (empty($project_data['datestamp'])) {
|
735
|
$project_data['status'] = UPDATE_NOT_CHECKED;
|
736
|
$project_data['reason'] = t('Unknown release date');
|
737
|
}
|
738
|
elseif (($project_data['datestamp'] + 100 > $latest['date'])) {
|
739
|
$project_data['status'] = UPDATE_CURRENT;
|
740
|
}
|
741
|
else {
|
742
|
$project_data['status'] = UPDATE_NOT_CURRENT;
|
743
|
}
|
744
|
break;
|
745
|
|
746
|
default:
|
747
|
$project_data['status'] = UPDATE_UNKNOWN;
|
748
|
$project_data['reason'] = t('Invalid info');
|
749
|
}
|
750
|
}
|
751
|
|
752
|
/**
|
753
|
* Retrieves data from {cache_update} or empties the cache when necessary.
|
754
|
*
|
755
|
* Two very expensive arrays computed by this module are the list of all
|
756
|
* installed modules and themes (and .info data, project associations, etc), and
|
757
|
* the current status of the site relative to the currently available releases.
|
758
|
* These two arrays are cached in the {cache_update} table and used whenever
|
759
|
* possible. The cache is cleared whenever the administrator visits the status
|
760
|
* report, available updates report, or the module or theme administration
|
761
|
* pages, since we should always recompute the most current values on any of
|
762
|
* those pages.
|
763
|
*
|
764
|
* Note: while both of these arrays are expensive to compute (in terms of disk
|
765
|
* I/O and some fairly heavy CPU processing), neither of these is the actual
|
766
|
* data about available updates that we have to fetch over the network from
|
767
|
* updates.drupal.org. That information is stored with the
|
768
|
* 'update_available_releases' cache ID -- it needs to persist longer than 1
|
769
|
* hour and never get invalidated just by visiting a page on the site.
|
770
|
*
|
771
|
* @param $cid
|
772
|
* The cache ID of data to return from the cache. Valid options are
|
773
|
* 'update_project_data' and 'update_project_projects'.
|
774
|
*
|
775
|
* @return
|
776
|
* The cached value of the $projects array generated by
|
777
|
* update_calculate_project_data() or update_get_projects(), or an empty array
|
778
|
* when the cache is cleared.
|
779
|
*/
|
780
|
function update_project_cache($cid) {
|
781
|
$projects = array();
|
782
|
|
783
|
// On certain paths, we should clear the cache and recompute the projects for
|
784
|
// update status of the site to avoid presenting stale information.
|
785
|
$q = $_GET['q'];
|
786
|
$paths = array(
|
787
|
'admin/modules',
|
788
|
'admin/modules/update',
|
789
|
'admin/appearance',
|
790
|
'admin/appearance/update',
|
791
|
'admin/reports',
|
792
|
'admin/reports/updates',
|
793
|
'admin/reports/updates/update',
|
794
|
'admin/reports/status',
|
795
|
'admin/reports/updates/check',
|
796
|
);
|
797
|
if (in_array($q, $paths)) {
|
798
|
_update_cache_clear($cid);
|
799
|
}
|
800
|
else {
|
801
|
$cache = _update_cache_get($cid);
|
802
|
if (!empty($cache->data) && $cache->expire > REQUEST_TIME) {
|
803
|
$projects = $cache->data;
|
804
|
}
|
805
|
}
|
806
|
return $projects;
|
807
|
}
|
808
|
|
809
|
/**
|
810
|
* Filters the project .info data to only save attributes we need.
|
811
|
*
|
812
|
* @param array $info
|
813
|
* Array of .info file data as returned by drupal_parse_info_file().
|
814
|
*
|
815
|
* @return
|
816
|
* Array of .info file data we need for the update manager.
|
817
|
*
|
818
|
* @see _update_process_info_list()
|
819
|
*/
|
820
|
function update_filter_project_info($info) {
|
821
|
$whitelist = array(
|
822
|
'_info_file_ctime',
|
823
|
'datestamp',
|
824
|
'major',
|
825
|
'name',
|
826
|
'package',
|
827
|
'project',
|
828
|
'project status url',
|
829
|
'version',
|
830
|
);
|
831
|
return array_intersect_key($info, drupal_map_assoc($whitelist));
|
832
|
}
|