1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Install, update, and uninstall functions for the Update Manager module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_requirements().
|
10 |
|
|
*
|
11 |
|
|
* @return
|
12 |
|
|
* An array describing the status of the site regarding available updates. If
|
13 |
|
|
* there is no update data, only one record will be returned, indicating that
|
14 |
|
|
* the status of core can't be determined. If data is available, there will be
|
15 |
|
|
* two records: one for core, and another for all of contrib (assuming there
|
16 |
|
|
* are any contributed modules or themes enabled on the site). In addition to
|
17 |
|
|
* the fields expected by hook_requirements ('value', 'severity', and
|
18 |
|
|
* optionally 'description'), this array will contain a 'reason' attribute,
|
19 |
|
|
* which is an integer constant to indicate why the given status is being
|
20 |
|
|
* returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or UPDATE_UNKNOWN). This
|
21 |
|
|
* is used for generating the appropriate e-mail notification messages during
|
22 |
|
|
* update_cron(), and might be useful for other modules that invoke
|
23 |
|
|
* update_requirements() to find out if the site is up to date or not.
|
24 |
|
|
*
|
25 |
|
|
* @see _update_message_text()
|
26 |
|
|
* @see _update_cron_notify()
|
27 |
|
|
*/
|
28 |
|
|
function update_requirements($phase) {
|
29 |
|
|
$requirements = array();
|
30 |
|
|
if ($phase == 'runtime') {
|
31 |
|
|
if ($available = update_get_available(FALSE)) {
|
32 |
|
|
module_load_include('inc', 'update', 'update.compare');
|
33 |
|
|
$data = update_calculate_project_data($available);
|
34 |
|
|
// First, populate the requirements for core:
|
35 |
|
|
$requirements['update_core'] = _update_requirement_check($data['drupal'], 'core');
|
36 |
|
|
// We don't want to check drupal a second time.
|
37 |
|
|
unset($data['drupal']);
|
38 |
|
|
if (!empty($data)) {
|
39 |
|
|
// Now, sort our $data array based on each project's status. The
|
40 |
|
|
// status constants are numbered in the right order of precedence, so
|
41 |
|
|
// we just need to make sure the projects are sorted in ascending
|
42 |
|
|
// order of status, and we can look at the first project we find.
|
43 |
|
|
uasort($data, '_update_project_status_sort');
|
44 |
|
|
$first_project = reset($data);
|
45 |
|
|
$requirements['update_contrib'] = _update_requirement_check($first_project, 'contrib');
|
46 |
|
|
}
|
47 |
|
|
}
|
48 |
|
|
else {
|
49 |
|
|
$requirements['update_core']['title'] = t('Drupal core update status');
|
50 |
|
|
$requirements['update_core']['value'] = t('No update data available');
|
51 |
|
|
$requirements['update_core']['severity'] = REQUIREMENT_WARNING;
|
52 |
|
|
$requirements['update_core']['reason'] = UPDATE_UNKNOWN;
|
53 |
|
|
$requirements['update_core']['description'] = _update_no_data();
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
return $requirements;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Implements hook_schema().
|
61 |
|
|
*/
|
62 |
|
|
function update_schema() {
|
63 |
|
|
$schema['cache_update'] = drupal_get_schema_unprocessed('system', 'cache');
|
64 |
|
|
$schema['cache_update']['description'] = 'Cache table for the Update module to store information about available releases, fetched from central server.';
|
65 |
|
|
return $schema;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* Implements hook_install().
|
70 |
|
|
*/
|
71 |
|
|
function update_install() {
|
72 |
|
|
$queue = DrupalQueue::get('update_fetch_tasks', TRUE);
|
73 |
|
|
$queue->createQueue();
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/**
|
77 |
|
|
* Implements hook_uninstall().
|
78 |
|
|
*/
|
79 |
|
|
function update_uninstall() {
|
80 |
|
|
// Clear any variables that might be in use
|
81 |
|
|
$variables = array(
|
82 |
|
|
'update_check_frequency',
|
83 |
|
|
'update_fetch_url',
|
84 |
|
|
'update_last_check',
|
85 |
|
|
'update_last_email_notification',
|
86 |
|
|
'update_notification_threshold',
|
87 |
|
|
'update_notify_emails',
|
88 |
|
|
'update_max_fetch_attempts',
|
89 |
|
|
'update_max_fetch_time',
|
90 |
|
|
);
|
91 |
|
|
foreach ($variables as $variable) {
|
92 |
|
|
variable_del($variable);
|
93 |
|
|
}
|
94 |
|
|
$queue = DrupalQueue::get('update_fetch_tasks');
|
95 |
|
|
$queue->deleteQueue();
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
/**
|
99 |
|
|
* Fills in the requirements array.
|
100 |
|
|
*
|
101 |
|
|
* This is shared for both core and contrib to generate the right elements in
|
102 |
|
|
* the array for hook_requirements().
|
103 |
|
|
*
|
104 |
|
|
* @param $project
|
105 |
|
|
* Array of information about the project we're testing as returned by
|
106 |
|
|
* update_calculate_project_data().
|
107 |
|
|
* @param $type
|
108 |
|
|
* What kind of project this is ('core' or 'contrib').
|
109 |
|
|
*
|
110 |
|
|
* @return
|
111 |
|
|
* An array to be included in the nested $requirements array.
|
112 |
|
|
*
|
113 |
|
|
* @see hook_requirements()
|
114 |
|
|
* @see update_requirements()
|
115 |
|
|
* @see update_calculate_project_data()
|
116 |
|
|
*/
|
117 |
|
|
function _update_requirement_check($project, $type) {
|
118 |
|
|
$requirement = array();
|
119 |
|
|
if ($type == 'core') {
|
120 |
|
|
$requirement['title'] = t('Drupal core update status');
|
121 |
|
|
}
|
122 |
|
|
else {
|
123 |
|
|
$requirement['title'] = t('Module and theme update status');
|
124 |
|
|
}
|
125 |
|
|
$status = $project['status'];
|
126 |
|
|
if ($status != UPDATE_CURRENT) {
|
127 |
|
|
$requirement['reason'] = $status;
|
128 |
|
|
$requirement['description'] = _update_message_text($type, $status, TRUE);
|
129 |
|
|
$requirement['severity'] = REQUIREMENT_ERROR;
|
130 |
|
|
}
|
131 |
|
|
switch ($status) {
|
132 |
|
|
case UPDATE_NOT_SECURE:
|
133 |
|
|
$requirement_label = t('Not secure!');
|
134 |
|
|
break;
|
135 |
|
|
case UPDATE_REVOKED:
|
136 |
|
|
$requirement_label = t('Revoked!');
|
137 |
|
|
break;
|
138 |
|
|
case UPDATE_NOT_SUPPORTED:
|
139 |
|
|
$requirement_label = t('Unsupported release');
|
140 |
|
|
break;
|
141 |
|
|
case UPDATE_NOT_CURRENT:
|
142 |
|
|
$requirement_label = t('Out of date');
|
143 |
|
|
$requirement['severity'] = REQUIREMENT_WARNING;
|
144 |
|
|
break;
|
145 |
|
|
case UPDATE_UNKNOWN:
|
146 |
|
|
case UPDATE_NOT_CHECKED:
|
147 |
|
|
case UPDATE_NOT_FETCHED:
|
148 |
|
|
$requirement_label = isset($project['reason']) ? $project['reason'] : t('Can not determine status');
|
149 |
|
|
$requirement['severity'] = REQUIREMENT_WARNING;
|
150 |
|
|
break;
|
151 |
|
|
default:
|
152 |
|
|
$requirement_label = t('Up to date');
|
153 |
|
|
}
|
154 |
|
|
if ($status != UPDATE_CURRENT && $type == 'core' && isset($project['recommended'])) {
|
155 |
|
|
$requirement_label .= ' ' . t('(version @version available)', array('@version' => $project['recommended']));
|
156 |
|
|
}
|
157 |
|
|
$requirement['value'] = l($requirement_label, update_manager_access() ? 'admin/reports/updates/update' : 'admin/reports/updates');
|
158 |
|
|
return $requirement;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
/**
|
162 |
|
|
* @addtogroup updates-6.x-to-7.x
|
163 |
|
|
* @{
|
164 |
|
|
*/
|
165 |
|
|
|
166 |
|
|
/**
|
167 |
|
|
* Create a queue to store tasks for requests to fetch available update data.
|
168 |
|
|
*/
|
169 |
|
|
function update_update_7000() {
|
170 |
|
|
module_load_include('inc', 'system', 'system.queue');
|
171 |
|
|
$queue = DrupalQueue::get('update_fetch_tasks');
|
172 |
|
|
$queue->createQueue();
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
/**
|
176 |
|
|
* Recreates cache_update table.
|
177 |
|
|
*
|
178 |
|
|
* Converts fields that hold serialized variables from text to blob.
|
179 |
|
|
* Removes 'headers' column.
|
180 |
|
|
*/
|
181 |
|
|
function update_update_7001() {
|
182 |
|
|
$schema = system_schema_cache_7054();
|
183 |
|
|
|
184 |
|
|
db_drop_table('cache_update');
|
185 |
|
|
db_create_table('cache_update', $schema);
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
/**
|
189 |
|
|
* @} End of "addtogroup updates-6.x-to-7.x".
|
190 |
|
|
*/ |