StatusInfoDrupal7.php

  1. 8.0.x lib/Drush/UpdateService/StatusInfoDrupal7.php
  2. 7.x lib/Drush/UpdateService/StatusInfoDrupal7.php
  3. master lib/Drush/UpdateService/StatusInfoDrupal7.php

Implementation of 'drupal' update_status engine for Drupal 7.

Namespace

Drush\UpdateService

Classes

Namesort descending Description
StatusInfoDrupal7

File

lib/Drush/UpdateService/StatusInfoDrupal7.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Implementation of 'drupal' update_status engine for Drupal 7.
  5. */
  6. namespace Drush\UpdateService;
  7. class StatusInfoDrupal7 extends StatusInfoDrupal8 {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. function lastCheck() {
  12. return variable_get('update_last_check', 0);
  13. }
  14. /**
  15. * {@inheritdoc}
  16. */
  17. function beforeGetStatus(&$projects, $check_disabled) {
  18. // If check-disabled option was provided, alter Drupal settings temporarily.
  19. // There's no other way to hook into this.
  20. if (!is_null($check_disabled)) {
  21. global $conf;
  22. $this->update_check_disabled = $conf['update_check_disabled'];
  23. $conf['update_check_disabled'] = $check_disabled;
  24. }
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. function afterGetStatus(&$update_info, $projects, $check_disabled) {
  30. // Restore Drupal settings.
  31. if (!is_null($check_disabled)) {
  32. global $conf;
  33. $conf['update_check_disabled'] = $this->update_check_disabled;
  34. unset($this->update_check_disabled);
  35. }
  36. // update.module sets a different project type
  37. // for disabled projects. Here we normalize it.
  38. if ($check_disabled) {
  39. foreach ($update_info as $key => $project) {
  40. if (in_array($project['project_type'], array('module-disabled', 'theme-disabled'))) {
  41. $update_info[$key]['project_type'] = substr($project['project_type'], 0, strpos($project['project_type'], '-'));
  42. }
  43. }
  44. }
  45. }
  46. /**
  47. * Obtains release info for all installed projects via update.module.
  48. *
  49. * @see update_get_available().
  50. * @see update_manual_status().
  51. */
  52. protected function getAvailableReleases() {
  53. // Force to invalidate some caches that are only cleared
  54. // when visiting update status report page. This allow to detect changes in
  55. // .info files.
  56. _update_cache_clear('update_project_data');
  57. _update_cache_clear('update_project_projects');
  58. // From update_get_available(): Iterate all projects and create a fetch task
  59. // for those we have no information or is obsolete.
  60. $available = _update_get_cached_available_releases();
  61. module_load_include('inc', 'update', 'update.compare');
  62. $update_projects = update_get_projects();
  63. foreach ($update_projects as $key => $project) {
  64. if (empty($available[$key])) {
  65. update_create_fetch_task($project);
  66. continue;
  67. }
  68. if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) {
  69. $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
  70. }
  71. if (empty($available[$key]['releases'])) {
  72. $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
  73. }
  74. if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UPDATE_FETCH_PENDING) {
  75. update_create_fetch_task($project);
  76. }
  77. }
  78. // Set a batch to process all pending tasks.
  79. $batch = array(
  80. 'operations' => array(
  81. array('update_fetch_data_batch', array()),
  82. ),
  83. 'finished' => 'update_fetch_data_finished',
  84. 'file' => drupal_get_path('module', 'update') . '/update.fetch.inc',
  85. );
  86. batch_set($batch);
  87. drush_backend_batch_process();
  88. // Clear any error set by a failed update fetch task. This avoid rollbacks.
  89. drush_clear_error();
  90. // Calculate update status data.
  91. $available = _update_get_cached_available_releases();
  92. return $available;
  93. }
  94. }