Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Code required only when comparing available updates to existing data.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Determines version and type information for currently installed projects.
|
Chris@0
|
10 *
|
Chris@0
|
11 * Processes the list of projects on the system to figure out the currently
|
Chris@0
|
12 * installed versions, and other information that is required before we can
|
Chris@0
|
13 * compare against the available releases to produce the status report.
|
Chris@0
|
14 *
|
Chris@0
|
15 * @param $projects
|
Chris@0
|
16 * Array of project information from
|
Chris@0
|
17 * \Drupal\Update\UpdateManager::getProjects().
|
Chris@0
|
18 */
|
Chris@0
|
19 function update_process_project_info(&$projects) {
|
Chris@0
|
20 foreach ($projects as $key => $project) {
|
Chris@0
|
21 // Assume an official release until we see otherwise.
|
Chris@0
|
22 $install_type = 'official';
|
Chris@0
|
23
|
Chris@0
|
24 $info = $project['info'];
|
Chris@0
|
25
|
Chris@0
|
26 if (isset($info['version'])) {
|
Chris@0
|
27 // Check for development snapshots
|
Chris@0
|
28 if (preg_match('@(dev|HEAD)@', $info['version'])) {
|
Chris@0
|
29 $install_type = 'dev';
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 // Figure out what the currently installed major version is. We need
|
Chris@0
|
33 // to handle both contribution (e.g. "5.x-1.3", major = 1) and core
|
Chris@0
|
34 // (e.g. "5.1", major = 5) version strings.
|
Chris@0
|
35 $matches = [];
|
Chris@0
|
36 if (preg_match('/^(\d+\.x-)?(\d+)\..*$/', $info['version'], $matches)) {
|
Chris@0
|
37 $info['major'] = $matches[2];
|
Chris@0
|
38 }
|
Chris@0
|
39 elseif (!isset($info['major'])) {
|
Chris@0
|
40 // This would only happen for version strings that don't follow the
|
Chris@0
|
41 // drupal.org convention. We let contribs define "major" in their
|
Chris@0
|
42 // .info.yml in this case, and only if that's missing would we hit this.
|
Chris@0
|
43 $info['major'] = -1;
|
Chris@0
|
44 }
|
Chris@0
|
45 }
|
Chris@0
|
46 else {
|
Chris@0
|
47 // No version info available at all.
|
Chris@0
|
48 $install_type = 'unknown';
|
Chris@0
|
49 $info['version'] = t('Unknown');
|
Chris@0
|
50 $info['major'] = -1;
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 // Finally, save the results we care about into the $projects array.
|
Chris@0
|
54 $projects[$key]['existing_version'] = $info['version'];
|
Chris@0
|
55 $projects[$key]['existing_major'] = $info['major'];
|
Chris@0
|
56 $projects[$key]['install_type'] = $install_type;
|
Chris@0
|
57 }
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 /**
|
Chris@0
|
61 * Calculates the current update status of all projects on the site.
|
Chris@0
|
62 *
|
Chris@0
|
63 * The results of this function are expensive to compute, especially on sites
|
Chris@0
|
64 * with lots of modules or themes, since it involves a lot of comparisons and
|
Chris@0
|
65 * other operations. Therefore, we store the results. However, since this is not
|
Chris@0
|
66 * the data about available updates fetched from the network, it is ok to
|
Chris@0
|
67 * invalidate it somewhat quickly. If we keep this data for very long, site
|
Chris@0
|
68 * administrators are more likely to see incorrect results if they upgrade to a
|
Chris@0
|
69 * newer version of a module or theme but do not visit certain pages that
|
Chris@0
|
70 * automatically clear this.
|
Chris@0
|
71 *
|
Chris@0
|
72 * @param array $available
|
Chris@0
|
73 * Data about available project releases.
|
Chris@0
|
74 *
|
Chris@0
|
75 * @return
|
Chris@0
|
76 * An array of installed projects with current update status information.
|
Chris@0
|
77 *
|
Chris@0
|
78 * @see update_get_available()
|
Chris@0
|
79 * @see \Drupal\Update\UpdateManager::getProjects()
|
Chris@0
|
80 * @see update_process_project_info()
|
Chris@0
|
81 * @see \Drupal\update\UpdateManagerInterface::projectStorage()
|
Chris@0
|
82 */
|
Chris@0
|
83 function update_calculate_project_data($available) {
|
Chris@0
|
84 // Retrieve the projects from storage, if present.
|
Chris@0
|
85 $projects = \Drupal::service('update.manager')->projectStorage('update_project_data');
|
Chris@0
|
86 // If $projects is empty, then the data must be rebuilt.
|
Chris@0
|
87 // Otherwise, return the data and skip the rest of the function.
|
Chris@0
|
88 if (!empty($projects)) {
|
Chris@0
|
89 return $projects;
|
Chris@0
|
90 }
|
Chris@0
|
91 $projects = \Drupal::service('update.manager')->getProjects();
|
Chris@0
|
92 update_process_project_info($projects);
|
Chris@0
|
93 foreach ($projects as $project => $project_info) {
|
Chris@0
|
94 if (isset($available[$project])) {
|
Chris@0
|
95 update_calculate_project_update_status($projects[$project], $available[$project]);
|
Chris@0
|
96 }
|
Chris@0
|
97 else {
|
Chris@0
|
98 $projects[$project]['status'] = UPDATE_UNKNOWN;
|
Chris@0
|
99 $projects[$project]['reason'] = t('No available releases found');
|
Chris@0
|
100 }
|
Chris@0
|
101 }
|
Chris@0
|
102 // Give other modules a chance to alter the status (for example, to allow a
|
Chris@0
|
103 // contrib module to provide fine-grained settings to ignore specific
|
Chris@0
|
104 // projects or releases).
|
Chris@0
|
105 \Drupal::moduleHandler()->alter('update_status', $projects);
|
Chris@0
|
106
|
Chris@0
|
107 // Store the site's update status for at most 1 hour.
|
Chris@0
|
108 \Drupal::keyValueExpirable('update')->setWithExpire('update_project_data', $projects, 3600);
|
Chris@0
|
109 return $projects;
|
Chris@0
|
110 }
|
Chris@0
|
111
|
Chris@0
|
112 /**
|
Chris@0
|
113 * Calculates the current update status of a specific project.
|
Chris@0
|
114 *
|
Chris@0
|
115 * This function is the heart of the update status feature. For each project it
|
Chris@0
|
116 * is invoked with, it first checks if the project has been flagged with a
|
Chris@0
|
117 * special status like "unsupported" or "insecure", or if the project node
|
Chris@0
|
118 * itself has been unpublished. In any of those cases, the project is marked
|
Chris@0
|
119 * with an error and the next project is considered.
|
Chris@0
|
120 *
|
Chris@0
|
121 * If the project itself is valid, the function decides what major release
|
Chris@0
|
122 * series to consider. The project defines what the currently supported major
|
Chris@0
|
123 * versions are for each version of core, so the first step is to make sure the
|
Chris@0
|
124 * current version is still supported. If so, that's the target version. If the
|
Chris@0
|
125 * current version is unsupported, the project maintainer's recommended major
|
Chris@0
|
126 * version is used. There's also a check to make sure that this function never
|
Chris@0
|
127 * recommends an earlier release than the currently installed major version.
|
Chris@0
|
128 *
|
Chris@0
|
129 * Given a target major version, the available releases are scanned looking for
|
Chris@0
|
130 * the specific release to recommend (avoiding beta releases and development
|
Chris@0
|
131 * snapshots if possible). For the target major version, the highest patch level
|
Chris@0
|
132 * is found. If there is a release at that patch level with no extra ("beta",
|
Chris@0
|
133 * etc.), then the release at that patch level with the most recent release date
|
Chris@0
|
134 * is recommended. If every release at that patch level has extra (only betas),
|
Chris@0
|
135 * then the latest release from the previous patch level is recommended. For
|
Chris@0
|
136 * example:
|
Chris@0
|
137 *
|
Chris@0
|
138 * - 1.6-bugfix <-- recommended version because 1.6 already exists.
|
Chris@0
|
139 * - 1.6
|
Chris@0
|
140 *
|
Chris@0
|
141 * or
|
Chris@0
|
142 *
|
Chris@0
|
143 * - 1.6-beta
|
Chris@0
|
144 * - 1.5 <-- recommended version because no 1.6 exists.
|
Chris@0
|
145 * - 1.4
|
Chris@0
|
146 *
|
Chris@0
|
147 * Also, the latest release from the same major version is looked for, even beta
|
Chris@0
|
148 * releases, to display to the user as the "Latest version" option.
|
Chris@0
|
149 * Additionally, the latest official release from any higher major versions that
|
Chris@0
|
150 * have been released is searched for to provide a set of "Also available"
|
Chris@0
|
151 * options.
|
Chris@0
|
152 *
|
Chris@0
|
153 * Finally, and most importantly, the release history continues to be scanned
|
Chris@0
|
154 * until the currently installed release is reached, searching for anything
|
Chris@0
|
155 * marked as a security update. If any security updates have been found between
|
Chris@0
|
156 * the recommended release and the installed version, all of the releases that
|
Chris@0
|
157 * included a security fix are recorded so that the site administrator can be
|
Chris@0
|
158 * warned their site is insecure, and links pointing to the release notes for
|
Chris@0
|
159 * each security update can be included (which, in turn, will link to the
|
Chris@0
|
160 * official security announcements for each vulnerability).
|
Chris@0
|
161 *
|
Chris@0
|
162 * This function relies on the fact that the .xml release history data comes
|
Chris@0
|
163 * sorted based on major version and patch level, then finally by release date
|
Chris@0
|
164 * if there are multiple releases such as betas from the same major.patch
|
Chris@0
|
165 * version (e.g., 5.x-1.5-beta1, 5.x-1.5-beta2, and 5.x-1.5). Development
|
Chris@0
|
166 * snapshots for a given major version are always listed last.
|
Chris@0
|
167 *
|
Chris@0
|
168 * @param $project_data
|
Chris@0
|
169 * An array containing information about a specific project.
|
Chris@0
|
170 * @param $available
|
Chris@0
|
171 * Data about available project releases of a specific project.
|
Chris@0
|
172 */
|
Chris@0
|
173 function update_calculate_project_update_status(&$project_data, $available) {
|
Chris@0
|
174 foreach (['title', 'link'] as $attribute) {
|
Chris@0
|
175 if (!isset($project_data[$attribute]) && isset($available[$attribute])) {
|
Chris@0
|
176 $project_data[$attribute] = $available[$attribute];
|
Chris@0
|
177 }
|
Chris@0
|
178 }
|
Chris@0
|
179
|
Chris@0
|
180 // If the project status is marked as something bad, there's nothing else
|
Chris@0
|
181 // to consider.
|
Chris@0
|
182 if (isset($available['project_status'])) {
|
Chris@0
|
183 switch ($available['project_status']) {
|
Chris@0
|
184 case 'insecure':
|
Chris@0
|
185 $project_data['status'] = UPDATE_NOT_SECURE;
|
Chris@0
|
186 if (empty($project_data['extra'])) {
|
Chris@0
|
187 $project_data['extra'] = [];
|
Chris@0
|
188 }
|
Chris@0
|
189 $project_data['extra'][] = [
|
Chris@0
|
190 'label' => t('Project not secure'),
|
Chris@0
|
191 '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!'),
|
Chris@0
|
192 ];
|
Chris@0
|
193 break;
|
Chris@0
|
194 case 'unpublished':
|
Chris@0
|
195 case 'revoked':
|
Chris@0
|
196 $project_data['status'] = UPDATE_REVOKED;
|
Chris@0
|
197 if (empty($project_data['extra'])) {
|
Chris@0
|
198 $project_data['extra'] = [];
|
Chris@0
|
199 }
|
Chris@0
|
200 $project_data['extra'][] = [
|
Chris@0
|
201 'label' => t('Project revoked'),
|
Chris@0
|
202 'data' => t('This project has been revoked, and is no longer available for download. Disabling everything included by this project is strongly recommended!'),
|
Chris@0
|
203 ];
|
Chris@0
|
204 break;
|
Chris@0
|
205 case 'unsupported':
|
Chris@0
|
206 $project_data['status'] = UPDATE_NOT_SUPPORTED;
|
Chris@0
|
207 if (empty($project_data['extra'])) {
|
Chris@0
|
208 $project_data['extra'] = [];
|
Chris@0
|
209 }
|
Chris@0
|
210 $project_data['extra'][] = [
|
Chris@0
|
211 'label' => t('Project not supported'),
|
Chris@0
|
212 'data' => t('This project is no longer supported, and is no longer available for download. Disabling everything included by this project is strongly recommended!'),
|
Chris@0
|
213 ];
|
Chris@0
|
214 break;
|
Chris@0
|
215 case 'not-fetched':
|
Chris@0
|
216 $project_data['status'] = UPDATE_NOT_FETCHED;
|
Chris@0
|
217 $project_data['reason'] = t('Failed to get available update data.');
|
Chris@0
|
218 break;
|
Chris@0
|
219
|
Chris@0
|
220 default:
|
Chris@0
|
221 // Assume anything else (e.g. 'published') is valid and we should
|
Chris@0
|
222 // perform the rest of the logic in this function.
|
Chris@0
|
223 break;
|
Chris@0
|
224 }
|
Chris@0
|
225 }
|
Chris@0
|
226
|
Chris@0
|
227 if (!empty($project_data['status'])) {
|
Chris@0
|
228 // We already know the status for this project, so there's nothing else to
|
Chris@0
|
229 // compute. Record the project status into $project_data and we're done.
|
Chris@0
|
230 $project_data['project_status'] = $available['project_status'];
|
Chris@0
|
231 return;
|
Chris@0
|
232 }
|
Chris@0
|
233
|
Chris@0
|
234 // Figure out the target major version.
|
Chris@0
|
235 $existing_major = $project_data['existing_major'];
|
Chris@0
|
236 $supported_majors = [];
|
Chris@0
|
237 if (isset($available['supported_majors'])) {
|
Chris@0
|
238 $supported_majors = explode(',', $available['supported_majors']);
|
Chris@0
|
239 }
|
Chris@0
|
240 elseif (isset($available['default_major'])) {
|
Chris@0
|
241 // Older release history XML file without supported or recommended.
|
Chris@0
|
242 $supported_majors[] = $available['default_major'];
|
Chris@0
|
243 }
|
Chris@0
|
244
|
Chris@0
|
245 if (in_array($existing_major, $supported_majors)) {
|
Chris@0
|
246 // Still supported, stay at the current major version.
|
Chris@0
|
247 $target_major = $existing_major;
|
Chris@0
|
248 }
|
Chris@0
|
249 elseif (isset($available['recommended_major'])) {
|
Chris@0
|
250 // Since 'recommended_major' is defined, we know this is the new XML
|
Chris@0
|
251 // format. Therefore, we know the current release is unsupported since
|
Chris@0
|
252 // its major version was not in the 'supported_majors' list. We should
|
Chris@0
|
253 // find the best release from the recommended major version.
|
Chris@0
|
254 $target_major = $available['recommended_major'];
|
Chris@0
|
255 $project_data['status'] = UPDATE_NOT_SUPPORTED;
|
Chris@0
|
256 }
|
Chris@0
|
257 elseif (isset($available['default_major'])) {
|
Chris@0
|
258 // Older release history XML file without recommended, so recommend
|
Chris@0
|
259 // the currently defined "default_major" version.
|
Chris@0
|
260 $target_major = $available['default_major'];
|
Chris@0
|
261 }
|
Chris@0
|
262 else {
|
Chris@0
|
263 // Malformed XML file? Stick with the current version.
|
Chris@0
|
264 $target_major = $existing_major;
|
Chris@0
|
265 }
|
Chris@0
|
266
|
Chris@0
|
267 // Make sure we never tell the admin to downgrade. If we recommended an
|
Chris@0
|
268 // earlier version than the one they're running, they'd face an
|
Chris@0
|
269 // impossible data migration problem, since Drupal never supports a DB
|
Chris@0
|
270 // downgrade path. In the unfortunate case that what they're running is
|
Chris@0
|
271 // unsupported, and there's nothing newer for them to upgrade to, we
|
Chris@0
|
272 // can't print out a "Recommended version", but just have to tell them
|
Chris@0
|
273 // what they have is unsupported and let them figure it out.
|
Chris@0
|
274 $target_major = max($existing_major, $target_major);
|
Chris@0
|
275
|
Chris@0
|
276 $release_patch_changed = '';
|
Chris@0
|
277 $patch = '';
|
Chris@0
|
278
|
Chris@0
|
279 // If the project is marked as UPDATE_FETCH_PENDING, it means that the
|
Chris@0
|
280 // data we currently have (if any) is stale, and we've got a task queued
|
Chris@0
|
281 // up to (re)fetch the data. In that case, we mark it as such, merge in
|
Chris@0
|
282 // whatever data we have (e.g. project title and link), and move on.
|
Chris@0
|
283 if (!empty($available['fetch_status']) && $available['fetch_status'] == UPDATE_FETCH_PENDING) {
|
Chris@0
|
284 $project_data['status'] = UPDATE_FETCH_PENDING;
|
Chris@0
|
285 $project_data['reason'] = t('No available update data');
|
Chris@0
|
286 $project_data['fetch_status'] = $available['fetch_status'];
|
Chris@0
|
287 return;
|
Chris@0
|
288 }
|
Chris@0
|
289
|
Chris@0
|
290 // Defend ourselves from XML history files that contain no releases.
|
Chris@0
|
291 if (empty($available['releases'])) {
|
Chris@0
|
292 $project_data['status'] = UPDATE_UNKNOWN;
|
Chris@0
|
293 $project_data['reason'] = t('No available releases found');
|
Chris@0
|
294 return;
|
Chris@0
|
295 }
|
Chris@0
|
296 foreach ($available['releases'] as $version => $release) {
|
Chris@0
|
297 // First, if this is the existing release, check a few conditions.
|
Chris@0
|
298 if ($project_data['existing_version'] === $version) {
|
Chris@0
|
299 if (isset($release['terms']['Release type']) &&
|
Chris@0
|
300 in_array('Insecure', $release['terms']['Release type'])) {
|
Chris@0
|
301 $project_data['status'] = UPDATE_NOT_SECURE;
|
Chris@0
|
302 }
|
Chris@0
|
303 elseif ($release['status'] == 'unpublished') {
|
Chris@0
|
304 $project_data['status'] = UPDATE_REVOKED;
|
Chris@0
|
305 if (empty($project_data['extra'])) {
|
Chris@0
|
306 $project_data['extra'] = [];
|
Chris@0
|
307 }
|
Chris@0
|
308 $project_data['extra'][] = [
|
Chris@0
|
309 'class' => ['release-revoked'],
|
Chris@0
|
310 'label' => t('Release revoked'),
|
Chris@0
|
311 '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!'),
|
Chris@0
|
312 ];
|
Chris@0
|
313 }
|
Chris@0
|
314 elseif (isset($release['terms']['Release type']) &&
|
Chris@0
|
315 in_array('Unsupported', $release['terms']['Release type'])) {
|
Chris@0
|
316 $project_data['status'] = UPDATE_NOT_SUPPORTED;
|
Chris@0
|
317 if (empty($project_data['extra'])) {
|
Chris@0
|
318 $project_data['extra'] = [];
|
Chris@0
|
319 }
|
Chris@0
|
320 $project_data['extra'][] = [
|
Chris@0
|
321 'class' => ['release-not-supported'],
|
Chris@0
|
322 'label' => t('Release not supported'),
|
Chris@0
|
323 '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!'),
|
Chris@0
|
324 ];
|
Chris@0
|
325 }
|
Chris@0
|
326 }
|
Chris@0
|
327
|
Chris@0
|
328 // Otherwise, ignore unpublished, insecure, or unsupported releases.
|
Chris@0
|
329 if ($release['status'] == 'unpublished' ||
|
Chris@0
|
330 (isset($release['terms']['Release type']) &&
|
Chris@0
|
331 (in_array('Insecure', $release['terms']['Release type']) ||
|
Chris@0
|
332 in_array('Unsupported', $release['terms']['Release type'])))) {
|
Chris@0
|
333 continue;
|
Chris@0
|
334 }
|
Chris@0
|
335
|
Chris@0
|
336 // See if this is a higher major version than our target and yet still
|
Chris@0
|
337 // supported. If so, record it as an "Also available" release.
|
Chris@0
|
338 // Note: Some projects have a HEAD release from CVS days, which could
|
Chris@0
|
339 // be one of those being compared. They would not have version_major
|
Chris@0
|
340 // set, so we must call isset first.
|
Chris@0
|
341 if (isset($release['version_major']) && $release['version_major'] > $target_major) {
|
Chris@0
|
342 if (in_array($release['version_major'], $supported_majors)) {
|
Chris@0
|
343 if (!isset($project_data['also'])) {
|
Chris@0
|
344 $project_data['also'] = [];
|
Chris@0
|
345 }
|
Chris@0
|
346 if (!isset($project_data['also'][$release['version_major']])) {
|
Chris@0
|
347 $project_data['also'][$release['version_major']] = $version;
|
Chris@0
|
348 $project_data['releases'][$version] = $release;
|
Chris@0
|
349 }
|
Chris@0
|
350 }
|
Chris@0
|
351 // Otherwise, this release can't matter to us, since it's neither
|
Chris@0
|
352 // from the release series we're currently using nor the recommended
|
Chris@0
|
353 // release. We don't even care about security updates for this
|
Chris@0
|
354 // branch, since if a project maintainer puts out a security release
|
Chris@0
|
355 // at a higher major version and not at the lower major version,
|
Chris@0
|
356 // they must remove the lower version from the supported major
|
Chris@0
|
357 // versions at the same time, in which case we won't hit this code.
|
Chris@0
|
358 continue;
|
Chris@0
|
359 }
|
Chris@0
|
360
|
Chris@0
|
361 // Look for the 'latest version' if we haven't found it yet. Latest is
|
Chris@0
|
362 // defined as the most recent version for the target major version.
|
Chris@0
|
363 if (!isset($project_data['latest_version'])
|
Chris@0
|
364 && $release['version_major'] == $target_major) {
|
Chris@0
|
365 $project_data['latest_version'] = $version;
|
Chris@0
|
366 $project_data['releases'][$version] = $release;
|
Chris@0
|
367 }
|
Chris@0
|
368
|
Chris@0
|
369 // Look for the development snapshot release for this branch.
|
Chris@0
|
370 if (!isset($project_data['dev_version'])
|
Chris@0
|
371 && $release['version_major'] == $target_major
|
Chris@0
|
372 && isset($release['version_extra'])
|
Chris@0
|
373 && $release['version_extra'] == 'dev') {
|
Chris@0
|
374 $project_data['dev_version'] = $version;
|
Chris@0
|
375 $project_data['releases'][$version] = $release;
|
Chris@0
|
376 }
|
Chris@0
|
377
|
Chris@0
|
378 // Look for the 'recommended' version if we haven't found it yet (see
|
Chris@0
|
379 // phpdoc at the top of this function for the definition).
|
Chris@0
|
380 if (!isset($project_data['recommended'])
|
Chris@0
|
381 && $release['version_major'] == $target_major
|
Chris@0
|
382 && isset($release['version_patch'])) {
|
Chris@0
|
383 if ($patch != $release['version_patch']) {
|
Chris@0
|
384 $patch = $release['version_patch'];
|
Chris@0
|
385 $release_patch_changed = $release;
|
Chris@0
|
386 }
|
Chris@0
|
387 if (empty($release['version_extra']) && $patch == $release['version_patch']) {
|
Chris@0
|
388 $project_data['recommended'] = $release_patch_changed['version'];
|
Chris@0
|
389 $project_data['releases'][$release_patch_changed['version']] = $release_patch_changed;
|
Chris@0
|
390 }
|
Chris@0
|
391 }
|
Chris@0
|
392
|
Chris@0
|
393 // Stop searching once we hit the currently installed version.
|
Chris@0
|
394 if ($project_data['existing_version'] === $version) {
|
Chris@0
|
395 break;
|
Chris@0
|
396 }
|
Chris@0
|
397
|
Chris@0
|
398 // If we're running a dev snapshot and have a timestamp, stop
|
Chris@0
|
399 // searching for security updates once we hit an official release
|
Chris@0
|
400 // older than what we've got. Allow 100 seconds of leeway to handle
|
Chris@0
|
401 // differences between the datestamp in the .info.yml file and the
|
Chris@0
|
402 // timestamp of the tarball itself (which are usually off by 1 or 2
|
Chris@0
|
403 // seconds) so that we don't flag that as a new release.
|
Chris@0
|
404 if ($project_data['install_type'] == 'dev') {
|
Chris@0
|
405 if (empty($project_data['datestamp'])) {
|
Chris@0
|
406 // We don't have current timestamp info, so we can't know.
|
Chris@0
|
407 continue;
|
Chris@0
|
408 }
|
Chris@0
|
409 elseif (isset($release['date']) && ($project_data['datestamp'] + 100 > $release['date'])) {
|
Chris@0
|
410 // We're newer than this, so we can skip it.
|
Chris@0
|
411 continue;
|
Chris@0
|
412 }
|
Chris@0
|
413 }
|
Chris@0
|
414
|
Chris@0
|
415 // See if this release is a security update.
|
Chris@0
|
416 if (isset($release['terms']['Release type'])
|
Chris@0
|
417 && in_array('Security update', $release['terms']['Release type'])) {
|
Chris@0
|
418 $project_data['security updates'][] = $release;
|
Chris@0
|
419 }
|
Chris@0
|
420 }
|
Chris@0
|
421
|
Chris@0
|
422 // If we were unable to find a recommended version, then make the latest
|
Chris@0
|
423 // version the recommended version if possible.
|
Chris@0
|
424 if (!isset($project_data['recommended']) && isset($project_data['latest_version'])) {
|
Chris@0
|
425 $project_data['recommended'] = $project_data['latest_version'];
|
Chris@0
|
426 }
|
Chris@0
|
427
|
Chris@0
|
428 if (isset($project_data['status'])) {
|
Chris@0
|
429 // If we already know the status, we're done.
|
Chris@0
|
430 return;
|
Chris@0
|
431 }
|
Chris@0
|
432
|
Chris@0
|
433 // If we don't know what to recommend, there's nothing we can report.
|
Chris@0
|
434 // Bail out early.
|
Chris@0
|
435 if (!isset($project_data['recommended'])) {
|
Chris@0
|
436 $project_data['status'] = UPDATE_UNKNOWN;
|
Chris@0
|
437 $project_data['reason'] = t('No available releases found');
|
Chris@0
|
438 return;
|
Chris@0
|
439 }
|
Chris@0
|
440
|
Chris@0
|
441 // If we're running a dev snapshot, compare the date of the dev snapshot
|
Chris@0
|
442 // with the latest official version, and record the absolute latest in
|
Chris@0
|
443 // 'latest_dev' so we can correctly decide if there's a newer release
|
Chris@0
|
444 // than our current snapshot.
|
Chris@0
|
445 if ($project_data['install_type'] == 'dev') {
|
Chris@0
|
446 if (isset($project_data['dev_version']) && $available['releases'][$project_data['dev_version']]['date'] > $available['releases'][$project_data['latest_version']]['date']) {
|
Chris@0
|
447 $project_data['latest_dev'] = $project_data['dev_version'];
|
Chris@0
|
448 }
|
Chris@0
|
449 else {
|
Chris@0
|
450 $project_data['latest_dev'] = $project_data['latest_version'];
|
Chris@0
|
451 }
|
Chris@0
|
452 }
|
Chris@0
|
453
|
Chris@0
|
454 // Figure out the status, based on what we've seen and the install type.
|
Chris@0
|
455 switch ($project_data['install_type']) {
|
Chris@0
|
456 case 'official':
|
Chris@0
|
457 if ($project_data['existing_version'] === $project_data['recommended'] || $project_data['existing_version'] === $project_data['latest_version']) {
|
Chris@0
|
458 $project_data['status'] = UPDATE_CURRENT;
|
Chris@0
|
459 }
|
Chris@0
|
460 else {
|
Chris@0
|
461 $project_data['status'] = UPDATE_NOT_CURRENT;
|
Chris@0
|
462 }
|
Chris@0
|
463 break;
|
Chris@0
|
464
|
Chris@0
|
465 case 'dev':
|
Chris@0
|
466 $latest = $available['releases'][$project_data['latest_dev']];
|
Chris@0
|
467 if (empty($project_data['datestamp'])) {
|
Chris@0
|
468 $project_data['status'] = UPDATE_NOT_CHECKED;
|
Chris@0
|
469 $project_data['reason'] = t('Unknown release date');
|
Chris@0
|
470 }
|
Chris@0
|
471 elseif (($project_data['datestamp'] + 100 > $latest['date'])) {
|
Chris@0
|
472 $project_data['status'] = UPDATE_CURRENT;
|
Chris@0
|
473 }
|
Chris@0
|
474 else {
|
Chris@0
|
475 $project_data['status'] = UPDATE_NOT_CURRENT;
|
Chris@0
|
476 }
|
Chris@0
|
477 break;
|
Chris@0
|
478
|
Chris@0
|
479 default:
|
Chris@0
|
480 $project_data['status'] = UPDATE_UNKNOWN;
|
Chris@0
|
481 $project_data['reason'] = t('Invalid info');
|
Chris@0
|
482 }
|
Chris@0
|
483 }
|