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_get_release Get the a best release match for a requested update.
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. $requests = 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 = pm_parse_project_version($requests, $projects);
  20. $update_info = _pm_get_update_info($projects);
  21. foreach ($extensions as $name => $extension) {
  22. // Add an item to $update_info for each enabled extension which was obtained
  23. // from cvs or git and its project is unknown (because of cvs_deploy or
  24. // git_deploy is not enabled).
  25. if (!isset($extension->info['project'])) {
  26. if ((isset($extension->vcs)) && ($extension->status)) {
  27. $update_info[$name] = array(
  28. 'name' => $name,
  29. 'label' => $extension->label,
  30. 'existing_version' => 'Unknown',
  31. 'status' => DRUSH_PM_REQUESTED_PROJECT_NOT_PACKAGED,
  32. '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)),
  33. );
  34. // The user may have requested to update a project matching this
  35. // extension. If it was by coincidence or error we don't mind as we've
  36. // already added an item to $update_info. Just clean up $requests.
  37. if (isset($requests[$name])) {
  38. unset($requests[$name]);
  39. }
  40. }
  41. }
  42. // Additionally if the extension name is distinct to the project name and
  43. // the user asked to update the extension, fix the request.
  44. elseif ((isset($requests[$name])) && ($extension->name != $extension->info['project'])) {
  45. $requests[$extension->info['project']] = $requests[$name];
  46. unset($requests[$name]);
  47. }
  48. }
  49. // If specific project updates were requested then remove releases for all
  50. // others.
  51. $requested = func_get_args();
  52. if (!empty($requested)) {
  53. foreach ($update_info as $name => $project) {
  54. if (!isset($requests[$name])) {
  55. unset($update_info[$name]);
  56. }
  57. }
  58. }
  59. // Add an item to $update_info for each request not present in $update_info.
  60. foreach ($requests as $name => $request) {
  61. if (!isset($update_info[$name])) {
  62. // Disabled projects.
  63. if ((isset($projects[$name])) && ($projects[$name]['status'] == 0)) {
  64. $update_info[$name] = array(
  65. 'name' => $name,
  66. 'label' => $projects[$name]['label'],
  67. 'existing_version' => $projects[$name]['version'],
  68. 'status' => DRUSH_PM_REQUESTED_PROJECT_NOT_UPDATEABLE,
  69. );
  70. unset($requests[$name]);
  71. }
  72. // At this point we are unable to find matching installed project.
  73. // It does not exist at all or it is misspelled,...
  74. else {
  75. $update_info[$name] = array(
  76. 'name' => $name,
  77. 'label' => $name,
  78. 'existing_version' => 'Unknown',
  79. 'status'=> DRUSH_PM_REQUESTED_PROJECT_NOT_FOUND,
  80. );
  81. }
  82. }
  83. }
  84. // If specific versions were requested, match the requested release.
  85. foreach ($requests as $name => $request) {
  86. if (!empty($request['version'])) {
  87. $release = pm_get_release($request, $update_info[$name]);
  88. if (!$release) {
  89. $update_info[$name]['status'] = DRUSH_PM_REQUESTED_VERSION_NOT_FOUND;
  90. }
  91. else if ($release['version'] == $update_info[$name]['existing_version']) {
  92. $update_info[$name]['status'] = DRUSH_PM_REQUESTED_CURRENT;
  93. }
  94. else {
  95. $update_info[$name]['status'] = DRUSH_PM_REQUESTED_UPDATE;
  96. }
  97. // Set the candidate version to the requested release.
  98. $update_info[$name]['candidate_version'] = $release['version'];
  99. }
  100. }
  101. // Process locks specified on the command line.
  102. $locked_list = drush_pm_update_lock($update_info, drush_get_option_list('lock'), drush_get_option_list('unlock'), drush_get_option('lock-message'));
  103. // Build project updatable messages, set candidate version and mark
  104. // 'updateable' in the project.
  105. foreach ($update_info as $key => $project) {
  106. switch($project['status']) {
  107. case DRUSH_PM_REQUESTED_UPDATE:
  108. $status = dt('Specified version available');
  109. $project['updateable'] = TRUE;
  110. break;
  111. case DRUSH_PM_REQUESTED_CURRENT:
  112. $status = dt('Specified version already installed');
  113. break;
  114. case DRUSH_PM_REQUESTED_PROJECT_NOT_PACKAGED:
  115. $status = $project['status_msg'];
  116. break;
  117. case DRUSH_PM_REQUESTED_VERSION_NOT_FOUND:
  118. $status = dt('Specified version not found');
  119. break;
  120. case DRUSH_PM_REQUESTED_PROJECT_NOT_FOUND:
  121. $status = dt('Specified project not found');
  122. break;
  123. case DRUSH_PM_REQUESTED_PROJECT_NOT_UPDATEABLE:
  124. $status = dt('Project has no enabled extensions and can\'t be updated');
  125. break;
  126. default:
  127. // This can set $project['updateable'] and $project['candidate_version']
  128. $status = pm_update_filter($project);
  129. break;
  130. }
  131. if (isset($project['locked'])) {
  132. $status = $project['locked'] . " ($status)";
  133. }
  134. // Persist candidate_version in $update_info (plural).
  135. if (empty($project['candidate_version'])) {
  136. $update_info[$key]['candidate_version'] = $project['existing_version']; // Default to no change
  137. }
  138. else {
  139. $update_info[$key]['candidate_version'] = $project['candidate_version'];
  140. }
  141. $update_info[$key]['status_msg'] = $status;
  142. if (isset($project['updateable'])) {
  143. $update_info[$key]['updateable'] = $project['updateable'];
  144. }
  145. }
  146. // Filter projects to show.
  147. return pm_project_filter($update_info, drush_get_option('security-only'));
  148. }
  149. /**
  150. * Filter projects based on verbosity level and $security_only flag.
  151. *
  152. * @param array $update_info
  153. * Update info for projects.
  154. * @param bool $security_only
  155. * Whether to select only projects with security updates.
  156. *
  157. * @return
  158. * Array of projects matching filter criteria.
  159. */
  160. function pm_project_filter($update_info, $security_only) {
  161. $eligible = array();
  162. foreach ($update_info as $key => $project) {
  163. if ($security_only) {
  164. if ($project['status'] == UPDATE_NOT_SECURE) {
  165. $eligible[$key] = $project;
  166. }
  167. }
  168. elseif (drush_get_context('DRUSH_VERBOSE')) {
  169. $eligible[$key] = $project;
  170. }
  171. elseif ($project['status'] != UPDATE_CURRENT) {
  172. $eligible[$key] = $project;
  173. }
  174. }
  175. return $eligible;
  176. }
  177. /**
  178. * Set a release to a recommended version (if available), and set as updateable.
  179. */
  180. function pm_release_recommended(&$project) {
  181. if (isset($project['recommended'])) {
  182. $project['candidate_version'] = $project['recommended'];
  183. $project['updateable'] = TRUE;
  184. }
  185. // If installed version is dev and the candidate version is older, choose
  186. // latest dev as candidate.
  187. if (($project['install_type'] == 'dev') && isset($project['candidate_version'])) {
  188. if ($project['releases'][$project['candidate_version']]['date'] < $project['info']['datestamp']) {
  189. $project['candidate_version'] = $project['latest_dev'];
  190. if ($project['releases'][$project['candidate_version']]['date'] <= $project['info']['datestamp']) {
  191. $project['candidate_version'] = $project['existing_version'];
  192. $project['updateable'] = FALSE;
  193. }
  194. }
  195. }
  196. }
  197. /**
  198. * Get the a best release match for a requested update.
  199. *
  200. * @param $request A information array for the requested project
  201. * @param $project A project information array for this project, as returned by an update service from pm_get_extensions()
  202. */
  203. function pm_get_release($request, $project) {
  204. $minor = '';
  205. $version_patch_changed = '';
  206. if ($request['version']) {
  207. // The user specified a specific version - try to find that exact version
  208. foreach($project['releases'] as $version => $release) {
  209. // Ignore unpublished releases.
  210. if ($release['status'] != 'published') {
  211. continue;
  212. }
  213. // Straight match
  214. if (!isset($recommended_version) && $release['version'] == $request['version']) {
  215. $recommended_version = $version;
  216. }
  217. }
  218. }
  219. else {
  220. // No version specified - try to find the best version we can
  221. foreach($project['releases'] as $version => $release) {
  222. // Ignore unpublished releases.
  223. if ($release['status'] != 'published') {
  224. continue;
  225. }
  226. // If we haven't found a recommended version yet, put the dev
  227. // version as recommended and hope it gets overwritten later.
  228. // Look for the 'latest version' if we haven't found it yet.
  229. // Latest version is defined as the most recent version for the
  230. // default major version.
  231. if (!isset($latest_version) && $release['version_major'] == $project['default_major']) {
  232. $latest_version = $version;
  233. }
  234. if (!isset($recommended_version) && $release['version_major'] == $project['default_major']) {
  235. if ($minor != $release['version_patch']) {
  236. $minor = $release['version_patch'];
  237. $version_patch_changed = $version;
  238. }
  239. if (empty($release['version_extra']) && $minor == $release['version_patch']) {
  240. $recommended_version = $version_patch_changed;
  241. }
  242. continue;
  243. }
  244. }
  245. }
  246. if (isset($recommended_version)) {
  247. return $project['releases'][$recommended_version];
  248. }
  249. else if (isset($latest_version)) {
  250. return $project['releases'][$latest_version];
  251. }
  252. else {
  253. return false;
  254. }
  255. }