update.compare.inc

Code required only when comparing available updates to existing data.

Archivo

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

Functions

Nombreorden descendente Descripción
update_calculate_project_data Given the installed projects and the available release data retrieved from remote servers, calculate the current status.
update_filter_project_info Filter the project .info data to only save attributes we need.
update_get_projects Fetch an array of installed and enabled projects.
update_get_project_name Given a $file object (as returned by system_get_files_database()), figure out what project it belongs to.
update_process_project_info Process the list of projects on the system to figure out the currently installed versions, and other information that is required before we can compare against the available releases to produce the status report.
update_project_cache Retrieve data from {cache_update} or empty the cache when necessary.
_update_process_info_list Populate an array of project data.