update.install

  1. drupal
    1. 6 modules/update/update.install
    2. 7 modules/update/update.install
    3. 8 core/modules/update/update.install

Install, update and uninstall functions for the update module.

Functions & methods

NameDescription
update_installImplements hook_install().
update_requirementsImplements hook_requirements().
update_schemaImplements hook_schema().
update_uninstallImplements hook_uninstall().
update_update_7000Create a queue to store tasks for requests to fetch available update data.
update_update_7001Recreates cache_update table.
_update_requirement_checkPrivate helper method to fill in the requirements array.

File

modules/update/update.install
View source
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the update module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. *
  9. * @return
  10. * An array describing the status of the site regarding available updates.
  11. * If there is no update data, only one record will be returned, indicating
  12. * that the status of core can't be determined. If data is available, there
  13. * will be two records: one for core, and another for all of contrib
  14. * (assuming there are any contributed modules or themes enabled on the
  15. * site). In addition to the fields expected by hook_requirements ('value',
  16. * 'severity', and optionally 'description'), this array will contain a
  17. * 'reason' attribute, which is an integer constant to indicate why the
  18. * given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or
  19. * UPDATE_UNKNOWN). This is used for generating the appropriate e-mail
  20. * notification messages during update_cron(), and might be useful for other
  21. * modules that invoke update_requirements() to find out if the site is up
  22. * to date or not.
  23. *
  24. * @see _update_message_text()
  25. * @see _update_cron_notify()
  26. */
  27. function update_requirements($phase) {
  28. $requirements = array();
  29. if ($phase == 'runtime') {
  30. if ($available = update_get_available(FALSE)) {
  31. module_load_include('inc', 'update', 'update.compare');
  32. $data = update_calculate_project_data($available);
  33. // First, populate the requirements for core:
  34. $requirements['update_core'] = _update_requirement_check($data['drupal'], 'core');
  35. // We don't want to check drupal a second time.
  36. unset($data['drupal']);
  37. if (!empty($data)) {
  38. // Now, sort our $data array based on each project's status. The
  39. // status constants are numbered in the right order of precedence, so
  40. // we just need to make sure the projects are sorted in ascending
  41. // order of status, and we can look at the first project we find.
  42. uasort($data, '_update_project_status_sort');
  43. $first_project = reset($data);
  44. $requirements['update_contrib'] = _update_requirement_check($first_project, 'contrib');
  45. }
  46. }
  47. else {
  48. $requirements['update_core']['title'] = t('Drupal core update status');
  49. $requirements['update_core']['value'] = t('No update data available');
  50. $requirements['update_core']['severity'] = REQUIREMENT_WARNING;
  51. $requirements['update_core']['reason'] = UPDATE_UNKNOWN;
  52. $requirements['update_core']['description'] = _update_no_data();
  53. }
  54. }
  55. return $requirements;
  56. }
  57. /**
  58. * Implements hook_schema().
  59. */
  60. function update_schema() {
  61. $schema['cache_update'] = drupal_get_schema_unprocessed('system', 'cache');
  62. $schema['cache_update']['description'] = 'Cache table for the Update module to store information about available releases, fetched from central server.';
  63. return $schema;
  64. }
  65. /**
  66. * Implements hook_install().
  67. */
  68. function update_install() {
  69. $queue = DrupalQueue::get('update_fetch_tasks', TRUE);
  70. $queue->createQueue();
  71. }
  72. /**
  73. * Implements hook_uninstall().
  74. */
  75. function update_uninstall() {
  76. // Clear any variables that might be in use
  77. $variables = array(
  78. 'update_check_frequency',
  79. 'update_fetch_url',
  80. 'update_last_check',
  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. * Private helper method to fill 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 is this ('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. */
Login or register to post comments