| 1 |
<?php
|
| 2 |
// $Id: date_api.install,v 1.22 2009/09/05 09:26:56 karens Exp $
|
| 3 |
function date_api_set_variables() {
|
| 4 |
/**
|
| 5 |
* Set absolute minimum and maximum year for dates on this site.
|
| 6 |
*
|
| 7 |
* There is actually no maximum and minimum year in PHP 5, but a date with
|
| 8 |
* a year less than 0 would result in negative ISO and DATETIME dates,
|
| 9 |
* like -1250-01-01T00:00:00, which probably won't make sense or work
|
| 10 |
* correctly anywhere.
|
| 11 |
*
|
| 12 |
* The odd construct of using variable_get() instead of variable_set()
|
| 13 |
* is so we don't accidentally write over an existing value. If
|
| 14 |
* no value is set, variable_get() will set it.
|
| 15 |
*/
|
| 16 |
variable_get('date_max_year', 4000);
|
| 17 |
variable_get('date_min_year', 1);
|
| 18 |
variable_get('date_php_min_year', 1901);
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Set an API version in a way that other modules can test for compatibility.
|
| 22 |
*/
|
| 23 |
variable_set('date_api_version', '7.2');
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implementation of hook_schema().
|
| 28 |
*/
|
| 29 |
function date_api_schema() {
|
| 30 |
$schema['date_format_types'] = array(
|
| 31 |
'description' => 'For storing configured date format types. ',
|
| 32 |
'fields' => array(
|
| 33 |
'type' => array(
|
| 34 |
'description' => 'The date format type, e.g. medium. ',
|
| 35 |
'type' => 'varchar',
|
| 36 |
'length' => 200,
|
| 37 |
'not null' => TRUE,
|
| 38 |
),
|
| 39 |
'title' => array(
|
| 40 |
'description' => 'The human readable name of the format type. ',
|
| 41 |
'type' => 'varchar',
|
| 42 |
'length' => 255,
|
| 43 |
'not null' => TRUE,
|
| 44 |
),
|
| 45 |
'locked' => array(
|
| 46 |
'description' => 'Whether or not this is a system provided format. ',
|
| 47 |
'type' => 'int',
|
| 48 |
'size' => 'tiny',
|
| 49 |
'default' => 0,
|
| 50 |
'not null' => TRUE,
|
| 51 |
),
|
| 52 |
),
|
| 53 |
'primary key' => array('type'),
|
| 54 |
);
|
| 55 |
|
| 56 |
$schema['date_formats'] = array(
|
| 57 |
'description' => 'For storing configured date formats. ',
|
| 58 |
'fields' => array(
|
| 59 |
'dfid' => array(
|
| 60 |
'description' => 'The date format identifier. ',
|
| 61 |
'type' => 'serial',
|
| 62 |
'not null' => TRUE,
|
| 63 |
'unsigned' => TRUE,
|
| 64 |
),
|
| 65 |
'format' => array(
|
| 66 |
'description' => 'The date format string. ',
|
| 67 |
'type' => 'varchar',
|
| 68 |
'length' => 100,
|
| 69 |
'not null' => TRUE,
|
| 70 |
),
|
| 71 |
'type' => array(
|
| 72 |
'description' => 'The date format type, e.g. medium. ',
|
| 73 |
'type' => 'varchar',
|
| 74 |
'length' => 200,
|
| 75 |
'not null' => TRUE,
|
| 76 |
),
|
| 77 |
'locked' => array(
|
| 78 |
'description' => 'Whether or not this format can be modified. ',
|
| 79 |
'type' => 'int',
|
| 80 |
'size' => 'tiny',
|
| 81 |
'default' => 0,
|
| 82 |
'not null' => TRUE,
|
| 83 |
),
|
| 84 |
),
|
| 85 |
'primary key' => array('dfid'),
|
| 86 |
'unique keys' => array('formats' => array('format', 'type')),
|
| 87 |
);
|
| 88 |
|
| 89 |
$schema['date_format_locale'] = array(
|
| 90 |
'description' => 'For storing configured date formats for each locale. ',
|
| 91 |
'fields' => array(
|
| 92 |
'format' => array(
|
| 93 |
'description' => 'The date format string. ',
|
| 94 |
'type' => 'varchar',
|
| 95 |
'length' => 100,
|
| 96 |
'not null' => TRUE,
|
| 97 |
),
|
| 98 |
'type' => array(
|
| 99 |
'description' => 'The date format type, e.g. medium. ',
|
| 100 |
'type' => 'varchar',
|
| 101 |
'length' => 200,
|
| 102 |
'not null' => TRUE,
|
| 103 |
),
|
| 104 |
'language' => array(
|
| 105 |
'description' => 'A {languages}.language for this format to be used with. ',
|
| 106 |
'type' => 'varchar',
|
| 107 |
'length' => 12,
|
| 108 |
'not null' => TRUE,
|
| 109 |
),
|
| 110 |
),
|
| 111 |
'primary key' => array('type', 'language'),
|
| 112 |
);
|
| 113 |
|
| 114 |
return $schema;
|
| 115 |
}
|
| 116 |
|
| 117 |
/**
|
| 118 |
* Implementation of hook_install().
|
| 119 |
*/
|
| 120 |
function date_api_install() {
|
| 121 |
drupal_install_schema('date_api');
|
| 122 |
|
| 123 |
// date_api_set_variables can install date_timezone and date_php4. The
|
| 124 |
// date_timezone_install() function does a module_enable('date_api'). This
|
| 125 |
// means that date_api_enable() can be called before date_api_install()
|
| 126 |
// finishes! So the date_api schema needs to be installed before this line!
|
| 127 |
date_api_set_variables();
|
| 128 |
|
| 129 |
$ret = array();
|
| 130 |
db_add_field($ret, "users", "timezone_name", array('type' => 'varchar', 'length' => 50, 'not null' => TRUE, 'default' => ''));
|
| 131 |
|
| 132 |
// Make sure MYSQL does not stupidly do case-insensitive
|
| 133 |
// searches and indexes on our formats.
|
| 134 |
// @see http://pure.rednoize.com/2006/11/26/mysql-collation-matters-when-using-unique-indexes/
|
| 135 |
// @see http://jjinux.blogspot.com/2009/03/mysql-case-sensitivity-hell.html
|
| 136 |
// @see http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
|
| 137 |
global $db_type;
|
| 138 |
if ($db_type == 'mysql' || $db_type == 'mysqli') {
|
| 139 |
$sql = "ALTER TABLE {date_formats} CHANGE format format VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
|
| 140 |
$ret[] = update_sql($sql);
|
| 141 |
$sql = "ALTER TABLE {date_format_locale} CHANGE format format VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
|
| 142 |
$ret[] = update_sql($sql);
|
| 143 |
}
|
| 144 |
|
| 145 |
return $ret;
|
| 146 |
}
|
| 147 |
|
| 148 |
/**
|
| 149 |
* Implementation of hook_enable().
|
| 150 |
*/
|
| 151 |
function date_api_enable() {
|
| 152 |
/* When module is enabled, build the list of date formats and types. This
|
| 153 |
* includes those provided by this module and other contrib modules. As the
|
| 154 |
* date_format tables are created but the schema hasn't been updated, force
|
| 155 |
* a refresh so we can use the schema API. */
|
| 156 |
drupal_get_schema('', TRUE);
|
| 157 |
// Ensure schema has been installed - order of things gets out of sync because
|
| 158 |
// date_api_set_variables() in date_api_install() enables the 'date_timezone'
|
| 159 |
// module, which in return enables the 'date_api' module!
|
| 160 |
if (db_table_exists('date_format_types')) {
|
| 161 |
date_formats_rebuild();
|
| 162 |
}
|
| 163 |
date_api_set_variables();
|
| 164 |
|
| 165 |
}
|
| 166 |
|
| 167 |
/**
|
| 168 |
* Implementation of hook_uninstall().
|
| 169 |
*/
|
| 170 |
function date_api_uninstall() {
|
| 171 |
$ret = array();
|
| 172 |
|
| 173 |
cache_clear_all('date_timezone_identifiers_list', 'cache');
|
| 174 |
$variables = array(
|
| 175 |
'date_api_version',
|
| 176 |
'date_min_year',
|
| 177 |
'date_max_year',
|
| 178 |
'date_php_min_year',
|
| 179 |
'date_db_tz_support',
|
| 180 |
);
|
| 181 |
foreach ($variables as $variable) {
|
| 182 |
variable_del($variable);
|
| 183 |
}
|
| 184 |
|
| 185 |
if (db_table_exists('views_display')) {
|
| 186 |
$displays = array(
|
| 187 |
'date_nav',
|
| 188 |
);
|
| 189 |
db_query("DELETE FROM {views_display} WHERE display_plugin IN ('". implode("','", $displays) ."')");
|
| 190 |
db_query("DELETE FROM {cache_views}");
|
| 191 |
}
|
| 192 |
|
| 193 |
drupal_uninstall_schema('date_api');
|
| 194 |
return $ret;
|
| 195 |
}
|
| 196 |
|
| 197 |
/**
|
| 198 |
* Make sure all the appropriate modules get enabled.
|
| 199 |
*/
|
| 200 |
function date_api_update_5200() {
|
| 201 |
$ret = array();
|
| 202 |
return $ret;
|
| 203 |
}
|
| 204 |
|
| 205 |
/**
|
| 206 |
* Make sure all the appropriate modules get enabled.
|
| 207 |
* Repeated again in the 5.2 version.
|
| 208 |
*/
|
| 209 |
function date_api_update_5201() {
|
| 210 |
$ret = array();
|
| 211 |
return $ret;
|
| 212 |
}
|
| 213 |
|
| 214 |
/**
|
| 215 |
* Make sure all the appropriate modules get enabled.
|
| 216 |
* Repeated again just to be sure they are set.
|
| 217 |
*/
|
| 218 |
function date_api_update_6000() {
|
| 219 |
$ret = array();
|
| 220 |
// don't attempt to upgrade if views is not yet upgraded.
|
| 221 |
if (module_exists('views') && drupal_get_installed_schema_version('views', TRUE) < 6000) {
|
| 222 |
$ret = array();
|
| 223 |
drupal_set_message(t('date module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates. ', array('@update-php' => base_path() . 'update.php?op=selection')), 'warning', FALSE);
|
| 224 |
$ret['#abort'] = array('success' => FALSE, 'query' => t('date.module has updates, but cannot be updated until views.module is updated first.'));
|
| 225 |
|
| 226 |
return $ret;
|
| 227 |
}
|
| 228 |
date_api_set_variables();
|
| 229 |
return $ret;
|
| 230 |
}
|
| 231 |
|
| 232 |
/**
|
| 233 |
* Rebuild the theme registry and all the caches.
|
| 234 |
* needed to pick up changes created by updated Views API.
|
| 235 |
*/
|
| 236 |
function date_api_update_6001() {
|
| 237 |
$ret = array();
|
| 238 |
// don't attempt to upgrade if views is not yet upgraded.
|
| 239 |
if (module_exists('views') && drupal_get_installed_schema_version('views', TRUE) < 6000) {
|
| 240 |
$ret = array();
|
| 241 |
drupal_set_message(t('date module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates. ', array('@update-php' => base_path() . 'update.php?op=selection')), 'warning', FALSE);
|
| 242 |
$ret['#abort'] = array('success' => FALSE, 'query' => t('date.module has updates, but cannot be updated until views.module is updated first.'));
|
| 243 |
|
| 244 |
return $ret;
|
| 245 |
}
|
| 246 |
if (db_table_exists('cache_content')) {
|
| 247 |
db_query('DELETE FROM {cache_content}');
|
| 248 |
}
|
| 249 |
if (db_table_exists('cache_views')) {
|
| 250 |
db_query('DELETE FROM {cache_views}');
|
| 251 |
}
|
| 252 |
if (db_table_exists('views_object_cache')) {
|
| 253 |
db_query('DELETE FROM {views_object_cache}');
|
| 254 |
}
|
| 255 |
db_query("DELETE FROM {cache} where cid LIKE 'theme_registry%'");
|
| 256 |
return $ret;
|
| 257 |
}
|
| 258 |
|
| 259 |
/**
|
| 260 |
* Create new date format tables.
|
| 261 |
*/
|
| 262 |
function date_api_update_6002() {
|
| 263 |
$ret = array();
|
| 264 |
// don't attempt to upgrade if views is not yet upgraded.
|
| 265 |
if (module_exists('views') && drupal_get_installed_schema_version('views', TRUE) < 6000) {
|
| 266 |
$ret = array();
|
| 267 |
drupal_set_message(t('date module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates. ', array('@update-php' => base_path() . 'update.php?op=selection')), 'warning', FALSE);
|
| 268 |
$ret['#abort'] = array('success' => FALSE, 'query' => t('date.module has updates, but cannot be updated until views.module is updated first.'));
|
| 269 |
|
| 270 |
return $ret;
|
| 271 |
}
|
| 272 |
|
| 273 |
$schema['date_format_types'] = array(
|
| 274 |
'fields' => array(
|
| 275 |
'type' => array(
|
| 276 |
'type' => 'varchar',
|
| 277 |
'length' => 200,
|
| 278 |
'not null' => TRUE,
|
| 279 |
),
|
| 280 |
'title' => array(
|
| 281 |
'type' => 'varchar',
|
| 282 |
'length' => 255,
|
| 283 |
'not null' => TRUE,
|
| 284 |
),
|
| 285 |
'locked' => array(
|
| 286 |
'type' => 'int',
|
| 287 |
'size' => 'tiny',
|
| 288 |
'default' => 0,
|
| 289 |
'not null' => TRUE,
|
| 290 |
),
|
| 291 |
),
|
| 292 |
'primary key' => array('type'),
|
| 293 |
);
|
| 294 |
|
| 295 |
$schema['date_format'] = array(
|
| 296 |
'fields' => array(
|
| 297 |
'dfid' => array(
|
| 298 |
'type' => 'serial',
|
| 299 |
'not null' => TRUE,
|
| 300 |
'unsigned' => TRUE,
|
| 301 |
),
|
| 302 |
'format' => array(
|
| 303 |
'type' => 'varchar',
|
| 304 |
'length' => 100,
|
| 305 |
'not null' => TRUE,
|
| 306 |
),
|
| 307 |
'type' => array(
|
| 308 |
'type' => 'varchar',
|
| 309 |
'length' => 200,
|
| 310 |
'not null' => TRUE,
|
| 311 |
),
|
| 312 |
'locked' => array(
|
| 313 |
'type' => 'int',
|
| 314 |
'size' => 'tiny',
|
| 315 |
'default' => 0,
|
| 316 |
'not null' => TRUE,
|
| 317 |
),
|
| 318 |
),
|
| 319 |
'primary key' => array('dfid'),
|
| 320 |
'unique keys' => array('format' => array('format', 'type')),
|
| 321 |
);
|
| 322 |
|
| 323 |
$schema['date_format_locale'] = array(
|
| 324 |
'fields' => array(
|
| 325 |
'format' => array(
|
| 326 |
'type' => 'varchar',
|
| 327 |
'length' => 255,
|
| 328 |
'not null' => TRUE,
|
| 329 |
),
|
| 330 |
'type' => array(
|
| 331 |
'type' => 'varchar',
|
| 332 |
'length' => 200,
|
| 333 |
'not null' => TRUE,
|
| 334 |
),
|
| 335 |
'language' => array(
|
| 336 |
'type' => 'varchar',
|
| 337 |
'length' => 12,
|
| 338 |
'not null' => TRUE,
|
| 339 |
),
|
| 340 |
),
|
| 341 |
'primary key' => array('type', 'language'),
|
| 342 |
);
|
| 343 |
|
| 344 |
|
| 345 |
db_create_table($ret, 'date_format_types', $schema['date_format_types']);
|
| 346 |
db_create_table($ret, 'date_format', $schema['date_format']);
|
| 347 |
db_create_table($ret, 'date_format_locale', $schema['date_format_locale']);
|
| 348 |
|
| 349 |
return $ret;
|
| 350 |
}
|
| 351 |
|
| 352 |
function date_api_update_6003() {
|
| 353 |
$ret = array();
|
| 354 |
db_change_field($ret, 'date_format_types', 'type', 'type', array('type' => 'varchar', 'length' => 200, 'not null' => TRUE));
|
| 355 |
db_change_field($ret, 'date_format', 'type', 'type', array('type' => 'varchar', 'length' => 200, 'not null' => TRUE));
|
| 356 |
db_change_field($ret, 'date_format', 'format', 'format', array('type' => 'varchar', 'length' => 100, 'not null' => TRUE));
|
| 357 |
db_change_field($ret, 'date_format_locale', 'type', 'type', array('type' => 'varchar', 'length' => 200, 'not null' => TRUE));
|
| 358 |
db_change_field($ret, 'date_format_locale', 'format', 'format', array('type' => 'varchar', 'length' => 100, 'not null' => TRUE));
|
| 359 |
db_drop_unique_key($ret, 'date_format', 'format');
|
| 360 |
db_add_unique_key($ret, 'date_format', 'format', array('format', 'type'));
|
| 361 |
return $ret;
|
| 362 |
}
|
| 363 |
|
| 364 |
/**
|
| 365 |
* The "date_format" table is missing on boxes having MySQL 5.0.67 installed.
|
| 366 |
* There seems to be a bug in MySQL that prevents the creation of tables with
|
| 367 |
* a name "date_format" and indexes with the name "format".
|
| 368 |
*
|
| 369 |
* We rename the table and index as a workaround.
|
| 370 |
*/
|
| 371 |
function date_api_update_6004() {
|
| 372 |
$ret = array();
|
| 373 |
|
| 374 |
$schema['date_formats'] = array(
|
| 375 |
'description' => 'For storing configured date formats. ',
|
| 376 |
'fields' => array(
|
| 377 |
'dfid' => array(
|
| 378 |
'description' => 'The date format identifier. ',
|
| 379 |
'type' => 'serial',
|
| 380 |
'not null' => TRUE,
|
| 381 |
'unsigned' => TRUE,
|
| 382 |
),
|
| 383 |
'format' => array(
|
| 384 |
'description' => 'The date format string. ',
|
| 385 |
'type' => 'varchar',
|
| 386 |
'length' => 100,
|
| 387 |
'not null' => TRUE,
|
| 388 |
),
|
| 389 |
'type' => array(
|
| 390 |
'description' => 'The date format type, e.g. medium. ',
|
| 391 |
'type' => 'varchar',
|
| 392 |
'length' => 200,
|
| 393 |
'not null' => TRUE,
|
| 394 |
),
|
| 395 |
'locked' => array(
|
| 396 |
'description' => 'Whether or not this format can be modified. ',
|
| 397 |
'type' => 'int',
|
| 398 |
'size' => 'tiny',
|
| 399 |
'default' => 0,
|
| 400 |
'not null' => TRUE,
|
| 401 |
),
|
| 402 |
),
|
| 403 |
'primary key' => array('dfid'),
|
| 404 |
'unique keys' => array('formats' => array('format', 'type')),
|
| 405 |
);
|
| 406 |
|
| 407 |
// Create missing table.
|
| 408 |
if (!db_table_exists('date_format')) {
|
| 409 |
db_create_table($ret, 'date_formats', $schema['date_formats']);
|
| 410 |
date_formats_rebuild();
|
| 411 |
}
|
| 412 |
// Rename existing table and index.
|
| 413 |
else {
|
| 414 |
db_drop_unique_key($ret, 'date_format', 'format');
|
| 415 |
db_rename_table($ret, 'date_format', 'date_formats');
|
| 416 |
db_add_unique_key($ret, 'date_formats', 'formats', array('format', 'type'));
|
| 417 |
}
|
| 418 |
|
| 419 |
return $ret;
|
| 420 |
}
|
| 421 |
|
| 422 |
/**
|
| 423 |
* Make sure MYSQL does not stupidly do case-insensitive
|
| 424 |
* searches and indexes on our formats.
|
| 425 |
* @see http://pure.rednoize.com/2006/11/26/mysql-collation-matters-when-using-unique-indexes/
|
| 426 |
* @see http://jjinux.blogspot.com/2009/03/mysql-case-sensitivity-hell.html
|
| 427 |
* @see http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
|
| 428 |
*/
|
| 429 |
function date_api_update_6005() {
|
| 430 |
global $db_type;
|
| 431 |
$ret = array();
|
| 432 |
if ($db_type == 'mysql' || $db_type == 'mysqli') {
|
| 433 |
$sql = "ALTER TABLE {date_formats} CHANGE format format VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
|
| 434 |
$ret[] = update_sql($sql);
|
| 435 |
$sql = "ALTER TABLE {date_format_locale} CHANGE format format VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
|
| 436 |
$ret[] = update_sql($sql);
|
| 437 |
}
|
| 438 |
return $ret;
|
| 439 |
}
|