updatestatus.pm.inc

  1. 8.0.x commands/pm/updatestatus.pm.inc
  2. 6.x commands/pm/updatestatus.pm.inc
  3. 7.x commands/pm/updatestatus.pm.inc
  4. master commands/pm/updatestatus.pm.inc

pm-updatestatus command implementation.

Functions

Namesort descending Description
drush_pm_updatestatus Command callback. Displays update status info of installed projects.
pm_project_filter Filter projects based on verbosity level and $security_only flag.
pm_release_recommended Set a release to a recommended version (if available), and set as updateable.

File

commands/pm/updatestatus.pm.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * pm-updatestatus command implementation.
  5. */
  6. /**
  7. * Command callback. Displays update status info of installed projects.
  8. *
  9. * Pass specific projects as arguments, otherwise we show all that are
  10. * updateable.
  11. */
  12. function drush_pm_updatestatus() {
  13. // Get specific requests.
  14. $args = pm_parse_arguments(func_get_args(), FALSE);
  15. // Get installed extensions and projects.
  16. $extensions = drush_get_extensions();
  17. $projects = drush_get_projects($extensions);
  18. // Parse out project name and version.
  19. $requests = array();
  20. foreach ($args as $request) {
  21. $request = pm_parse_request($request, NULL, $projects);
  22. $requests[$request['name']] = $request;
  23. }
  24. // Get the engine instance.
  25. $update_status = drush_get_engine('update_status');
  26. // If the user doesn't provide a value for check-disabled option,
  27. // and the update backend is 'drupal', use NULL, so the engine
  28. // will respect update.module defaults.
  29. $check_disabled_default = ($update_status->engine == 'drupal') ? NULL : FALSE;
  30. $check_disabled = drush_get_option('check-disabled', $check_disabled_default);
  31. $update_info = $update_status->getStatus($projects, $check_disabled);
  32. foreach ($extensions as $name => $extension) {
  33. // Add an item to $update_info for each enabled extension which was obtained
  34. // from cvs or git and its project is unknown (because of cvs_deploy or
  35. // git_deploy is not enabled).
  36. if (!isset($extension->info['project'])) {
  37. if ((isset($extension->vcs)) && ($extension->status)) {
  38. $update_info[$name] = array(
  39. 'name' => $name,
  40. 'label' => $extension->label,
  41. 'existing_version' => 'Unknown',
  42. 'status' => DRUSH_UPDATESTATUS_PROJECT_NOT_PACKAGED,
  43. 'status_msg' => dt('Project was not packaged by drupal.org but obtained from !vcs. You need to enable !vcs_deploy module', array('!vcs' => $extension->vcs)),
  44. );
  45. // The user may have requested to update a project matching this
  46. // extension. If it was by coincidence or error we don't mind as we've
  47. // already added an item to $update_info. Just clean up $requests.
  48. if (isset($requests[$name])) {
  49. unset($requests[$name]);
  50. }
  51. }
  52. }
  53. // Additionally if the extension name is distinct to the project name and
  54. // the user asked to update the extension, fix the request.
  55. elseif ((isset($requests[$name])) && ($name != $extension->info['project'])) {
  56. $requests[$extension->info['project']] = $requests[$name];
  57. unset($requests[$name]);
  58. }
  59. }
  60. // If specific project updates were requested then remove releases for all
  61. // others.
  62. $requested = func_get_args();
  63. if (!empty($requested)) {
  64. foreach ($update_info as $name => $project) {
  65. if (!isset($requests[$name])) {
  66. unset($update_info[$name]);
  67. }
  68. }
  69. }
  70. // Add an item to $update_info for each request not present in $update_info.
  71. foreach ($requests as $name => $request) {
  72. if (!isset($update_info[$name])) {
  73. // Disabled projects.
  74. if ((isset($projects[$name])) && ($projects[$name]['status'] == 0)) {
  75. $update_info[$name] = array(
  76. 'name' => $name,
  77. 'label' => $projects[$name]['label'],
  78. 'existing_version' => $projects[$name]['version'],
  79. 'status' => DRUSH_UPDATESTATUS_REQUESTED_PROJECT_NOT_UPDATEABLE,
  80. );
  81. unset($requests[$name]);
  82. }
  83. // At this point we are unable to find matching installed project.
  84. // It does not exist at all or it is misspelled,...
  85. else {
  86. $update_info[$name] = array(
  87. 'name' => $name,
  88. 'label' => $name,
  89. 'existing_version' => 'Unknown',
  90. 'status'=> DRUSH_UPDATESTATUS_REQUESTED_PROJECT_NOT_FOUND,
  91. );
  92. }
  93. }
  94. }
  95. // If specific versions were requested, match the requested release.
  96. foreach ($requests as $name => $request) {
  97. if (!empty($request['version'])) {
  98. if (empty($update_info[$name]['releases'][$request['version']])) {
  99. $update_info[$name]['status'] = DRUSH_UPDATESTATUS_REQUESTED_VERSION_NOT_FOUND;
  100. }
  101. elseif ($request['version'] == $update_info[$name]['existing_version']) {
  102. $update_info[$name]['status'] = DRUSH_UPDATESTATUS_REQUESTED_VERSION_CURRENT;
  103. }
  104. // TODO: should we warn/reject if this is a downgrade?
  105. else {
  106. $update_info[$name]['status'] = DRUSH_UPDATESTATUS_REQUESTED_VERSION_NOT_CURRENT;
  107. $update_info[$name]['candidate_version'] = $request['version'];
  108. }
  109. }
  110. }
  111. // Process locks specified on the command line.
  112. $locked_list = drush_pm_update_lock($update_info, drush_get_option_list('lock'), drush_get_option_list('unlock'), drush_get_option('lock-message'));
  113. // Build project updatable messages, set candidate version and mark
  114. // 'updateable' in the project.
  115. foreach ($update_info as $key => $project) {
  116. switch($project['status']) {
  117. case DRUSH_UPDATESTATUS_NOT_SECURE:
  118. $status = dt('SECURITY UPDATE available');
  119. pm_release_recommended($project);
  120. break;
  121. case DRUSH_UPDATESTATUS_REVOKED:
  122. $status = dt('Installed version REVOKED');
  123. pm_release_recommended($project);
  124. break;
  125. case DRUSH_UPDATESTATUS_NOT_SUPPORTED:
  126. $status = dt('Installed version not supported');
  127. pm_release_recommended($project);
  128. break;
  129. case DRUSH_UPDATESTATUS_NOT_CURRENT:
  130. $status = dt('Update available');
  131. pm_release_recommended($project);
  132. break;
  133. case DRUSH_UPDATESTATUS_CURRENT:
  134. $status = dt('Up to date');
  135. pm_release_recommended($project);
  136. $project['updateable'] = FALSE;
  137. break;
  138. case DRUSH_UPDATESTATUS_NOT_CHECKED:
  139. case DRUSH_UPDATESTATUS_NOT_FETCHED:
  140. case DRUSH_UPDATESTATUS_FETCH_PENDING:
  141. $status = dt('Unable to check status');
  142. break;
  143. case DRUSH_UPDATESTATUS_PROJECT_NOT_PACKAGED:
  144. $status = $project['status_msg'];
  145. break;
  146. case DRUSH_UPDATESTATUS_REQUESTED_PROJECT_NOT_UPDATEABLE:
  147. $status = dt('Project has no enabled extensions and can\'t be updated');
  148. break;
  149. case DRUSH_UPDATESTATUS_REQUESTED_PROJECT_NOT_FOUND:
  150. $status = dt('Specified project not found');
  151. break;
  152. case DRUSH_UPDATESTATUS_REQUESTED_VERSION_NOT_FOUND:
  153. $status = dt('Specified version not found');
  154. break;
  155. case DRUSH_UPDATESTATUS_REQUESTED_VERSION_CURRENT:
  156. $status = dt('Specified version already installed');
  157. break;
  158. case DRUSH_UPDATESTATUS_REQUESTED_VERSION_NOT_CURRENT:
  159. $status = dt('Specified version available');
  160. $project['updateable'] = TRUE;
  161. break;
  162. default:
  163. $status = dt('Unknown');
  164. break;
  165. }
  166. if (isset($project['locked'])) {
  167. $status = $project['locked'] . " ($status)";
  168. }
  169. // Persist candidate_version in $update_info (plural).
  170. if (empty($project['candidate_version'])) {
  171. $update_info[$key]['candidate_version'] = $project['existing_version']; // Default to no change
  172. }
  173. else {
  174. $update_info[$key]['candidate_version'] = $project['candidate_version'];
  175. }
  176. $update_info[$key]['status_msg'] = $status;
  177. if (isset($project['updateable'])) {
  178. $update_info[$key]['updateable'] = $project['updateable'];
  179. }
  180. }
  181. // Filter projects to show.
  182. return pm_project_filter($update_info, drush_get_option('security-only'));
  183. }
  184. /**
  185. * Filter projects based on verbosity level and $security_only flag.
  186. *
  187. * @param array $update_info
  188. * Update info for projects.
  189. * @param bool $security_only
  190. * Whether to select only projects with security updates.
  191. *
  192. * @return
  193. * Array of projects matching filter criteria.
  194. */
  195. function pm_project_filter($update_info, $security_only) {
  196. $eligible = array();
  197. foreach ($update_info as $key => $project) {
  198. if ($security_only) {
  199. if ($project['status'] == DRUSH_UPDATESTATUS_NOT_SECURE) {
  200. $eligible[$key] = $project;
  201. }
  202. }
  203. elseif (drush_get_context('DRUSH_VERBOSE')) {
  204. $eligible[$key] = $project;
  205. }
  206. elseif ($project['status'] != DRUSH_UPDATESTATUS_CURRENT) {
  207. $eligible[$key] = $project;
  208. }
  209. }
  210. return $eligible;
  211. }
  212. /**
  213. * Set a release to a recommended version (if available), and set as updateable.
  214. */
  215. function pm_release_recommended(&$project) {
  216. if (isset($project['recommended'])) {
  217. $project['candidate_version'] = $project['recommended'];
  218. $project['updateable'] = TRUE;
  219. }
  220. // If installed version is dev and the candidate version is older, choose
  221. // latest dev as candidate.
  222. if (($project['install_type'] == 'dev') && isset($project['candidate_version'])) {
  223. if ($project['releases'][$project['candidate_version']]['date'] < $project['datestamp']) {
  224. $project['candidate_version'] = $project['latest_dev'];
  225. if ($project['releases'][$project['candidate_version']]['date'] <= $project['datestamp']) {
  226. $project['candidate_version'] = $project['existing_version'];
  227. $project['updateable'] = FALSE;
  228. }
  229. }
  230. }
  231. }