drupal.inc

  1. 8.0.x includes/drupal.inc
  2. 6.x commands/pm/update_info/drupal.inc
  3. 6.x includes/drupal.inc
  4. 7.x includes/drupal.inc
  5. 4.x commands/pm/update_info/drupal.inc
  6. 5.x commands/pm/update_info/drupal.inc
  7. 5.x includes/drupal.inc
  8. master includes/drupal.inc

Implementation of 'drupal' update_info engine for Drupal >= 7.

Functions

Namesort descending Description
pm_update_filter Returns a human readable message based on update status of a project.
pm_update_last_check
_pm_get_update_info Get update information for all installed projects.
_pm_refresh Command callback. Refresh update status information.

File

commands/pm/update_info/drupal.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Implementation of 'drupal' update_info engine for Drupal >= 7.
  5. */
  6. /**
  7. * Returns a human readable message based on update status of a project.
  8. *
  9. * It also may alter the project object and set $project['updateable']
  10. * and $project['candidate_version'].
  11. *
  12. * @see pm_release_recommended()
  13. *
  14. * Project statuses in Drupal >=7 are:
  15. * - UPDATE_NOT_SECURE
  16. * - UPDATE_REVOKED
  17. * - UPDATE_NOT_SUPPORTED
  18. * - UPDATE_NOT_CURRENT
  19. * - UPDATE_CURRENT
  20. * - UPDATE_NOT_CHECKED
  21. * - UPDATE_UNKNOWN
  22. * - UPDATE_NOT_FETCHED
  23. * - UPDATE_FETCH_PENDING
  24. *
  25. */
  26. function pm_update_filter(&$project) {
  27. switch($project['status']) {
  28. case UPDATE_NOT_SECURE:
  29. $status = dt('SECURITY UPDATE available');
  30. pm_release_recommended($project);
  31. break;
  32. case UPDATE_REVOKED:
  33. $status = dt('Installed version REVOKED');
  34. pm_release_recommended($project);
  35. break;
  36. case UPDATE_NOT_SUPPORTED:
  37. $status = dt('Installed version not supported');
  38. pm_release_recommended($project);
  39. break;
  40. case UPDATE_NOT_CURRENT:
  41. $status = dt('Update available');
  42. pm_release_recommended($project);
  43. break;
  44. case UPDATE_CURRENT:
  45. $status = dt('Up to date');
  46. pm_release_recommended($project);
  47. $project['updateable'] = FALSE;
  48. break;
  49. case UPDATE_NOT_CHECKED:
  50. $status = dt('Unable to check status');
  51. break;
  52. case UPDATE_UNKNOWN:
  53. case UPDATE_NOT_FETCHED:
  54. case UPDATE_FETCH_PENDING:
  55. default:
  56. $status = dt('Unknown');
  57. break;
  58. }
  59. return $status;
  60. }
  61. /**
  62. * Returns time of last check of available updates.
  63. */
  64. // @todo This moved to state() in D8.
  65. function pm_update_last_check() {
  66. return variable_get('update_last_check', 0);
  67. }
  68. /**
  69. * Command callback. Refresh update status information.
  70. */
  71. function _pm_refresh() {
  72. drush_print(dt("Refreshing update status information ..."));
  73. update_refresh();
  74. drush_print(dt("Done."));
  75. }
  76. /**
  77. * Get update information for all installed projects.
  78. *
  79. * @see update_get_available().
  80. * @see update_manual_status().
  81. *
  82. * @return An array containing remote and local versions for all installed
  83. * projects
  84. */
  85. function _pm_get_update_info($projects) {
  86. // Force to invalidate some caches that are only cleared
  87. // when visiting update status report page. This allow to detect changes in
  88. // .info files.
  89. _update_cache_clear('update_project_data');
  90. _update_cache_clear('update_project_projects');
  91. // From update_get_available(): Iterate all projects and create a fetch task
  92. // for those we have no information or is obsolete.
  93. module_load_include('inc', 'update', 'update.compare');
  94. $available = _update_get_cached_available_releases();
  95. $update_projects = update_get_projects();
  96. foreach ($update_projects as $key => $project) {
  97. if (empty($available[$key])) {
  98. update_create_fetch_task($project);
  99. continue;
  100. }
  101. if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) {
  102. $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
  103. }
  104. if (empty($available[$key]['releases'])) {
  105. $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
  106. }
  107. if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UPDATE_FETCH_PENDING) {
  108. update_create_fetch_task($project);
  109. }
  110. }
  111. // Set a batch to process all pending tasks.
  112. $batch = array(
  113. 'operations' => array(
  114. array('update_fetch_data_batch', array()),
  115. ),
  116. 'finished' => 'update_fetch_data_finished',
  117. 'file' => drupal_get_path('module', 'update') . '/update.fetch.inc',
  118. );
  119. batch_set($batch);
  120. drush_backend_batch_process();
  121. // Clear any error set by a failed update fetch task. This avoid rollbacks.
  122. drush_clear_error();
  123. // Calculate update status data.
  124. $available = _update_get_cached_available_releases();
  125. $data = update_calculate_project_data($available);
  126. foreach ($data as $project_name => $project) {
  127. // Discard custom projects.
  128. if ($project['status'] == UPDATE_UNKNOWN) {
  129. unset($data[$project_name]);
  130. continue;
  131. }
  132. // Discard projects with unknown installation path.
  133. if ($project_name != 'drupal' && !isset($projects[$project_name]['path'])) {
  134. unset($data[$project_name]);
  135. continue;
  136. }
  137. // Allow to update disabled projects.
  138. if (in_array($project['project_type'], array('module-disabled', 'theme-disabled'))) {
  139. $data[$project_name]['project_type'] = substr($project['project_type'], 0, strpos($project['project_type'], '-'));
  140. }
  141. // Add some info from the project to $data.
  142. $data[$project_name] += array(
  143. 'path' => isset($projects[$project_name]['path']) ? $projects[$project_name]['path'] : '',
  144. 'label' => $projects[$project_name]['label'],
  145. );
  146. // Store all releases, not just the ones selected by update.module.
  147. if (isset($available[$project_name]['releases'])) {
  148. $data[$project_name]['releases'] = $available[$project_name]['releases'];
  149. }
  150. }
  151. return $data;
  152. }