update.install 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * @file
  4. * Install, update, and uninstall functions for the Update Manager module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. *
  9. * @return
  10. * An array describing the status of the site regarding available updates. If
  11. * there is no update data, only one record will be returned, indicating that
  12. * the status of core can't be determined. If data is available, there will be
  13. * two records: one for core, and another for all of contrib (assuming there
  14. * are any contributed modules or themes enabled on the site). In addition to
  15. * the fields expected by hook_requirements ('value', 'severity', and
  16. * optionally 'description'), this array will contain a 'reason' attribute,
  17. * which is an integer constant to indicate why the given status is being
  18. * returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or UPDATE_UNKNOWN). This
  19. * is used for generating the appropriate e-mail notification messages during
  20. * update_cron(), and might be useful for other modules that invoke
  21. * update_requirements() to find out if the site is up to date or not.
  22. *
  23. * @see _update_message_text()
  24. * @see _update_cron_notify()
  25. */
  26. function update_requirements($phase) {
  27. $requirements = array();
  28. if ($phase == 'runtime') {
  29. if ($available = update_get_available(FALSE)) {
  30. module_load_include('inc', 'update', 'update.compare');
  31. $data = update_calculate_project_data($available);
  32. // First, populate the requirements for core:
  33. $requirements['update_core'] = _update_requirement_check($data['drupal'], 'core');
  34. // We don't want to check drupal a second time.
  35. unset($data['drupal']);
  36. if (!empty($data)) {
  37. // Now, sort our $data array based on each project's status. The
  38. // status constants are numbered in the right order of precedence, so
  39. // we just need to make sure the projects are sorted in ascending
  40. // order of status, and we can look at the first project we find.
  41. uasort($data, '_update_project_status_sort');
  42. $first_project = reset($data);
  43. $requirements['update_contrib'] = _update_requirement_check($first_project, 'contrib');
  44. }
  45. }
  46. else {
  47. $requirements['update_core']['title'] = t('Drupal core update status');
  48. $requirements['update_core']['value'] = t('No update data available');
  49. $requirements['update_core']['severity'] = REQUIREMENT_WARNING;
  50. $requirements['update_core']['reason'] = UPDATE_UNKNOWN;
  51. $requirements['update_core']['description'] = _update_no_data();
  52. }
  53. }
  54. return $requirements;
  55. }
  56. /**
  57. * Implements hook_schema().
  58. */
  59. function update_schema() {
  60. $schema['cache_update'] = drupal_get_schema_unprocessed('system', 'cache');
  61. $schema['cache_update']['description'] = 'Cache table for the Update module to store information about available releases, fetched from central server.';
  62. return $schema;
  63. }
  64. /**
  65. * Implements hook_install().
  66. */
  67. function update_install() {
  68. $queue = DrupalQueue::get('update_fetch_tasks', TRUE);
  69. $queue->createQueue();
  70. }
  71. /**
  72. * Implements hook_uninstall().
  73. */
  74. function update_uninstall() {
  75. // Clear any variables that might be in use
  76. $variables = array(
  77. 'update_check_frequency',
  78. 'update_fetch_url',
  79. 'update_last_check',
  80. 'update_last_email_notification',
  81. 'update_notification_threshold',
  82. 'update_notify_emails',
  83. 'update_max_fetch_attempts',
  84. 'update_max_fetch_time',
  85. );
  86. foreach ($variables as $variable) {
  87. variable_del($variable);
  88. }
  89. $queue = DrupalQueue::get('update_fetch_tasks');
  90. $queue->deleteQueue();
  91. }
  92. /**
  93. * Fills in the requirements array.
  94. *
  95. * This is shared for both core and contrib to generate the right elements in
  96. * the array for hook_requirements().
  97. *
  98. * @param $project
  99. * Array of information about the project we're testing as returned by
  100. * update_calculate_project_data().
  101. * @param $type
  102. * What kind of project this is ('core' or 'contrib').
  103. *
  104. * @return
  105. * An array to be included in the nested $requirements array.
  106. *
  107. * @see hook_requirements()
  108. * @see update_requirements()
  109. * @see update_calculate_project_data()
  110. */
  111. function _update_requirement_check($project, $type) {
  112. $requirement = array();
  113. if ($type == 'core') {
  114. $requirement['title'] = t('Drupal core update status');
  115. }
  116. else {
  117. $requirement['title'] = t('Module and theme update status');
  118. }
  119. $status = $project['status'];
  120. if ($status != UPDATE_CURRENT) {
  121. $requirement['reason'] = $status;
  122. $requirement['description'] = _update_message_text($type, $status, TRUE);
  123. $requirement['severity'] = REQUIREMENT_ERROR;
  124. }
  125. switch ($status) {
  126. case UPDATE_NOT_SECURE:
  127. $requirement_label = t('Not secure!');
  128. break;
  129. case UPDATE_REVOKED:
  130. $requirement_label = t('Revoked!');
  131. break;
  132. case UPDATE_NOT_SUPPORTED:
  133. $requirement_label = t('Unsupported release');
  134. break;
  135. case UPDATE_NOT_CURRENT:
  136. $requirement_label = t('Out of date');
  137. $requirement['severity'] = REQUIREMENT_WARNING;
  138. break;
  139. case UPDATE_UNKNOWN:
  140. case UPDATE_NOT_CHECKED:
  141. case UPDATE_NOT_FETCHED:
  142. $requirement_label = isset($project['reason']) ? $project['reason'] : t('Can not determine status');
  143. $requirement['severity'] = REQUIREMENT_WARNING;
  144. break;
  145. default:
  146. $requirement_label = t('Up to date');
  147. }
  148. if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) {
  149. $requirement_label .= ' ' . t('(version @version available)', array('@version' => $project['recommended']));
  150. }
  151. $requirement['value'] = l($requirement_label, update_manager_access() ? 'admin/reports/updates/update' : 'admin/reports/updates');
  152. return $requirement;
  153. }
  154. /**
  155. * @addtogroup updates-6.x-to-7.x
  156. * @{
  157. */
  158. /**
  159. * Create a queue to store tasks for requests to fetch available update data.
  160. */
  161. function update_update_7000() {
  162. module_load_include('inc', 'system', 'system.queue');
  163. $queue = DrupalQueue::get('update_fetch_tasks');
  164. $queue->createQueue();
  165. }
  166. /**
  167. * Recreates cache_update table.
  168. *
  169. * Converts fields that hold serialized variables from text to blob.
  170. * Removes 'headers' column.
  171. */
  172. function update_update_7001() {
  173. $schema = system_schema_cache_7054();
  174. db_drop_table('cache_update');
  175. db_create_table('cache_update', $schema);
  176. }
  177. /**
  178. * @} End of "addtogroup updates-6.x-to-7.x".
  179. */