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