update.api.php

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

Hooks provided by the Update Status module.

Functions & methods

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