update.api.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. */