update.api.php

You are here

  1. 7 modules/update/update.api.php
  2. 8 core/modules/update/update.api.php

Hooks provided by the Update Manager module.

Functions

Namesort descending Description
hook_update_projects_alter Alter the list of projects before fetching data and comparing versions.
hook_update_status_alter Alter the information about available updates for projects.
hook_verify_update_archive Verify an archive after it has been downloaded and extracted.

File

modules/update/update.api.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Update Manager module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Alter the list of projects before fetching data and comparing versions.
  12. *
  13. * Most modules will never need to implement this hook. It is for advanced
  14. * interaction with the Update Manager module. The primary use-case for this
  15. * hook is to add projects to the list; for example, to provide update status
  16. * data on disabled modules and themes. A contributed module might want to hide
  17. * projects from the list; for example, if there is a site-specific module that
  18. * doesn't have any official releases, that module could remove itself from this
  19. * list to avoid "No available releases found" warnings on the available updates
  20. * report. In rare cases, a module might want to alter the data associated with
  21. * a project already in the list.
  22. *
  23. * @param $projects
  24. * Reference to an array of the projects installed on the system. This
  25. * includes all the metadata documented in the comments below for each project
  26. * (either module or theme) that is currently enabled. The array is initially
  27. * populated inside update_get_projects() with the help of
  28. * _update_process_info_list(), so look there for examples of how to populate
  29. * the array with real values.
  30. *
  31. * @see update_get_projects()
  32. * @see _update_process_info_list()
  33. */
  34. function hook_update_projects_alter(&$projects) {
  35. // Hide a site-specific module from the list.
  36. unset($projects['site_specific_module']);
  37. // Add a disabled module to the list.
  38. // The key for the array should be the machine-readable project "short name".
  39. $projects['disabled_project_name'] = array(
  40. // Machine-readable project short name (same as the array key above).
  41. 'name' => 'disabled_project_name',
  42. // Array of values from the main .info file for this project.
  43. 'info' => array(
  44. 'name' => 'Some disabled module',
  45. 'description' => 'A module not enabled on the site that you want to see in the available updates report.',
  46. 'version' => '7.x-1.0',
  47. 'core' => '7.x',
  48. // The maximum file change time (the "ctime" returned by the filectime()
  49. // PHP method) for all of the .info files included in this project.
  50. '_info_file_ctime' => 1243888165,
  51. ),
  52. // The date stamp when the project was released, if known. If the disabled
  53. // project was an officially packaged release from drupal.org, this will
  54. // be included in the .info file as the 'datestamp' field. This only
  55. // really matters for development snapshot releases that are regenerated,
  56. // so it can be left undefined or set to 0 in most cases.
  57. 'datestamp' => 1243888185,
  58. // Any modules (or themes) included in this project. Keyed by machine-
  59. // readable "short name", value is the human-readable project name printed
  60. // in the UI.
  61. 'includes' => array(
  62. 'disabled_project' => 'Disabled module',
  63. 'disabled_project_helper' => 'Disabled module helper module',
  64. 'disabled_project_foo' => 'Disabled module foo add-on module',
  65. ),
  66. // Does this project contain a 'module', 'theme', 'disabled-module', or
  67. // 'disabled-theme'?
  68. 'project_type' => 'disabled-module',
  69. );
  70. }
  71. /**
  72. * Alter the information about available updates for projects.
  73. *
  74. * @param $projects
  75. * Reference to an array of information about available updates to each
  76. * project installed on the system.
  77. *
  78. * @see update_calculate_project_data()
  79. */
  80. function hook_update_status_alter(&$projects) {
  81. $settings = variable_get('update_advanced_project_settings', array());
  82. foreach ($projects as $project => $project_info) {
  83. if (isset($settings[$project]) && isset($settings[$project]['check']) &&
  84. ($settings[$project]['check'] == 'never' ||
  85. (isset($project_info['recommended']) &&
  86. $settings[$project]['check'] === $project_info['recommended']))) {
  87. $projects[$project]['status'] = UPDATE_NOT_CHECKED;
  88. $projects[$project]['reason'] = t('Ignored from settings');
  89. if (!empty($settings[$project]['notes'])) {
  90. $projects[$project]['extra'][] = array(
  91. 'class' => array('admin-note'),
  92. 'label' => t('Administrator note'),
  93. 'data' => $settings[$project]['notes'],
  94. );
  95. }
  96. }
  97. }
  98. }
  99. /**
  100. * Verify an archive after it has been downloaded and extracted.
  101. *
  102. * @param string $project
  103. * The short name of the project that has been downloaded.
  104. * @param string $archive_file
  105. * The filename of the unextracted archive.
  106. * @param string $directory
  107. * The directory that the archive was extracted into.
  108. *
  109. * @return
  110. * If there are any problems, return an array of error messages. If there are
  111. * no problems, return an empty array.
  112. *
  113. * @see update_manager_archive_verify()
  114. * @ingroup update_manager_file
  115. */
  116. function hook_verify_update_archive($project, $archive_file, $directory) {
  117. $errors = array();
  118. if (!file_exists($directory)) {
  119. $errors[] = t('The %directory does not exist.', array('%directory' => $directory));
  120. }
  121. // Add other checks on the archive integrity here.
  122. return $errors;
  123. }
  124. /**
  125. * @} End of "addtogroup hooks".
  126. */