drupal.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. function pm_update_filter(&$project) {
  3. $update = FALSE;
  4. switch($project['status']) {
  5. case UPDATE_CURRENT:
  6. $status = dt('Up to date');
  7. $project['candidate_version'] = $project['recommended'];
  8. break;
  9. case UPDATE_NOT_CURRENT:
  10. $status = dt('Update available');
  11. pm_release_recommended($project);
  12. break;
  13. case UPDATE_NOT_SECURE:
  14. $status = dt('SECURITY UPDATE available');
  15. pm_release_recommended($project);
  16. break;
  17. case UPDATE_REVOKED:
  18. $status = dt('Installed version REVOKED');
  19. pm_release_recommended($project);
  20. break;
  21. case UPDATE_NOT_SUPPORTED:
  22. $status = dt('Installed version not supported');
  23. pm_release_recommended($project);
  24. break;
  25. case UPDATE_NOT_CHECKED:
  26. $status = dt('Unable to check status');
  27. break;
  28. default:
  29. $status = dt('Unknown');
  30. break;
  31. }
  32. return $status;
  33. }
  34. function pm_update_last_check() {
  35. return variable_get('update_last_check', 0);
  36. }
  37. /**
  38. * Command callback. Refresh update status information.
  39. */
  40. function _pm_refresh() {
  41. drush_print(dt("Refreshing update status information ..."));
  42. update_refresh();
  43. drush_print(dt("Done."));
  44. }
  45. /**
  46. * Get update information for all installed projects.
  47. *
  48. * @see update_get_available().
  49. * @see update_manual_status().
  50. *
  51. * @return An array containing remote and local versions for all installed
  52. * projects
  53. */
  54. function _pm_get_update_info($projects) {
  55. // Force to invalidate some caches that are only cleared
  56. // when visiting update status report page. This allow to detect changes in
  57. // .info files.
  58. _update_cache_clear('update_project_data');
  59. _update_cache_clear('update_project_projects');
  60. // From update_get_available(): Iterate all projects and create a fetch task
  61. // for those we have no information or is obsolete.
  62. module_load_include('inc', 'update', 'update.compare');
  63. $available = _update_get_cached_available_releases();
  64. $update_projects = update_get_projects();
  65. foreach ($update_projects as $key => $project) {
  66. if (empty($available[$key])) {
  67. update_create_fetch_task($project);
  68. continue;
  69. }
  70. if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) {
  71. $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
  72. }
  73. if (empty($available[$key]['releases'])) {
  74. $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING;
  75. }
  76. if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UPDATE_FETCH_PENDING) {
  77. update_create_fetch_task($project);
  78. }
  79. }
  80. // Set a batch to process all pending tasks.
  81. $batch = array(
  82. 'operations' => array(
  83. array('update_fetch_data_batch', array()),
  84. ),
  85. 'finished' => 'update_fetch_data_finished',
  86. 'file' => drupal_get_path('module', 'update') . '/update.fetch.inc',
  87. );
  88. batch_set($batch);
  89. drush_backend_batch_process();
  90. // Calculate update status data.
  91. $available = _update_get_cached_available_releases();
  92. $data = update_calculate_project_data($available);
  93. foreach ($data as $project_name => $project) {
  94. // Discard custom projects.
  95. if ($project['status'] == UPDATE_UNKNOWN) {
  96. unset($data[$project_name]);
  97. continue;
  98. }
  99. // Allow to update disabled projects.
  100. if (in_array($project['project_type'], array('module-disabled', 'theme-disabled'))) {
  101. $data[$project_name]['project_type'] = substr($project['project_type'], 0, strpos($project['project_type'], '-'));
  102. }
  103. // Set 'includes' key to all extensions. By default it only contain enabled
  104. // extensions and _pm_get_project_path() needs all of them.
  105. $data[$project_name]['includes'] = drupal_map_assoc($projects[$project_name]['extensions']);
  106. // Store all releases, not just the ones selected by update.module.
  107. $data[$project_name]['releases'] = $available[$project_name]['releases'];
  108. }
  109. $data = _pm_get_project_path($data, 'includes');
  110. return $data;
  111. }
  112. function pm_get_project_info($projects) {
  113. $data = array();
  114. include_once drupal_get_path('module', 'update') .'/update.fetch.inc';
  115. foreach ($projects as $project_name => $project) {
  116. $url = UPDATE_DEFAULT_URL. "/$project_name/". drush_drupal_major_version() . '.x';
  117. $xml = drupal_http_request($url);
  118. if (isset($xml->error)) {
  119. drush_set_error(dt(
  120. 'HTTP Request to @request has failed. @error',
  121. array('@request' => $xml->request, '@error' => $xml->error)
  122. ));
  123. }
  124. elseif (!$info = update_parse_xml($xml->data)) {
  125. drush_set_error(dt(
  126. 'No release history found for @project_name',
  127. array('@project_name' => $project_name)
  128. ));
  129. }
  130. else {
  131. $data[$project_name] = $info;
  132. }
  133. }
  134. return $data;
  135. }