1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Install, update and uninstall functions for the date_api module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Helper function for setting Date variables.
|
10 |
|
|
*/
|
11 |
|
|
function date_api_set_variables() {
|
12 |
|
|
// Set absolute minimum and maximum year for dates on this site.
|
13 |
|
|
// There is actually no maximum and minimum year in PHP 5, but a date with
|
14 |
|
|
// a year less than 0 would result in negative ISO and DATETIME dates,
|
15 |
|
|
// like -1250-01-01T00:00:00, which probably won't make sense or work
|
16 |
|
|
// correctly anywhere.
|
17 |
|
|
// The odd construct of using variable_get() instead of variable_set()
|
18 |
|
|
// is so we don't accidentally write over an existing value. If
|
19 |
|
|
// no value is set, variable_get() will set it.
|
20 |
|
|
variable_get('date_max_year', 4000);
|
21 |
|
|
variable_get('date_min_year', 1);
|
22 |
|
|
variable_get('date_php_min_year', 1901);
|
23 |
|
|
|
24 |
|
|
// Set an API version in a way that other modules can test for compatibility.
|
25 |
|
|
variable_set('date_api_version', '7.2');
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* Implements hook_requirements().
|
30 |
|
|
*/
|
31 |
|
|
function date_api_requirements($phase) {
|
32 |
|
|
$requirements = array();
|
33 |
|
|
|
34 |
|
|
if ($phase == 'runtime') {
|
35 |
|
|
$t = get_t();
|
36 |
|
|
module_load_include('module', 'date_api');
|
37 |
|
|
$messages = date_api_status();
|
38 |
|
|
$error_messages = !empty($messages['errors']) ? $messages['errors'] : array();
|
39 |
|
|
$success_messages = !empty($messages['success']) ? $messages['success'] : array();
|
40 |
|
|
|
41 |
|
|
if (!empty($error_messages)) {
|
42 |
|
|
$requirements['date'] = array(
|
43 |
|
|
'title' => $t('Date API'),
|
44 |
|
|
'value' => $t('Missing system date settings'),
|
45 |
|
|
'description' => implode(' ', array_merge($error_messages, $success_messages)),
|
46 |
|
|
'severity' => REQUIREMENT_ERROR,
|
47 |
|
|
);
|
48 |
|
|
}
|
49 |
|
|
else {
|
50 |
|
|
$requirements['date'] = array(
|
51 |
|
|
'title' => $t('Date API'),
|
52 |
|
|
'value' => $t('System date settings'),
|
53 |
|
|
'description' => implode(' ', $success_messages),
|
54 |
|
|
);
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
return $requirements;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* Implements hook_install().
|
62 |
|
|
*/
|
63 |
|
|
function date_api_install() {
|
64 |
|
|
// Only set the message if Drupal itself is already installed.
|
65 |
|
|
if (variable_get('install_task') == 'done') {
|
66 |
|
|
// Ensure translations don't break at install time.
|
67 |
|
|
$t = get_t();
|
68 |
|
|
|
69 |
|
|
// date_api_set_variables can install date_timezone. The
|
70 |
|
|
// date_timezone_install() function does a module_enable('date_api'). This
|
71 |
|
|
// means that date_api_enable() can be called before date_api_install()
|
72 |
|
|
// finishes! So the date_api schema needs to be installed before this line!
|
73 |
|
|
date_api_set_variables();
|
74 |
|
|
|
75 |
|
|
$message = $t('The Date API requires that you set up the <a href="@regional_settings">site timezone and first day of week settings</a> and the <a href="@regional_date_time">date format settings</a> to function correctly.', array('@regional_settings' => url('admin/config/regional/settings'), '@regional_date_time' => url('admin/config/regional/date-time')));
|
76 |
|
|
drupal_set_message(filter_xss_admin($message), 'warning');
|
77 |
|
|
}
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
/**
|
81 |
|
|
* Implements hook_enable().
|
82 |
|
|
*/
|
83 |
|
|
function date_api_enable() {
|
84 |
|
|
date_api_set_variables();
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
/**
|
88 |
|
|
* Implements hook_uninstall().
|
89 |
|
|
*/
|
90 |
|
|
function date_api_uninstall() {
|
91 |
|
|
cache_clear_all('date_timezone_identifiers_list', 'cache');
|
92 |
|
|
$variables = array(
|
93 |
|
|
'date_api_version',
|
94 |
|
|
'date_min_year',
|
95 |
|
|
'date_max_year',
|
96 |
|
|
'date_php_min_year',
|
97 |
|
|
'date_db_tz_support',
|
98 |
|
|
'date_api_use_iso8601',
|
99 |
b720ea3e
|
Assos Assos
|
);
|
100 |
85ad3d82
|
Assos Assos
|
foreach ($variables as $variable) {
|
101 |
|
|
variable_del($variable);
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
if (db_table_exists('views_display')) {
|
105 |
|
|
$displays = array(
|
106 |
|
|
'date_nav',
|
107 |
|
|
);
|
108 |
|
|
db_query("DELETE FROM {views_display} WHERE display_plugin IN ('" . implode("','", $displays) . "')");
|
109 |
|
|
db_query("DELETE FROM {cache_views}");
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
/**
|
114 |
|
|
* Implements hook_update_last_removed().
|
115 |
|
|
*/
|
116 |
|
|
function date_api_update_last_removed() {
|
117 |
|
|
return 6005;
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
/**
|
121 |
b720ea3e
|
Assos Assos
|
* Move old date format to new date format tables,and delete the old tables.
|
122 |
|
|
*
|
123 |
|
|
* Insert only values that don't already exist in the new tables, in
|
124 |
85ad3d82
|
Assos Assos
|
* case new version of those custom values have already been created.
|
125 |
|
|
*/
|
126 |
|
|
function date_api_update_7000() {
|
127 |
|
|
// Move format data from the old 'date_format_types' table to the new
|
128 |
|
|
// 'date_format_type' table.
|
129 |
|
|
if (db_table_exists('date_format_types')) {
|
130 |
|
|
// Find all the custom entries in the D6 table.
|
131 |
599a39cd
|
Assos Assos
|
$result = db_select('date_format_types', 'old_formats')
|
132 |
|
|
->fields('old_formats', array('type', 'title', 'locked'))
|
133 |
85ad3d82
|
Assos Assos
|
->condition('locked', 0)
|
134 |
|
|
->execute()
|
135 |
|
|
->fetchAll(PDO::FETCH_ASSOC);
|
136 |
|
|
|
137 |
|
|
// Iterate over all the old values.
|
138 |
|
|
foreach ($result as $row) {
|
139 |
|
|
// See if this value already exists in the new table
|
140 |
|
|
// (it might have been added manually before this update got run).
|
141 |
599a39cd
|
Assos Assos
|
$count = db_select('date_format_type', 'new_formats')
|
142 |
85ad3d82
|
Assos Assos
|
->condition('type', $row['type'])
|
143 |
|
|
->countQuery()
|
144 |
|
|
->execute()
|
145 |
|
|
->fetchField();
|
146 |
|
|
|
147 |
|
|
// If the value is missing, insert it.
|
148 |
|
|
// Do nothing if it already exists, assume the value in the
|
149 |
|
|
// new table trumps the old values.
|
150 |
|
|
if (empty($count)) {
|
151 |
|
|
db_insert('date_format_type')
|
152 |
|
|
->fields(array(
|
153 |
|
|
'type' => $row['type'],
|
154 |
|
|
'title' => $row['title'],
|
155 |
|
|
'locked' => $row['locked'],
|
156 |
|
|
))
|
157 |
|
|
->execute();
|
158 |
|
|
}
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
// Drop the old table.
|
162 |
|
|
db_drop_table('date_format_types');
|
163 |
|
|
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
// Move format data from the old 'date_formats' table (which was renamed to
|
167 |
|
|
// 'd6_date_formats') to the new 'date_formats' table.
|
168 |
|
|
if (db_table_exists('d6_date_formats')) {
|
169 |
|
|
// Find all the custom entries in the D6 table.
|
170 |
599a39cd
|
Assos Assos
|
$result = db_select('d6_date_formats', 'old_formats')
|
171 |
|
|
->fields('old_formats', array('format', 'type', 'locked'))
|
172 |
85ad3d82
|
Assos Assos
|
->condition('type', 'custom')
|
173 |
|
|
->execute()
|
174 |
|
|
->fetchAll(PDO::FETCH_ASSOC);
|
175 |
|
|
|
176 |
|
|
// Iterate over all the old values.
|
177 |
|
|
foreach ($result as $row) {
|
178 |
|
|
// See if this value already exists in the new table (it might have been
|
179 |
|
|
// added manually before this update got run).
|
180 |
599a39cd
|
Assos Assos
|
$count = db_select('date_formats', 'new_formats')
|
181 |
85ad3d82
|
Assos Assos
|
->condition('format', $row['format'])
|
182 |
|
|
->condition('type', $row['type'])
|
183 |
|
|
->countQuery()
|
184 |
|
|
->execute()
|
185 |
|
|
->fetchField();
|
186 |
|
|
|
187 |
|
|
// If the value is missing, insert it. Do nothing if it already exists,
|
188 |
|
|
// assume the value in the new table trumps the old values.
|
189 |
|
|
if (empty($count)) {
|
190 |
|
|
db_insert('date_formats')
|
191 |
|
|
->fields(array(
|
192 |
|
|
'format' => $row['format'],
|
193 |
|
|
'type' => $row['type'],
|
194 |
|
|
'locked' => $row['locked'],
|
195 |
|
|
))
|
196 |
|
|
->execute();
|
197 |
|
|
}
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
// Drop the old table.
|
201 |
|
|
db_drop_table('d6_date_formats');
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
// Move format data from the old 'date_format_locale' table (which was renamed
|
205 |
|
|
// to 'd6_date_format_locale') to the new 'date_format_locale' table.
|
206 |
|
|
if (db_table_exists('d6_date_format_locale')) {
|
207 |
|
|
// Find all the custom entries in the D6 table.
|
208 |
599a39cd
|
Assos Assos
|
$result = db_select('d6_date_format_locale', 'old_formats')
|
209 |
|
|
->fields('old_formats', array('format', 'type', 'language'))
|
210 |
85ad3d82
|
Assos Assos
|
->condition('type', 'custom')
|
211 |
|
|
->execute()
|
212 |
|
|
->fetchAll(PDO::FETCH_ASSOC);
|
213 |
|
|
|
214 |
|
|
// Iterate over all the old values.
|
215 |
|
|
foreach ($result as $row) {
|
216 |
|
|
// See if this value already exists in the new table (it might have been
|
217 |
|
|
// added manually before this update got run).
|
218 |
599a39cd
|
Assos Assos
|
$count = db_select('date_format_locale', 'new_formats')
|
219 |
85ad3d82
|
Assos Assos
|
->condition('format', $row['format'])
|
220 |
|
|
->condition('type', $row['type'])
|
221 |
|
|
->condition('language', $row['language'])
|
222 |
|
|
->countQuery()
|
223 |
|
|
->execute()
|
224 |
|
|
->fetchField();
|
225 |
|
|
|
226 |
|
|
// If the value is missing, insert it.
|
227 |
|
|
// Do nothing if it already exists, assume the value in the
|
228 |
|
|
// new table trumps the old values.
|
229 |
|
|
if (empty($count)) {
|
230 |
|
|
db_insert('date_format_locale')
|
231 |
|
|
->fields(array(
|
232 |
|
|
'format' => $row['format'],
|
233 |
|
|
'type' => $row['type'],
|
234 |
|
|
'language' => $row['language'],
|
235 |
|
|
))
|
236 |
|
|
->execute();
|
237 |
|
|
}
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
// Drop the old table.
|
241 |
|
|
db_drop_table('d6_date_format_locale');
|
242 |
|
|
}
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
/**
|
247 |
|
|
* Drop D6 timezone_name field on {users} after upgrading to D7.
|
248 |
|
|
*/
|
249 |
|
|
function date_api_update_7001() {
|
250 |
|
|
if (db_field_exists('users', 'timezone_name')) {
|
251 |
|
|
db_drop_field('users', 'timezone_name');
|
252 |
|
|
}
|
253 |
|
|
} |