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