| Drupal | PHP Cross Reference | Content Management Systems |
1 <?php 2 3 /** 4 * @file 5 * Install, update and uninstall functions for the system module. 6 */ 7 8 /** 9 * Test and report Drupal installation requirements. 10 * 11 * @param $phase 12 * The current system installation phase. 13 * @return 14 * An array of system requirements. 15 */ 16 function system_requirements($phase) { 17 global $base_url; 18 $requirements = array(); 19 // Ensure translations don't break during installation. 20 $t = get_t(); 21 22 // Report Drupal version 23 if ($phase == 'runtime') { 24 $requirements['drupal'] = array( 25 'title' => $t('Drupal'), 26 'value' => VERSION, 27 'severity' => REQUIREMENT_INFO, 28 'weight' => -10, 29 ); 30 31 // Display the currently active installation profile, if the site 32 // is not running the default installation profile. 33 $profile = drupal_get_profile(); 34 if ($profile != 'standard') { 35 $info = system_get_info('module', $profile); 36 $requirements['install_profile'] = array( 37 'title' => $t('Install profile'), 38 'value' => $t('%profile_name (%profile-%version)', array( 39 '%profile_name' => $info['name'], 40 '%profile' => $profile, 41 '%version' => $info['version'] 42 )), 43 'severity' => REQUIREMENT_INFO, 44 'weight' => -9 45 ); 46 } 47 } 48 49 // Web server information. 50 $software = $_SERVER['SERVER_SOFTWARE']; 51 $requirements['webserver'] = array( 52 'title' => $t('Web server'), 53 'value' => $software, 54 ); 55 56 // Test PHP version and show link to phpinfo() if it's available 57 $phpversion = phpversion(); 58 if (function_exists('phpinfo')) { 59 $requirements['php'] = array( 60 'title' => $t('PHP'), 61 'value' => ($phase == 'runtime') ? $phpversion .' ('. l($t('more information'), 'admin/reports/status/php') .')' : $phpversion, 62 ); 63 } 64 else { 65 $requirements['php'] = array( 66 'title' => $t('PHP'), 67 'value' => $phpversion, 68 'description' => $t('The phpinfo() function has been disabled for security reasons. To see your server\'s phpinfo() information, change your PHP settings or contact your server administrator. For more information, <a href="@phpinfo">Enabling and disabling phpinfo()</a> handbook page.', array('@phpinfo' => 'http://drupal.org/node/243993')), 69 'severity' => REQUIREMENT_INFO, 70 ); 71 } 72 73 if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) { 74 $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP)); 75 $requirements['php']['severity'] = REQUIREMENT_ERROR; 76 // If PHP is old, it's not safe to continue with the requirements check. 77 return $requirements; 78 } 79 // Check that htmlspecialchars() is secure if the site is running any PHP 80 // version older than 5.2.5. We don't simply require 5.2.5, because Ubuntu 81 // 8.04 ships with PHP 5.2.4, but includes the necessary security patch. 82 elseif (version_compare($phpversion, '5.2.5') < 0 && strlen(@htmlspecialchars(chr(0xC0) . chr(0xAF), ENT_QUOTES, 'UTF-8'))) { 83 $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP 5.2.5, or PHP @version with the htmlspecialchars security patch backported.', array('@version' => DRUPAL_MINIMUM_PHP)); 84 $requirements['php']['severity'] = REQUIREMENT_ERROR; 85 // If PHP is old, it's not safe to continue with the requirements check. 86 return $requirements; 87 } 88 89 // Test PHP register_globals setting. 90 $requirements['php_register_globals'] = array( 91 'title' => $t('PHP register globals'), 92 ); 93 $register_globals = trim(ini_get('register_globals')); 94 // Unfortunately, ini_get() may return many different values, and we can't 95 // be certain which values mean 'on', so we instead check for 'not off' 96 // since we never want to tell the user that their site is secure 97 // (register_globals off), when it is in fact on. We can only guarantee 98 // register_globals is off if the value returned is 'off', '', or 0. 99 if (!empty($register_globals) && strtolower($register_globals) != 'off') { 100 $requirements['php_register_globals']['description'] = $t('<em>register_globals</em> is enabled. Drupal requires this configuration directive to be disabled. Your site may not be secure when <em>register_globals</em> is enabled. The PHP manual has instructions for <a href="http://php.net/configuration.changes">how to change configuration settings</a>.'); 101 $requirements['php_register_globals']['severity'] = REQUIREMENT_ERROR; 102 $requirements['php_register_globals']['value'] = $t("Enabled ('@value')", array('@value' => $register_globals)); 103 } 104 else { 105 $requirements['php_register_globals']['value'] = $t('Disabled'); 106 } 107 108 // Test for PHP extensions. 109 $requirements['php_extensions'] = array( 110 'title' => $t('PHP extensions'), 111 ); 112 113 $missing_extensions = array(); 114 $required_extensions = array( 115 'date', 116 'dom', 117 'filter', 118 'gd', 119 'hash', 120 'json', 121 'pcre', 122 'pdo', 123 'session', 124 'SimpleXML', 125 'SPL', 126 'xml', 127 ); 128 foreach ($required_extensions as $extension) { 129 if (!extension_loaded($extension)) { 130 $missing_extensions[] = $extension; 131 } 132 } 133 134 if (!empty($missing_extensions)) { 135 $description = $t('Drupal requires you to enable the PHP extensions in the following list (see the <a href="@system_requirements">system requirements page</a> for more information):', array( 136 '@system_requirements' => 'http://drupal.org/requirements', 137 )); 138 139 $description .= theme('item_list', array('items' => $missing_extensions)); 140 141 $requirements['php_extensions']['value'] = $t('Disabled'); 142 $requirements['php_extensions']['severity'] = REQUIREMENT_ERROR; 143 $requirements['php_extensions']['description'] = $description; 144 } 145 else { 146 $requirements['php_extensions']['value'] = $t('Enabled'); 147 } 148 149 if ($phase == 'install' || $phase == 'update') { 150 // Test for PDO (database). 151 $requirements['database_extensions'] = array( 152 'title' => $t('Database support'), 153 ); 154 155 // Make sure PDO is available. 156 $database_ok = extension_loaded('pdo'); 157 if (!$database_ok) { 158 $pdo_message = $t('Your web server does not appear to support PDO (PHP Data Objects). Ask your hosting provider if they support the native PDO extension. See the <a href="@link">system requirements</a> page for more information.', array( 159 '@link' => 'http://drupal.org/requirements/pdo', 160 )); 161 } 162 else { 163 // Make sure at least one supported database driver exists. 164 $drivers = drupal_detect_database_types(); 165 if (empty($drivers)) { 166 $database_ok = FALSE; 167 $pdo_message = $t('Your web server does not appear to support any common PDO database extensions. Check with your hosting provider to see if they support PDO (PHP Data Objects) and offer any databases that <a href="@drupal-databases">Drupal supports</a>.', array( 168 '@drupal-databases' => 'http://drupal.org/node/270#database', 169 )); 170 } 171 // Make sure the native PDO extension is available, not the older PEAR 172 // version. (See install_verify_pdo() for details.) 173 if (!defined('PDO::ATTR_DEFAULT_FETCH_MODE')) { 174 $database_ok = FALSE; 175 $pdo_message = $t('Your web server seems to have the wrong version of PDO installed. Drupal 7 requires the PDO extension from PHP core. This system has the older PECL version. See the <a href="@link">system requirements</a> page for more information.', array( 176 '@link' => 'http://drupal.org/requirements/pdo#pecl', 177 )); 178 } 179 } 180 181 if (!$database_ok) { 182 $requirements['database_extensions']['value'] = $t('Disabled'); 183 $requirements['database_extensions']['severity'] = REQUIREMENT_ERROR; 184 $requirements['database_extensions']['description'] = $pdo_message; 185 } 186 else { 187 $requirements['database_extensions']['value'] = $t('Enabled'); 188 } 189 } 190 else { 191 // Database information. 192 $class = 'DatabaseTasks_' . Database::getConnection()->driver(); 193 $tasks = new $class(); 194 $requirements['database_system'] = array( 195 'title' => $t('Database system'), 196 'value' => $tasks->name(), 197 ); 198 $requirements['database_system_version'] = array( 199 'title' => $t('Database system version'), 200 'value' => Database::getConnection()->version(), 201 ); 202 } 203 204 // Test PHP memory_limit 205 $memory_limit = ini_get('memory_limit'); 206 $requirements['php_memory_limit'] = array( 207 'title' => $t('PHP memory limit'), 208 'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit, 209 ); 210 211 if ($memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)) { 212 $description = ''; 213 if ($phase == 'install') { 214 $description = $t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', array('%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)); 215 } 216 elseif ($phase == 'update') { 217 $description = $t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', array('%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)); 218 } 219 elseif ($phase == 'runtime') { 220 $description = $t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', array('%memory_limit' => $memory_limit, '%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)); 221 } 222 223 if (!empty($description)) { 224 if ($php_ini_path = get_cfg_var('cfg_file_path')) { 225 $description .= ' ' . $t('Increase the memory limit by editing the memory_limit parameter in the file %configuration-file and then restart your web server (or contact your system administrator or hosting provider for assistance).', array('%configuration-file' => $php_ini_path)); 226 } 227 else { 228 $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.'); 229 } 230 231 $requirements['php_memory_limit']['description'] = $description . ' ' . $t('See the <a href="@url">Drupal requirements</a> for more information.', array('@url' => 'http://drupal.org/requirements')); 232 $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING; 233 } 234 } 235 236 // Test settings.php file writability 237 if ($phase == 'runtime') { 238 $conf_dir = drupal_verify_install_file(conf_path(), FILE_NOT_WRITABLE, 'dir'); 239 $conf_file = drupal_verify_install_file(conf_path() . '/settings.php', FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE); 240 if (!$conf_dir || !$conf_file) { 241 $requirements['settings.php'] = array( 242 'value' => $t('Not protected'), 243 'severity' => REQUIREMENT_ERROR, 244 'description' => '', 245 ); 246 if (!$conf_dir) { 247 $requirements['settings.php']['description'] .= $t('The directory %file is not protected from modifications and poses a security risk. You must change the directory\'s permissions to be non-writable. ', array('%file' => conf_path())); 248 } 249 if (!$conf_file) { 250 $requirements['settings.php']['description'] .= $t('The file %file is not protected from modifications and poses a security risk. You must change the file\'s permissions to be non-writable.', array('%file' => conf_path() . '/settings.php')); 251 } 252 } 253 else { 254 $requirements['settings.php'] = array( 255 'value' => $t('Protected'), 256 ); 257 } 258 $requirements['settings.php']['title'] = $t('Configuration file'); 259 } 260 261 // Report cron status. 262 if ($phase == 'runtime') { 263 // Cron warning threshold defaults to two days. 264 $threshold_warning = variable_get('cron_threshold_warning', 172800); 265 // Cron error threshold defaults to two weeks. 266 $threshold_error = variable_get('cron_threshold_error', 1209600); 267 // Cron configuration help text. 268 $help = $t('For more information, see the online handbook entry for <a href="@cron-handbook">configuring cron jobs</a>.', array('@cron-handbook' => 'http://drupal.org/cron')); 269 270 // Determine when cron last ran. 271 $cron_last = variable_get('cron_last'); 272 if (!is_numeric($cron_last)) { 273 $cron_last = variable_get('install_time', 0); 274 } 275 276 // Determine severity based on time since cron last ran. 277 $severity = REQUIREMENT_OK; 278 if (REQUEST_TIME - $cron_last > $threshold_error) { 279 $severity = REQUIREMENT_ERROR; 280 } 281 elseif (REQUEST_TIME - $cron_last > $threshold_warning) { 282 $severity = REQUIREMENT_WARNING; 283 } 284 285 // Set summary and description based on values determined above. 286 $summary = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last))); 287 $description = ''; 288 if ($severity != REQUIREMENT_OK) { 289 $description = $t('Cron has not run recently.') . ' ' . $help; 290 } 291 292 $description .= ' ' . $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron'))); 293 $description .= '<br />' . $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => variable_get('cron_key', 'drupal')))))); 294 295 $requirements['cron'] = array( 296 'title' => $t('Cron maintenance tasks'), 297 'severity' => $severity, 298 'value' => $summary, 299 'description' => $description 300 ); 301 } 302 303 // Test files directories. 304 $directories = array( 305 variable_get('file_public_path', conf_path() . '/files'), 306 // By default no private files directory is configured. For private files 307 // to be secure the admin needs to provide a path outside the webroot. 308 variable_get('file_private_path', FALSE), 309 ); 310 311 // Do not check for the temporary files directory during installation 312 // unless it has been set in settings.php. In this case the user has 313 // no alternative but to fix the directory if it is not writable. 314 if ($phase == 'install') { 315 $directories[] = variable_get('file_temporary_path', FALSE); 316 } 317 else { 318 $directories[] = variable_get('file_temporary_path', file_directory_temp()); 319 } 320 321 $requirements['file system'] = array( 322 'title' => $t('File system'), 323 ); 324 325 $error = ''; 326 // For installer, create the directories if possible. 327 foreach ($directories as $directory) { 328 if (!$directory) { 329 continue; 330 } 331 if ($phase == 'install') { 332 file_prepare_directory($directory, FILE_CREATE_DIRECTORY); 333 } 334 $is_writable = is_writable($directory); 335 $is_directory = is_dir($directory); 336 if (!$is_writable || !$is_directory) { 337 $description = ''; 338 $requirements['file system']['value'] = $t('Not writable'); 339 if (!$is_directory) { 340 $error .= $t('The directory %directory does not exist.', array('%directory' => $directory)) . ' '; 341 } 342 else { 343 $error .= $t('The directory %directory is not writable.', array('%directory' => $directory)) . ' '; 344 } 345 // The files directory requirement check is done only during install and runtime. 346 if ($phase == 'runtime') { 347 $description = $error . $t('You may need to set the correct directory at the <a href="@admin-file-system">file system settings page</a> or change the current directory\'s permissions so that it is writable.', array('@admin-file-system' => url('admin/config/media/file-system'))); 348 } 349 elseif ($phase == 'install') { 350 // For the installer UI, we need different wording. 'value' will 351 // be treated as version, so provide none there. 352 $description = $error . $t('An automated attempt to create this directory failed, possibly due to a permissions problem. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see INSTALL.txt or the <a href="@handbook_url">online handbook</a>.', array('@handbook_url' => 'http://drupal.org/server-permissions')); 353 $requirements['file system']['value'] = ''; 354 } 355 if (!empty($description)) { 356 $requirements['file system']['description'] = $description; 357 $requirements['file system']['severity'] = REQUIREMENT_ERROR; 358 } 359 } 360 else { 361 if (file_default_scheme() == 'public') { 362 $requirements['file system']['value'] = $t('Writable (<em>public</em> download method)'); 363 } 364 else { 365 $requirements['file system']['value'] = $t('Writable (<em>private</em> download method)'); 366 } 367 } 368 } 369 370 // See if updates are available in update.php. 371 if ($phase == 'runtime') { 372 $requirements['update'] = array( 373 'title' => $t('Database updates'), 374 'severity' => REQUIREMENT_OK, 375 'value' => $t('Up to date'), 376 ); 377 378 // Check installed modules. 379 foreach (module_list() as $module) { 380 $updates = drupal_get_schema_versions($module); 381 if ($updates !== FALSE) { 382 $default = drupal_get_installed_schema_version($module); 383 if (max($updates) > $default) { 384 $requirements['update']['severity'] = REQUIREMENT_ERROR; 385 $requirements['update']['value'] = $t('Out of date'); 386 $requirements['update']['description'] = $t('Some modules have database schema updates to install. You should run the <a href="@update">database update script</a> immediately.', array('@update' => base_path() . 'update.php')); 387 break; 388 } 389 } 390 } 391 } 392 393 // Verify the update.php access setting 394 if ($phase == 'runtime') { 395 if (!empty($GLOBALS['update_free_access'])) { 396 $requirements['update access'] = array( 397 'value' => $t('Not protected'), 398 'severity' => REQUIREMENT_ERROR, 399 'description' => $t('The update.php script is accessible to everyone without authentication check, which is a security risk. You must change the $update_free_access value in your settings.php back to FALSE.'), 400 ); 401 } 402 else { 403 $requirements['update access'] = array( 404 'value' => $t('Protected'), 405 ); 406 } 407 $requirements['update access']['title'] = $t('Access to update.php'); 408 } 409 410 // Display an error if a newly introduced dependency in a module is not resolved. 411 if ($phase == 'update') { 412 $profile = drupal_get_profile(); 413 $files = system_rebuild_module_data(); 414 foreach ($files as $module => $file) { 415 // Ignore disabled modules and installation profiles. 416 if (!$file->status || $module == $profile) { 417 continue; 418 } 419 // Check the module's PHP version. 420 $name = $file->info['name']; 421 $php = $file->info['php']; 422 if (version_compare($php, PHP_VERSION, '>')) { 423 $requirements['php']['description'] .= $t('@name requires at least PHP @version.', array('@name' => $name, '@version' => $php)); 424 $requirements['php']['severity'] = REQUIREMENT_ERROR; 425 } 426 // Check the module's required modules. 427 foreach ($file->requires as $requirement) { 428 $required_module = $requirement['name']; 429 // Check if the module exists. 430 if (!isset($files[$required_module])) { 431 $requirements["$module-$required_module"] = array( 432 'title' => $t('Unresolved dependency'), 433 'description' => $t('@name requires this module.', array('@name' => $name)), 434 'value' => t('@required_name (Missing)', array('@required_name' => $required_module)), 435 'severity' => REQUIREMENT_ERROR, 436 ); 437 continue; 438 } 439 // Check for an incompatible version. 440 $required_file = $files[$required_module]; 441 $required_name = $required_file->info['name']; 442 $version = str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $required_file->info['version']); 443 $compatibility = drupal_check_incompatibility($requirement, $version); 444 if ($compatibility) { 445 $compatibility = rtrim(substr($compatibility, 2), ')'); 446 $requirements["$module-$required_module"] = array( 447 'title' => $t('Unresolved dependency'), 448 'description' => $t('@name requires this module and version. Currently using @required_name version @version', array('@name' => $name, '@required_name' => $required_name, '@version' => $version)), 449 'value' => t('@required_name (Version @compatibility required)', array('@required_name' => $required_name, '@compatibility' => $compatibility)), 450 'severity' => REQUIREMENT_ERROR, 451 ); 452 continue; 453 } 454 } 455 } 456 } 457 458 // Test Unicode library 459 include_once DRUPAL_ROOT . '/includes/unicode.inc'; 460 $requirements = array_merge($requirements, unicode_requirements()); 461 462 if ($phase == 'runtime') { 463 // Check for update status module. 464 if (!module_exists('update')) { 465 $requirements['update status'] = array( 466 'value' => $t('Not enabled'), 467 'severity' => REQUIREMENT_WARNING, 468 'description' => $t('Update notifications are not enabled. It is <strong>highly recommended</strong> that you enable the update manager module from the <a href="@module">module administration page</a> in order to stay up-to-date on new releases. For more information, <a href="@update">Update status handbook page</a>.', array('@update' => 'http://drupal.org/documentation/modules/update', '@module' => url('admin/modules'))), 469 ); 470 } 471 else { 472 $requirements['update status'] = array( 473 'value' => $t('Enabled'), 474 ); 475 } 476 $requirements['update status']['title'] = $t('Update notifications'); 477 478 // Check that Drupal can issue HTTP requests. 479 if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) { 480 $requirements['http requests'] = array( 481 'title' => $t('HTTP request status'), 482 'value' => $t('Fails'), 483 'severity' => REQUIREMENT_ERROR, 484 'description' => $t('Your system or network configuration does not allow Drupal to access web pages, resulting in reduced functionality. This could be due to your webserver configuration or PHP settings, and should be resolved in order to download information about available updates, fetch aggregator feeds, sign in via OpenID, or use other network-dependent services. If you are certain that Drupal can access web pages but you are still seeing this message, you may add <code>$conf[\'drupal_http_request_fails\'] = FALSE;</code> to the bottom of your settings.php file.'), 485 ); 486 } 487 } 488 489 return $requirements; 490 } 491 492 /** 493 * Implements hook_install(). 494 */ 495 function system_install() { 496 // Create tables. 497 drupal_install_schema('system'); 498 $versions = drupal_get_schema_versions('system'); 499 $version = $versions ? max($versions) : SCHEMA_INSTALLED; 500 drupal_set_installed_schema_version('system', $version); 501 502 // Clear out module list and hook implementation statics before calling 503 // system_rebuild_theme_data(). 504 module_list(TRUE); 505 module_implements('', FALSE, TRUE); 506 507 // Load system theme data appropriately. 508 system_rebuild_theme_data(); 509 510 // Enable the default theme. 511 variable_set('theme_default', 'bartik'); 512 db_update('system') 513 ->fields(array('status' => 1)) 514 ->condition('type', 'theme') 515 ->condition('name', 'bartik') 516 ->execute(); 517 518 // Populate the cron key variable. 519 $cron_key = drupal_hash_base64(drupal_random_bytes(55)); 520 variable_set('cron_key', $cron_key); 521 } 522 523 /** 524 * Implements hook_schema(). 525 */ 526 function system_schema() { 527 // NOTE: {variable} needs to be created before all other tables, as 528 // some database drivers, e.g. Oracle and DB2, will require variable_get() 529 // and variable_set() for overcoming some database specific limitations. 530 $schema['variable'] = array( 531 'description' => 'Named variable/value pairs created by Drupal core or any other module or theme. All variables are cached in memory at the start of every Drupal request so developers should not be careless about what is stored here.', 532 'fields' => array( 533 'name' => array( 534 'description' => 'The name of the variable.', 535 'type' => 'varchar', 536 'length' => 128, 537 'not null' => TRUE, 538 'default' => '', 539 ), 540 'value' => array( 541 'description' => 'The value of the variable.', 542 'type' => 'blob', 543 'not null' => TRUE, 544 'size' => 'big', 545 'translatable' => TRUE, 546 ), 547 ), 548 'primary key' => array('name'), 549 ); 550 551 $schema['actions'] = array( 552 'description' => 'Stores action information.', 553 'fields' => array( 554 'aid' => array( 555 'description' => 'Primary Key: Unique actions ID.', 556 'type' => 'varchar', 557 'length' => 255, 558 'not null' => TRUE, 559 'default' => '0', 560 ), 561 'type' => array( 562 'description' => 'The object that that action acts on (node, user, comment, system or custom types.)', 563 'type' => 'varchar', 564 'length' => 32, 565 'not null' => TRUE, 566 'default' => '', 567 ), 568 'callback' => array( 569 'description' => 'The callback function that executes when the action runs.', 570 'type' => 'varchar', 571 'length' => 255, 572 'not null' => TRUE, 573 'default' => '', 574 ), 575 'parameters' => array( 576 'description' => 'Parameters to be passed to the callback function.', 577 'type' => 'blob', 578 'not null' => TRUE, 579 'size' => 'big', 580 ), 581 'label' => array( 582 'description' => 'Label of the action.', 583 'type' => 'varchar', 584 'length' => 255, 585 'not null' => TRUE, 586 'default' => '0', 587 ), 588 ), 589 'primary key' => array('aid'), 590 ); 591 592 $schema['batch'] = array( 593 'description' => 'Stores details about batches (processes that run in multiple HTTP requests).', 594 'fields' => array( 595 'bid' => array( 596 'description' => 'Primary Key: Unique batch ID.', 597 // This is not a serial column, to allow both progressive and 598 // non-progressive batches. See batch_process(). 599 'type' => 'int', 600 'unsigned' => TRUE, 601 'not null' => TRUE, 602 ), 603 'token' => array( 604 'description' => "A string token generated against the current user's session id and the batch id, used to ensure that only the user who submitted the batch can effectively access it.", 605 'type' => 'varchar', 606 'length' => 64, 607 'not null' => TRUE, 608 ), 609 'timestamp' => array( 610 'description' => 'A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.', 611 'type' => 'int', 612 'not null' => TRUE, 613 ), 614 'batch' => array( 615 'description' => 'A serialized array containing the processing data for the batch.', 616 'type' => 'blob', 617 'not null' => FALSE, 618 'size' => 'big', 619 ), 620 ), 621 'primary key' => array('bid'), 622 'indexes' => array( 623 'token' => array('token'), 624 ), 625 ); 626 627 $schema['blocked_ips'] = array( 628 'description' => 'Stores blocked IP addresses.', 629 'fields' => array( 630 'iid' => array( 631 'description' => 'Primary Key: unique ID for IP addresses.', 632 'type' => 'serial', 633 'unsigned' => TRUE, 634 'not null' => TRUE, 635 ), 636 'ip' => array( 637 'description' => 'IP address', 638 'type' => 'varchar', 639 'length' => 40, 640 'not null' => TRUE, 641 'default' => '', 642 ), 643 ), 644 'indexes' => array( 645 'blocked_ip' => array('ip'), 646 ), 647 'primary key' => array('iid'), 648 ); 649 650 $schema['cache'] = array( 651 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.', 652 'fields' => array( 653 'cid' => array( 654 'description' => 'Primary Key: Unique cache ID.', 655 'type' => 'varchar', 656 'length' => 255, 657 'not null' => TRUE, 658 'default' => '', 659 ), 660 'data' => array( 661 'description' => 'A collection of data to cache.', 662 'type' => 'blob', 663 'not null' => FALSE, 664 'size' => 'big', 665 ), 666 'expire' => array( 667 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.', 668 'type' => 'int', 669 'not null' => TRUE, 670 'default' => 0, 671 ), 672 'created' => array( 673 'description' => 'A Unix timestamp indicating when the cache entry was created.', 674 'type' => 'int', 675 'not null' => TRUE, 676 'default' => 0, 677 ), 678 'serialized' => array( 679 'description' => 'A flag to indicate whether content is serialized (1) or not (0).', 680 'type' => 'int', 681 'size' => 'small', 682 'not null' => TRUE, 683 'default' => 0, 684 ), 685 ), 686 'indexes' => array( 687 'expire' => array('expire'), 688 ), 689 'primary key' => array('cid'), 690 ); 691 $schema['cache_bootstrap'] = $schema['cache']; 692 $schema['cache_bootstrap']['description'] = 'Cache table for data required to bootstrap Drupal, may be routed to a shared memory cache.'; 693 $schema['cache_form'] = $schema['cache']; 694 $schema['cache_form']['description'] = 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.'; 695 $schema['cache_page'] = $schema['cache']; 696 $schema['cache_page']['description'] = 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.'; 697 $schema['cache_menu'] = $schema['cache']; 698 $schema['cache_menu']['description'] = 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.'; 699 $schema['cache_path'] = $schema['cache']; 700 $schema['cache_path']['description'] = 'Cache table for path alias lookup.'; 701 702 $schema['date_format_type'] = array( 703 'description' => 'Stores configured date format types.', 704 'fields' => array( 705 'type' => array( 706 'description' => 'The date format type, e.g. medium.', 707 'type' => 'varchar', 708 'length' => 64, 709 'not null' => TRUE, 710 ), 711 'title' => array( 712 'description' => 'The human readable name of the format type.', 713 'type' => 'varchar', 714 'length' => 255, 715 'not null' => TRUE, 716 ), 717 'locked' => array( 718 'description' => 'Whether or not this is a system provided format.', 719 'type' => 'int', 720 'size' => 'tiny', 721 'default' => 0, 722 'not null' => TRUE, 723 ), 724 ), 725 'primary key' => array('type'), 726 'indexes' => array( 727 'title' => array('title'), 728 ), 729 ); 730 731 // This table's name is plural as some versions of MySQL can't create a 732 // table named 'date_format'. 733 $schema['date_formats'] = array( 734 'description' => 'Stores configured date formats.', 735 'fields' => array( 736 'dfid' => array( 737 'description' => 'The date format identifier.', 738 'type' => 'serial', 739 'not null' => TRUE, 740 'unsigned' => TRUE, 741 ), 742 'format' => array( 743 'description' => 'The date format string.', 744 'type' => 'varchar', 745 'length' => 100, 746 'not null' => TRUE, 747 ), 748 'type' => array( 749 'description' => 'The date format type, e.g. medium.', 750 'type' => 'varchar', 751 'length' => 64, 752 'not null' => TRUE, 753 ), 754 'locked' => array( 755 'description' => 'Whether or not this format can be modified.', 756 'type' => 'int', 757 'size' => 'tiny', 758 'default' => 0, 759 'not null' => TRUE, 760 ), 761 ), 762 'primary key' => array('dfid'), 763 'unique keys' => array('formats' => array('format', 'type')), 764 ); 765 766 $schema['date_format_locale'] = array( 767 'description' => 'Stores configured date formats for each locale.', 768 'fields' => array( 769 'format' => array( 770 'description' => 'The date format string.', 771 'type' => 'varchar', 772 'length' => 100, 773 'not null' => TRUE, 774 ), 775 'type' => array( 776 'description' => 'The date format type, e.g. medium.', 777 'type' => 'varchar', 778 'length' => 64, 779 'not null' => TRUE, 780 ), 781 'language' => array( 782 'description' => 'A {languages}.language for this format to be used with.', 783 'type' => 'varchar', 784 'length' => 12, 785 'not null' => TRUE, 786 ), 787 ), 788 'primary key' => array('type', 'language'), 789 ); 790 791 $schema['file_managed'] = array( 792 'description' => 'Stores information for uploaded files.', 793 'fields' => array( 794 'fid' => array( 795 'description' => 'File ID.', 796 'type' => 'serial', 797 'unsigned' => TRUE, 798 'not null' => TRUE, 799 ), 800 'uid' => array( 801 'description' => 'The {users}.uid of the user who is associated with the file.', 802 'type' => 'int', 803 'unsigned' => TRUE, 804 'not null' => TRUE, 805 'default' => 0, 806 ), 807 'filename' => array( 808 'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.', 809 'type' => 'varchar', 810 'length' => 255, 811 'not null' => TRUE, 812 'default' => '', 813 ), 814 'uri' => array( 815 'description' => 'The URI to access the file (either local or remote).', 816 'type' => 'varchar', 817 'length' => 255, 818 'not null' => TRUE, 819 'default' => '', 820 'binary' => TRUE, 821 ), 822 'filemime' => array( 823 'description' => "The file's MIME type.", 824 'type' => 'varchar', 825 'length' => 255, 826 'not null' => TRUE, 827 'default' => '', 828 ), 829 'filesize' => array( 830 'description' => 'The size of the file in bytes.', 831 'type' => 'int', 832 'unsigned' => TRUE, 833 'not null' => TRUE, 834 'default' => 0, 835 ), 836 'status' => array( 837 'description' => 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.', 838 'type' => 'int', 839 'not null' => TRUE, 840 'default' => 0, 841 'size' => 'tiny', 842 ), 843 'timestamp' => array( 844 'description' => 'UNIX timestamp for when the file was added.', 845 'type' => 'int', 846 'unsigned' => TRUE, 847 'not null' => TRUE, 848 'default' => 0, 849 ), 850 ), 851 'indexes' => array( 852 'uid' => array('uid'), 853 'status' => array('status'), 854 'timestamp' => array('timestamp'), 855 ), 856 'unique keys' => array( 857 'uri' => array('uri'), 858 ), 859 'primary key' => array('fid'), 860 'foreign keys' => array( 861 'file_owner' => array( 862 'table' => 'users', 863 'columns' => array('uid' => 'uid'), 864 ), 865 ), 866 ); 867 868 $schema['file_usage'] = array( 869 'description' => 'Track where a file is used.', 870 'fields' => array( 871 'fid' => array( 872 'description' => 'File ID.', 873 'type' => 'int', 874 'unsigned' => TRUE, 875 'not null' => TRUE, 876 ), 877 'module' => array( 878 'description' => 'The name of the module that is using the file.', 879 'type' => 'varchar', 880 'length' => 255, 881 'not null' => TRUE, 882 'default' => '', 883 ), 884 'type' => array( 885 'description' => 'The name of the object type in which the file is used.', 886 'type' => 'varchar', 887 'length' => 64, 888 'not null' => TRUE, 889 'default' => '', 890 ), 891 'id' => array( 892 'description' => 'The primary key of the object using the file.', 893 'type' => 'int', 894 'unsigned' => TRUE, 895 'not null' => TRUE, 896 'default' => 0, 897 ), 898 'count' => array( 899 'description' => 'The number of times this file is used by this object.', 900 'type' => 'int', 901 'unsigned' => TRUE, 902 'not null' => TRUE, 903 'default' => 0, 904 ), 905 ), 906 'primary key' => array('fid', 'type', 'id', 'module'), 907 'indexes' => array( 908 'type_id' => array('type', 'id'), 909 'fid_count' => array('fid', 'count'), 910 'fid_module' => array('fid', 'module'), 911 ), 912 ); 913 914 $schema['flood'] = array( 915 'description' => 'Flood controls the threshold of events, such as the number of contact attempts.', 916 'fields' => array( 917 'fid' => array( 918 'description' => 'Unique flood event ID.', 919 'type' => 'serial', 920 'not null' => TRUE, 921 ), 922 'event' => array( 923 'description' => 'Name of event (e.g. contact).', 924 'type' => 'varchar', 925 'length' => 64, 926 'not null' => TRUE, 927 'default' => '', 928 ), 929 'identifier' => array( 930 'description' => 'Identifier of the visitor, such as an IP address or hostname.', 931 'type' => 'varchar', 932 'length' => 128, 933 'not null' => TRUE, 934 'default' => '', 935 ), 936 'timestamp' => array( 937 'description' => 'Timestamp of the event.', 938 'type' => 'int', 939 'not null' => TRUE, 940 'default' => 0, 941 ), 942 'expiration' => array( 943 'description' => 'Expiration timestamp. Expired events are purged on cron run.', 944 'type' => 'int', 945 'not null' => TRUE, 946 'default' => 0, 947 ), 948 ), 949 'primary key' => array('fid'), 950 'indexes' => array( 951 'allow' => array('event', 'identifier', 'timestamp'), 952 'purge' => array('expiration'), 953 ), 954 ); 955 956 $schema['menu_router'] = array( 957 'description' => 'Maps paths to various callbacks (access, page and title)', 958 'fields' => array( 959 'path' => array( 960 'description' => 'Primary Key: the Drupal path this entry describes', 961 'type' => 'varchar', 962 'length' => 255, 963 'not null' => TRUE, 964 'default' => '', 965 ), 966 'load_functions' => array( 967 'description' => 'A serialized array of function names (like node_load) to be called to load an object corresponding to a part of the current path.', 968 'type' => 'blob', 969 'not null' => TRUE, 970 ), 971 'to_arg_functions' => array( 972 'description' => 'A serialized array of function names (like user_uid_optional_to_arg) to be called to replace a part of the router path with another string.', 973 'type' => 'blob', 974 'not null' => TRUE, 975 ), 976 'access_callback' => array( 977 'description' => 'The callback which determines the access to this router path. Defaults to user_access.', 978 'type' => 'varchar', 979 'length' => 255, 980 'not null' => TRUE, 981 'default' => '', 982 ), 983 'access_arguments' => array( 984 'description' => 'A serialized array of arguments for the access callback.', 985 'type' => 'blob', 986 'not null' => FALSE, 987 ), 988 'page_callback' => array( 989 'description' => 'The name of the function that renders the page.', 990 'type' => 'varchar', 991 'length' => 255, 992 'not null' => TRUE, 993 'default' => '', 994 ), 995 'page_arguments' => array( 996 'description' => 'A serialized array of arguments for the page callback.', 997 'type' => 'blob', 998 'not null' => FALSE, 999 ), 1000 'delivery_callback' => array( 1001 'description' => 'The name of the function that sends the result of the page_callback function to the browser.', 1002 'type' => 'varchar', 1003 'length' => 255, 1004 'not null' => TRUE, 1005 'default' => '', 1006 ), 1007 'fit' => array( 1008 'description' => 'A numeric representation of how specific the path is.', 1009 'type' => 'int', 1010 'not null' => TRUE, 1011 'default' => 0, 1012 ), 1013 'number_parts' => array( 1014 'description' => 'Number of parts in this router path.', 1015 'type' => 'int', 1016 'not null' => TRUE, 1017 'default' => 0, 1018 'size' => 'small', 1019 ), 1020 'context' => array( 1021 'description' => 'Only for local tasks (tabs) - the context of a local task to control its placement.', 1022 'type' => 'int', 1023 'not null' => TRUE, 1024 'default' => 0, 1025 ), 1026 'tab_parent' => array( 1027 'description' => 'Only for local tasks (tabs) - the router path of the parent page (which may also be a local task).', 1028 'type' => 'varchar', 1029 'length' => 255, 1030 'not null' => TRUE, 1031 'default' => '', 1032 ), 1033 'tab_root' => array( 1034 'description' => 'Router path of the closest non-tab parent page. For pages that are not local tasks, this will be the same as the path.', 1035 'type' => 'varchar', 1036 'length' => 255, 1037 'not null' => TRUE, 1038 'default' => '', 1039 ), 1040 'title' => array( 1041 'description' => 'The title for the current page, or the title for the tab if this is a local task.', 1042 'type' => 'varchar', 1043 'length' => 255, 1044 'not null' => TRUE, 1045 'default' => '', 1046 ), 1047 'title_callback' => array( 1048 'description' => 'A function which will alter the title. Defaults to t()', 1049 'type' => 'varchar', 1050 'length' => 255, 1051 'not null' => TRUE, 1052 'default' => '', 1053 ), 1054 'title_arguments' => array( 1055 'description' => 'A serialized array of arguments for the title callback. If empty, the title will be used as the sole argument for the title callback.', 1056 'type' => 'varchar', 1057 'length' => 255, 1058 'not null' => TRUE, 1059 'default' => '', 1060 ), 1061 'theme_callback' => array( 1062 'description' => 'A function which returns the name of the theme that will be used to render this page. If left empty, the default theme will be used.', 1063 'type' => 'varchar', 1064 'length' => 255, 1065 'not null' => TRUE, 1066 'default' => '', 1067 ), 1068 'theme_arguments' => array( 1069 'description' => 'A serialized array of arguments for the theme callback.', 1070 'type' => 'varchar', 1071 'length' => 255, 1072 'not null' => TRUE, 1073 'default' => '', 1074 ), 1075 'type' => array( 1076 'description' => 'Numeric representation of the type of the menu item, like MENU_LOCAL_TASK.', 1077 'type' => 'int', 1078 'not null' => TRUE, 1079 'default' => 0, 1080 ), 1081 'description' => array( 1082 'description' => 'A description of this item.', 1083 'type' => 'text', 1084 'not null' => TRUE, 1085 ), 1086 'position' => array( 1087 'description' => 'The position of the block (left or right) on the system administration page for this item.', 1088 'type' => 'varchar', 1089 'length' => 255, 1090 'not null' => TRUE, 1091 'default' => '', 1092 ), 1093 'weight' => array( 1094 'description' => 'Weight of the element. Lighter weights are higher up, heavier weights go down.', 1095 'type' => 'int', 1096 'not null' => TRUE, 1097 'default' => 0, 1098 ), 1099 'include_file' => array( 1100 'description' => 'The file to include for this element, usually the page callback function lives in this file.', 1101 'type' => 'text', 1102 'size' => 'medium', 1103 ), 1104 ), 1105 'indexes' => array( 1106 'fit' => array('fit'), 1107 'tab_parent' => array(array('tab_parent', 64), 'weight', 'title'), 1108 'tab_root_weight_title' => array(array('tab_root', 64), 'weight', 'title'), 1109 ), 1110 'primary key' => array('path'), 1111 ); 1112 1113 $schema['menu_links'] = array( 1114 'description' => 'Contains the individual links within a menu.', 1115 'fields' => array( 1116 'menu_name' => array( 1117 'description' => "The menu name. All links with the same menu name (such as 'navigation') are part of the same menu.", 1118 'type' => 'varchar', 1119 'length' => 32, 1120 'not null' => TRUE, 1121 'default' => '', 1122 ), 1123 'mlid' => array( 1124 'description' => 'The menu link ID (mlid) is the integer primary key.', 1125 'type' => 'serial', 1126 'unsigned' => TRUE, 1127 'not null' => TRUE, 1128 ), 1129 'plid' => array( 1130 'description' => 'The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.', 1131 'type' => 'int', 1132 'unsigned' => TRUE, 1133 'not null' => TRUE, 1134 'default' => 0, 1135 ), 1136 'link_path' => array( 1137 'description' => 'The Drupal path or external path this link points to.', 1138 'type' => 'varchar', 1139 'length' => 255, 1140 'not null' => TRUE, 1141 'default' => '', 1142 ), 1143 'router_path' => array( 1144 'description' => 'For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.', 1145 'type' => 'varchar', 1146 'length' => 255, 1147 'not null' => TRUE, 1148 'default' => '', 1149 ), 1150 'link_title' => array( 1151 'description' => 'The text displayed for the link, which may be modified by a title callback stored in {menu_router}.', 1152 'type' => 'varchar', 1153 'length' => 255, 1154 'not null' => TRUE, 1155 'default' => '', 1156 'translatable' => TRUE, 1157 ), 1158 'options' => array( 1159 'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.', 1160 'type' => 'blob', 1161 'not null' => FALSE, 1162 'translatable' => TRUE, 1163 ), 1164 'module' => array( 1165 'description' => 'The name of the module that generated this link.', 1166 'type' => 'varchar', 1167 'length' => 255, 1168 'not null' => TRUE, 1169 'default' => 'system', 1170 ), 1171 'hidden' => array( 1172 'description' => 'A flag for whether the link should be rendered in menus. (1 = a disabled menu item that may be shown on admin screens, -1 = a menu callback, 0 = a normal, visible link)', 1173 'type' => 'int', 1174 'not null' => TRUE, 1175 'default' => 0, 1176 'size' => 'small', 1177 ), 1178 'external' => array( 1179 'description' => 'A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).', 1180 'type' => 'int', 1181 'not null' => TRUE, 1182 'default' => 0, 1183 'size' => 'small', 1184 ), 1185 'has_children' => array( 1186 'description' => 'Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).', 1187 'type' => 'int', 1188 'not null' => TRUE, 1189 'default' => 0, 1190 'size' => 'small', 1191 ), 1192 'expanded' => array( 1193 'description' => 'Flag for whether this link should be rendered as expanded in menus - expanded links always have their child links displayed, instead of only when the link is in the active trail (1 = expanded, 0 = not expanded)', 1194 'type' => 'int', 1195 'not null' => TRUE, 1196 'default' => 0, 1197 'size' => 'small', 1198 ), 1199 'weight' => array( 1200 'description' => 'Link weight among links in the same menu at the same depth.', 1201 'type' => 'int', 1202 'not null' => TRUE, 1203 'default' => 0, 1204 ), 1205 'depth' => array( 1206 'description' => 'The depth relative to the top level. A link with plid == 0 will have depth == 1.', 1207 'type' => 'int', 1208 'not null' => TRUE, 1209 'default' => 0, 1210 'size' => 'small', 1211 ), 1212 'customized' => array( 1213 'description' => 'A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).', 1214 'type' => 'int', 1215 'not null' => TRUE, 1216 'default' => 0, 1217 'size' => 'small', 1218 ), 1219 'p1' => array( 1220 'description' => 'The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the plid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.', 1221 'type' => 'int', 1222 'unsigned' => TRUE, 1223 'not null' => TRUE, 1224 'default' => 0, 1225 ), 1226 'p2' => array( 1227 'description' => 'The second mlid in the materialized path. See p1.', 1228 'type' => 'int', 1229 'unsigned' => TRUE, 1230 'not null' => TRUE, 1231 'default' => 0, 1232 ), 1233 'p3' => array( 1234 'description' => 'The third mlid in the materialized path. See p1.', 1235 'type' => 'int', 1236 'unsigned' => TRUE, 1237 'not null' => TRUE, 1238 'default' => 0, 1239 ), 1240 'p4' => array( 1241 'description' => 'The fourth mlid in the materialized path. See p1.', 1242 'type' => 'int', 1243 'unsigned' => TRUE, 1244 'not null' => TRUE, 1245 'default' => 0, 1246 ), 1247 'p5' => array( 1248 'description' => 'The fifth mlid in the materialized path. See p1.', 1249 'type' => 'int', 1250 'unsigned' => TRUE, 1251 'not null' => TRUE, 1252 'default' => 0, 1253 ), 1254 'p6' => array( 1255 'description' => 'The sixth mlid in the materialized path. See p1.', 1256 'type' => 'int', 1257 'unsigned' => TRUE, 1258 'not null' => TRUE, 1259 'default' => 0, 1260 ), 1261 'p7' => array( 1262 'description' => 'The seventh mlid in the materialized path. See p1.', 1263 'type' => 'int', 1264 'unsigned' => TRUE, 1265 'not null' => TRUE, 1266 'default' => 0, 1267 ), 1268 'p8' => array( 1269 'description' => 'The eighth mlid in the materialized path. See p1.', 1270 'type' => 'int', 1271 'unsigned' => TRUE, 1272 'not null' => TRUE, 1273 'default' => 0, 1274 ), 1275 'p9' => array( 1276 'description' => 'The ninth mlid in the materialized path. See p1.', 1277 'type' => 'int', 1278 'unsigned' => TRUE, 1279 'not null' => TRUE, 1280 'default' => 0, 1281 ), 1282 'updated' => array( 1283 'description' => 'Flag that indicates that this link was generated during the update from Drupal 5.', 1284 'type' => 'int', 1285 'not null' => TRUE, 1286 'default' => 0, 1287 'size' => 'small', 1288 ), 1289 ), 1290 'indexes' => array( 1291 'path_menu' => array(array('link_path', 128), 'menu_name'), 1292 'menu_plid_expand_child' => array('menu_name', 'plid', 'expanded', 'has_children'), 1293 'menu_parents' => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'), 1294 'router_path' => array(array('router_path', 128)), 1295 ), 1296 'primary key' => array('mlid'), 1297 ); 1298 1299 $schema['queue'] = array( 1300 'description' => 'Stores items in queues.', 1301 'fields' => array( 1302 'item_id' => array( 1303 'type' => 'serial', 1304 'unsigned' => TRUE, 1305 'not null' => TRUE, 1306 'description' => 'Primary Key: Unique item ID.', 1307 ), 1308 'name' => array( 1309 'type' => 'varchar', 1310 'length' => 255, 1311 'not null' => TRUE, 1312 'default' => '', 1313 'description' => 'The queue name.', 1314 ), 1315 'data' => array( 1316 'type' => 'blob', 1317 'not null' => FALSE, 1318 'size' => 'big', 1319 'serialize' => TRUE, 1320 'description' => 'The arbitrary data for the item.', 1321 ), 1322 'expire' => array( 1323 'type' => 'int', 1324 'not null' => TRUE, 1325 'default' => 0, 1326 'description' => 'Timestamp when the claim lease expires on the item.', 1327 ), 1328 'created' => array( 1329 'type' => 'int', 1330 'not null' => TRUE, 1331 'default' => 0, 1332 'description' => 'Timestamp when the item was created.', 1333 ), 1334 ), 1335 'primary key' => array('item_id'), 1336 'indexes' => array( 1337 'name_created' => array('name', 'created'), 1338 'expire' => array('expire'), 1339 ), 1340 ); 1341 1342 $schema['registry'] = array( 1343 'description' => "Each record is a function, class, or interface name and the file it is in.", 1344 'fields' => array( 1345 'name' => array( 1346 'description' => 'The name of the function, class, or interface.', 1347 'type' => 'varchar', 1348 'length' => 255, 1349 'not null' => TRUE, 1350 'default' => '', 1351 ), 1352 'type' => array( 1353 'description' => 'Either function or class or interface.', 1354 'type' => 'varchar', 1355 'length' => 9, 1356 'not null' => TRUE, 1357 'default' => '', 1358 ), 1359 'filename' => array( 1360 'description' => 'Name of the file.', 1361 'type' => 'varchar', 1362 'length' => 255, 1363 'not null' => TRUE, 1364 ), 1365 'module' => array( 1366 'description' => 'Name of the module the file belongs to.', 1367 'type' => 'varchar', 1368 'length' => 255, 1369 'not null' => TRUE, 1370 'default' => '' 1371 ), 1372 'weight' => array( 1373 'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.", 1374 'type' => 'int', 1375 'not null' => TRUE, 1376 'default' => 0, 1377 ), 1378 ), 1379 'primary key' => array('name', 'type'), 1380 'indexes' => array( 1381 'hook' => array('type', 'weight', 'module'), 1382 ), 1383 ); 1384 1385 $schema['registry_file'] = array( 1386 'description' => "Files parsed to build the registry.", 1387 'fields' => array( 1388 'filename' => array( 1389 'description' => 'Path to the file.', 1390 'type' => 'varchar', 1391 'length' => 255, 1392 'not null' => TRUE, 1393 ), 1394 'hash' => array( 1395 'description' => "sha-256 hash of the file's contents when last parsed.", 1396 'type' => 'varchar', 1397 'length' => 64, 1398 'not null' => TRUE, 1399 ), 1400 ), 1401 'primary key' => array('filename'), 1402 ); 1403 1404 $schema['semaphore'] = array( 1405 'description' => 'Table for holding semaphores, locks, flags, etc. that cannot be stored as Drupal variables since they must not be cached.', 1406 'fields' => array( 1407 'name' => array( 1408 'description' => 'Primary Key: Unique name.', 1409 'type' => 'varchar', 1410 'length' => 255, 1411 'not null' => TRUE, 1412 'default' => '' 1413 ), 1414 'value' => array( 1415 'description' => 'A value for the semaphore.', 1416 'type' => 'varchar', 1417 'length' => 255, 1418 'not null' => TRUE, 1419 'default' => '' 1420 ), 1421 'expire' => array( 1422 'description' => 'A Unix timestamp with microseconds indicating when the semaphore should expire.', 1423 'type' => 'float', 1424 'size' => 'big', 1425 'not null' => TRUE 1426 ), 1427 ), 1428 'indexes' => array( 1429 'value' => array('value'), 1430 'expire' => array('expire'), 1431 ), 1432 'primary key' => array('name'), 1433 ); 1434 1435 $schema['sequences'] = array( 1436 'description' => 'Stores IDs.', 1437 'fields' => array( 1438 'value' => array( 1439 'description' => 'The value of the sequence.', 1440 'type' => 'serial', 1441 'unsigned' => TRUE, 1442 'not null' => TRUE, 1443 ), 1444 ), 1445 'primary key' => array('value'), 1446 ); 1447 1448 $schema['sessions'] = array( 1449 'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.", 1450 'fields' => array( 1451 'uid' => array( 1452 'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.', 1453 'type' => 'int', 1454 'unsigned' => TRUE, 1455 'not null' => TRUE, 1456 ), 1457 'sid' => array( 1458 'description' => "A session ID. The value is generated by Drupal's session handlers.", 1459 'type' => 'varchar', 1460 'length' => 128, 1461 'not null' => TRUE, 1462 ), 1463 'ssid' => array( 1464 'description' => "Secure session ID. The value is generated by Drupal's session handlers.", 1465 'type' => 'varchar', 1466 'length' => 128, 1467 'not null' => TRUE, 1468 'default' => '', 1469 ), 1470 'hostname' => array( 1471 'description' => 'The IP address that last used this session ID (sid).', 1472 'type' => 'varchar', 1473 'length' => 128, 1474 'not null' => TRUE, 1475 'default' => '', 1476 ), 1477 'timestamp' => array( 1478 'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.', 1479 'type' => 'int', 1480 'not null' => TRUE, 1481 'default' => 0, 1482 ), 1483 'cache' => array( 1484 'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get().", 1485 'type' => 'int', 1486 'not null' => TRUE, 1487 'default' => 0, 1488 ), 1489 'session' => array( 1490 'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.', 1491 'type' => 'blob', 1492 'not null' => FALSE, 1493 'size' => 'big', 1494 ), 1495 ), 1496 'primary key' => array( 1497 'sid', 1498 'ssid', 1499 ), 1500 'indexes' => array( 1501 'timestamp' => array('timestamp'), 1502 'uid' => array('uid'), 1503 'ssid' => array('ssid'), 1504 ), 1505 'foreign keys' => array( 1506 'session_user' => array( 1507 'table' => 'users', 1508 'columns' => array('uid' => 'uid'), 1509 ), 1510 ), 1511 ); 1512 1513 $schema['system'] = array( 1514 'description' => "A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system.", 1515 'fields' => array( 1516 'filename' => array( 1517 'description' => 'The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.', 1518 'type' => 'varchar', 1519 'length' => 255, 1520 'not null' => TRUE, 1521 'default' => '', 1522 ), 1523 'name' => array( 1524 'description' => 'The name of the item; e.g. node.', 1525 'type' => 'varchar', 1526 'length' => 255, 1527 'not null' => TRUE, 1528 'default' => '', 1529 ), 1530 'type' => array( 1531 'description' => 'The type of the item, either module, theme, or theme_engine.', 1532 'type' => 'varchar', 1533 'length' => 12, 1534 'not null' => TRUE, 1535 'default' => '', 1536 ), 1537 'owner' => array( 1538 'description' => "A theme's 'parent' . Can be either a theme or an engine.", 1539 'type' => 'varchar', 1540 'length' => 255, 1541 'not null' => TRUE, 1542 'default' => '', 1543 ), 1544 'status' => array( 1545 'description' => 'Boolean indicating whether or not this item is enabled.', 1546 'type' => 'int', 1547 'not null' => TRUE, 1548 'default' => 0, 1549 ), 1550 'bootstrap' => array( 1551 'description' => "Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted).", 1552 'type' => 'int', 1553 'not null' => TRUE, 1554 'default' => 0, 1555 ), 1556 'schema_version' => array( 1557 'description' => "The module's database schema version number. -1 if the module is not installed (its tables do not exist); 0 or the largest N of the module's hook_update_N() function that has either been run or existed when the module was first installed.", 1558 'type' => 'int', 1559 'not null' => TRUE, 1560 'default' => -1, 1561 'size' => 'small', 1562 ), 1563 'weight' => array( 1564 'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.", 1565 'type' => 'int', 1566 'not null' => TRUE, 1567 'default' => 0, 1568 ), 1569 'info' => array( 1570 'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.", 1571 'type' => 'blob', 1572 'not null' => FALSE, 1573 ), 1574 ), 1575 'primary key' => array('filename'), 1576 'indexes' => array( 1577 'system_list' => array('status', 'bootstrap', 'type', 'weight', 'name'), 1578 'type_name' => array('type', 'name'), 1579 ), 1580 ); 1581 1582 $schema['url_alias'] = array( 1583 'description' => 'A list of URL aliases for Drupal paths; a user may visit either the source or destination path.', 1584 'fields' => array( 1585 'pid' => array( 1586 'description' => 'A unique path alias identifier.', 1587 'type' => 'serial', 1588 'unsigned' => TRUE, 1589 'not null' => TRUE, 1590 ), 1591 'source' => array( 1592 'description' => 'The Drupal path this alias is for; e.g. node/12.', 1593 'type' => 'varchar', 1594 'length' => 255, 1595 'not null' => TRUE, 1596 'default' => '', 1597 ), 1598 'alias' => array( 1599 'description' => 'The alias for this path; e.g. title-of-the-story.', 1600 'type' => 'varchar', 1601 'length' => 255, 1602 'not null' => TRUE, 1603 'default' => '', 1604 ), 1605 'language' => array( 1606 'description' => "The language this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.", 1607 'type' => 'varchar', 1608 'length' => 12, 1609 'not null' => TRUE, 1610 'default' => '', 1611 ), 1612 ), 1613 'primary key' => array('pid'), 1614 'indexes' => array( 1615 'alias_language_pid' => array('alias', 'language', 'pid'), 1616 'source_language_pid' => array('source', 'language', 'pid'), 1617 ), 1618 ); 1619 1620 return $schema; 1621 } 1622 1623 /** 1624 * The cache schema corresponding to system_update_7054. 1625 * 1626 * Drupal 7 adds several new cache tables. Since they all have identical schema 1627 * this helper function allows them to re-use the same definition, without 1628 * relying on system_schema(), which may change with future updates. 1629 */ 1630 function system_schema_cache_7054() { 1631 return array( 1632 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.', 1633 'fields' => array( 1634 'cid' => array( 1635 'description' => 'Primary Key: Unique cache ID.', 1636 'type' => 'varchar', 1637 'length' => 255, 1638 'not null' => TRUE, 1639 'default' => '', 1640 ), 1641 'data' => array( 1642 'description' => 'A collection of data to cache.', 1643 'type' => 'blob', 1644 'not null' => FALSE, 1645 'size' => 'big', 1646 ), 1647 'expire' => array( 1648 'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.', 1649 'type' => 'int', 1650 'not null' => TRUE, 1651 'default' => 0, 1652 ), 1653 'created' => array( 1654 'description' => 'A Unix timestamp indicating when the cache entry was created.', 1655 'type' => 'int', 1656 'not null' => TRUE, 1657 'default' => 0, 1658 ), 1659 'serialized' => array( 1660 'description' => 'A flag to indicate whether content is serialized (1) or not (0).', 1661 'type' => 'int', 1662 'size' => 'small', 1663 'not null' => TRUE, 1664 'default' => 0, 1665 ), 1666 ), 1667 'indexes' => array( 1668 'expire' => array('expire'), 1669 ), 1670 'primary key' => array('cid'), 1671 ); 1672 } 1673 1674 1675 // Updates for core. 1676 1677 function system_update_last_removed() { 1678 return 6055; 1679 } 1680 1681 /** 1682 * Implements hook_update_dependencies(). 1683 */ 1684 function system_update_dependencies() { 1685 // system_update_7053() queries the {block} table, so it must run after 1686 // block_update_7002(), which creates that table. 1687 $dependencies['system'][7053] = array( 1688 'block' => 7002, 1689 ); 1690 1691 // system_update_7061() queries the {node_revision} table, so it must run 1692 // after node_update_7001(), which renames the {node_revisions} table. 1693 $dependencies['system'][7061] = array( 1694 'node' => 7001, 1695 ); 1696 1697 // system_update_7067() migrates role permissions and therefore must run 1698 // after the {role} and {role_permission} tables are properly set up, which 1699 // happens in user_update_7007(). 1700 $dependencies['system'][7067] = array( 1701 'user' => 7007, 1702 ); 1703 1704 return $dependencies; 1705 } 1706 1707 /** 1708 * @defgroup updates-6.x-to-7.x Updates from 6.x to 7.x 1709 * @{ 1710 * Update functions from 6.x to 7.x. 1711 */ 1712 1713 /** 1714 * Rename blog and forum permissions to be consistent with other content types. 1715 */ 1716 function system_update_7000() { 1717 $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid"); 1718 foreach ($result as $role) { 1719 $renamed_permission = $role->perm; 1720 $renamed_permission = preg_replace('/(?<=^|,\ )create\ blog\ entries(?=,|$)/', 'create blog content', $renamed_permission); 1721 $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ blog\ entries(?=,|$)/', 'edit own blog content', $renamed_permission); 1722 $renamed_permission = preg_replace('/(?<=^|,\ )edit\ any\ blog\ entry(?=,|$)/', 'edit any blog content', $renamed_permission); 1723 $renamed_permission = preg_replace('/(?<=^|,\ )delete\ own\ blog\ entries(?=,|$)/', 'delete own blog content', $renamed_permission); 1724 $renamed_permission = preg_replace('/(?<=^|,\ )delete\ any\ blog\ entry(?=,|$)/', 'delete any blog content', $renamed_permission); 1725 1726 $renamed_permission = preg_replace('/(?<=^|,\ )create\ forum\ topics(?=,|$)/', 'create forum content', $renamed_permission); 1727 $renamed_permission = preg_replace('/(?<=^|,\ )delete\ any\ forum\ topic(?=,|$)/', 'delete any forum content', $renamed_permission); 1728 $renamed_permission = preg_replace('/(?<=^|,\ )delete\ own\ forum\ topics(?=,|$)/', 'delete own forum content', $renamed_permission); 1729 $renamed_permission = preg_replace('/(?<=^|,\ )edit\ any\ forum\ topic(?=,|$)/', 'edit any forum content', $renamed_permission); 1730 $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ forum\ topics(?=,|$)/', 'edit own forum content', $renamed_permission); 1731 1732 if ($renamed_permission != $role->perm) { 1733 db_update('permission') 1734 ->fields(array('perm' => $renamed_permission)) 1735 ->condition('rid', $role->rid) 1736 ->execute(); 1737 } 1738 } 1739 } 1740 1741 /** 1742 * Generate a cron key and save it in the variables table. 1743 */ 1744 function system_update_7001() { 1745 variable_set('cron_key', drupal_hash_base64(drupal_random_bytes(55))); 1746 } 1747 1748 /** 1749 * Add a table to store blocked IP addresses. 1750 */ 1751 function system_update_7002() { 1752 $schema['blocked_ips'] = array( 1753 'description' => 'Stores blocked IP addresses.', 1754 'fields' => array( 1755 'iid' => array( 1756 'description' => 'Primary Key: unique ID for IP addresses.', 1757 'type' => 'serial', 1758 'unsigned' => TRUE, 1759 'not null' => TRUE, 1760 ), 1761 'ip' => array( 1762 'description' => 'IP address', 1763 'type' => 'varchar', 1764 'length' => 32, 1765 'not null' => TRUE, 1766 'default' => '', 1767 ), 1768 ), 1769 'indexes' => array( 1770 'blocked_ip' => array('ip'), 1771 ), 1772 'primary key' => array('iid'), 1773 ); 1774 1775 db_create_table('blocked_ips', $schema['blocked_ips']); 1776 } 1777 1778 /** 1779 * Update {blocked_ips} with valid IP addresses from {access}. 1780 */ 1781 function system_update_7003() { 1782 $messages = array(); 1783 $type = 'host'; 1784 $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array( 1785 ':status' => 0, 1786 ':type' => $type, 1787 )); 1788 foreach ($result as $blocked) { 1789 if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) !== FALSE) { 1790 db_insert('blocked_ips') 1791 ->fields(array('ip' => $blocked->mask)) 1792 ->execute(); 1793 } 1794 else { 1795 $invalid_host = check_plain($blocked->mask); 1796 $messages[] = t('The host !host is no longer blocked because it is not a valid IP address.', array('!host' => $invalid_host )); 1797 } 1798 } 1799 if (isset($invalid_host)) { 1800 drupal_set_message('Drupal no longer supports wildcard IP address blocking. Visitors whose IP addresses match ranges you have previously set using <em>access rules</em> will no longer be blocked from your site when you put the site online. See the <a href="http://drupal.org/node/24302">IP address and referrer blocking Handbook page</a> for alternative methods.', 'warning'); 1801 } 1802 // Make sure not to block any IP addresses that were specifically allowed by access rules. 1803 if (!empty($result)) { 1804 $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array( 1805 ':status' => 1, 1806 ':type' => $type, 1807 )); 1808 $or = db_condition('or'); 1809 foreach ($result as $allowed) { 1810 $or->condition('ip', $allowed->mask, 'LIKE'); 1811 } 1812 if (count($or)) { 1813 db_delete('blocked_ips') 1814 ->condition($or) 1815 ->execute(); 1816 } 1817 } 1818 } 1819 1820 /** 1821 * Remove hardcoded numeric deltas from all blocks in core. 1822 */ 1823 function system_update_7004(&$sandbox) { 1824 // Get an array of the renamed block deltas, organized by module. 1825 $renamed_deltas = array( 1826 'blog' => array('0' => 'recent'), 1827 'book' => array('0' => 'navigation'), 1828 'comment' => array('0' => 'recent'), 1829 'forum' => array( 1830 '0' => 'active', 1831 '1' => 'new', 1832 ), 1833 'locale' => array('0' => LANGUAGE_TYPE_INTERFACE), 1834 'node' => array('0' => 'syndicate'), 1835 'poll' => array('0' => 'recent'), 1836 'profile' => array('0' => 'author-information'), 1837 'search' => array('0' => 'form'), 1838 'statistics' => array('0' => 'popular'), 1839 'system' => array('0' => 'powered-by'), 1840 'user' => array( 1841 '0' => 'login', 1842 '1' => 'navigation', 1843 '2' => 'new', 1844 '3' => 'online', 1845 ), 1846 ); 1847 1848 $moved_deltas = array( 1849 'user' => array('navigation' => 'system'), 1850 ); 1851 1852 // Only run this the first time through the batch update. 1853 if (!isset($sandbox['progress'])) { 1854 // Rename forum module's block variables. 1855 $forum_block_num_0 = variable_get('forum_block_num_0'); 1856 if (isset($forum_block_num_0)) { 1857 variable_set('forum_block_num_active', $forum_block_num_0); 1858 variable_del('forum_block_num_0'); 1859 } 1860 $forum_block_num_1 = variable_get('forum_block_num_1'); 1861 if (isset($forum_block_num_1)) { 1862 variable_set('forum_block_num_new', $forum_block_num_1); 1863 variable_del('forum_block_num_1'); 1864 } 1865 } 1866 1867 update_fix_d7_block_deltas($sandbox, $renamed_deltas, $moved_deltas); 1868 1869 } 1870 1871 /** 1872 * Remove throttle columns and variables. 1873 */ 1874 function system_update_7005() { 1875 db_drop_field('blocks', 'throttle'); 1876 db_drop_field('system', 'throttle'); 1877 variable_del('throttle_user'); 1878 variable_del('throttle_anonymous'); 1879 variable_del('throttle_level'); 1880 variable_del('throttle_probability_limiter'); 1881 } 1882 1883 /** 1884 * Convert to new method of storing permissions. 1885 */ 1886 function system_update_7007() { 1887 // Copy the permissions from the old {permission} table to the new {role_permission} table. 1888 $messages = array(); 1889 $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC"); 1890 $query = db_insert('role_permission')->fields(array('rid', 'permission')); 1891 foreach ($result as $role) { 1892 foreach (explode(', ', $role->perm) as $perm) { 1893 $query->values(array( 1894 'rid' => $role->rid, 1895 'permission' => $perm, 1896 )); 1897 } 1898 $messages[] = t('Inserted into {role_permission} the permissions for role ID !id', array('!id' => $role->rid)); 1899 } 1900 $query->execute(); 1901 db_drop_table('permission'); 1902 1903 return implode(', ', $messages); 1904 } 1905 1906 /** 1907 * Rename the variable for primary links. 1908 */ 1909 function system_update_7009() { 1910 $current_primary = variable_get('menu_primary_links_source'); 1911 if (isset($current_primary)) { 1912 variable_set('menu_main_links_source', $current_primary); 1913 variable_del('menu_primary_links_source'); 1914 } 1915 } 1916 1917 /** 1918 * Split the 'bypass node access' permission from 'administer nodes'. 1919 */ 1920 function system_update_7011() { 1921 // Get existing roles that can 'administer nodes'. 1922 $rids = array(); 1923 $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer nodes'))->fetchCol(); 1924 // None found. 1925 if (empty($rids)) { 1926 return; 1927 } 1928 $insert = db_insert('role_permission')->fields(array('rid', 'permission')); 1929 foreach ($rids as $rid) { 1930 $insert->values(array( 1931 'rid' => $rid, 1932 'permission' => 'bypass node access', 1933 )); 1934 } 1935 $insert->execute(); 1936 } 1937 1938 /** 1939 * Convert default time zone offset to default time zone name. 1940 */ 1941 function system_update_7013() { 1942 $timezone = NULL; 1943 $timezones = system_time_zones(); 1944 // If the contributed Date module set a default time zone name, use this 1945 // setting as the default time zone. 1946 if (($timezone_name = variable_get('date_default_timezone_name')) && isset($timezones[$timezone_name])) { 1947 $timezone = $timezone_name; 1948 } 1949 // If the contributed Event module has set a default site time zone, look up 1950 // the time zone name and use it as the default time zone. 1951 if (!$timezone && ($timezone_id = variable_get('date_default_timezone_id', 0))) { 1952 try { 1953 $timezone_name = db_query('SELECT name FROM {event_timezones} WHERE timezone = :timezone_id', array(':timezone_id' => $timezone_id))->fetchField(); 1954 if (($timezone_name = str_replace(' ', '_', $timezone_name)) && isset($timezones[$timezone_name])) { 1955 $timezone = $timezone_name; 1956 } 1957 } 1958 catch (PDOException $e) { 1959 // Ignore error if event_timezones table does not exist or unexpected 1960 // schema found. 1961 } 1962 } 1963 1964 // Check to see if timezone was overriden in update_prepare_d7_bootstrap(). 1965 $offset = variable_get('date_temporary_timezone'); 1966 // If not, use the default. 1967 if (!isset($offset)) { 1968 $offset = variable_get('date_default_timezone', 0); 1969 } 1970 1971 // If the previous default time zone was a non-zero offset, guess the site's 1972 // intended time zone based on that offset and the server's daylight saving 1973 // time status. 1974 if (!$timezone && $offset) { 1975 $timezone_name = timezone_name_from_abbr('', intval($offset), date('I')); 1976 if ($timezone_name && isset($timezones[$timezone_name])) { 1977 $timezone = $timezone_name; 1978 } 1979 } 1980 // Otherwise, the default time zone offset was zero, which is UTC. 1981 if (!$timezone) { 1982 $timezone = 'UTC'; 1983 } 1984 variable_set('date_default_timezone', $timezone); 1985 drupal_set_message('The default time zone has been set to <em>' . check_plain($timezone) . '</em>. Check the ' . l('date and time configuration page', 'admin/config/regional/settings') . ' to configure it correctly.', 'warning'); 1986 // Remove temporary override. 1987 variable_del('date_temporary_timezone'); 1988 } 1989 1990 /** 1991 * Change the user logout path. 1992 */ 1993 function system_update_7015() { 1994 db_update('menu_links') 1995 ->fields(array('link_path' => 'user/logout')) 1996 ->condition('link_path', 'logout') 1997 ->execute(); 1998 db_update('menu_links') 1999 ->fields(array('router_path' => 'user/logout')) 2000 ->condition('router_path', 'logout') 2001 ->execute(); 2002 2003 db_update('menu_links') 2004 ->fields(array( 2005 'menu_name' => 'user-menu', 2006 'plid' => 0, 2007 )) 2008 ->condition(db_or() 2009 ->condition('link_path', 'user/logout') 2010 ->condition('router_path', 'user/logout') 2011 ) 2012 ->condition('module', 'system') 2013 ->condition('customized', 0) 2014 ->execute(); 2015 } 2016 2017 /** 2018 * Remove custom datatype *_unsigned in PostgreSQL. 2019 */ 2020 function system_update_7016() { 2021 // Only run these queries if the driver used is pgsql. 2022 if (db_driver() == 'pgsql') { 2023 $result = db_query("SELECT c.relname AS table, a.attname AS field, 2024 pg_catalog.format_type(a.atttypid, a.atttypmod) AS type 2025 FROM pg_catalog.pg_attribute a 2026 LEFT JOIN pg_class c ON (c.oid = a.attrelid) 2027 WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relkind = 'r' 2028 AND pg_catalog.format_type(a.atttypid, a.atttypmod) LIKE '%unsigned%'"); 2029 foreach ($result as $row) { 2030 switch ($row->type) { 2031 case 'smallint_unsigned': 2032 $datatype = 'int'; 2033 break; 2034 case 'int_unsigned': 2035 case 'bigint_unsigned': 2036 default: 2037 $datatype = 'bigint'; 2038 break; 2039 } 2040 db_query('ALTER TABLE ' . $row->table . ' ALTER COLUMN "' . $row->field . '" TYPE ' . $datatype); 2041 db_query('ALTER TABLE ' . $row->table . ' ADD CHECK ("' . $row->field . '" >= 0)'); 2042 } 2043 db_query('DROP DOMAIN IF EXISTS smallint_unsigned'); 2044 db_query('DROP DOMAIN IF EXISTS int_unsigned'); 2045 db_query('DROP DOMAIN IF EXISTS bigint_unsigned'); 2046 } 2047 } 2048 2049 /** 2050 * Change the theme setting 'toggle_node_info' into a per content type variable. 2051 */ 2052 function system_update_7017() { 2053 // Get the global theme settings. 2054 $settings = variable_get('theme_settings', array()); 2055 // Get the settings of the default theme. 2056 $settings = array_merge($settings, variable_get('theme_' . variable_get('theme_default', 'garland') . '_settings', array())); 2057 2058 $types = _update_7000_node_get_types(); 2059 foreach ($types as $type) { 2060 if (isset($settings['toggle_node_info_' . $type->type])) { 2061 variable_set('node_submitted_' . $type->type, $settings['toggle_node_info_' . $type->type]); 2062 } 2063 } 2064 2065 // Unset deprecated 'toggle_node_info' theme settings. 2066 $theme_settings = variable_get('theme_settings', array()); 2067 foreach ($theme_settings as $setting => $value) { 2068 if (substr($setting, 0, 16) == 'toggle_node_info') { 2069 unset($theme_settings[$setting]); 2070 } 2071 } 2072 variable_set('theme_settings', $theme_settings); 2073 } 2074 2075 /** 2076 * Shorten the {system}.type column and modify indexes. 2077 */ 2078 function system_update_7018() { 2079 db_drop_index('system', 'modules'); 2080 db_drop_index('system', 'type_name'); 2081 db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '')); 2082 db_add_index('system', 'type_name', array('type', 'name')); 2083 } 2084 2085 /** 2086 * Enable field and field_ui modules. 2087 */ 2088 function system_update_7020() { 2089 $module_list = array('field_sql_storage', 'field', 'field_ui'); 2090 module_enable($module_list, FALSE); 2091 } 2092 2093 /** 2094 * Change the PHP for settings permission. 2095 */ 2096 function system_update_7021() { 2097 db_update('role_permission') 2098 ->fields(array('permission' => 'use PHP for settings')) 2099 ->condition('permission', 'use PHP for block visibility') 2100 ->execute(); 2101 } 2102 2103 /** 2104 * Enable field type modules. 2105 */ 2106 function system_update_7027() { 2107 $module_list = array('text', 'number', 'list', 'options'); 2108 module_enable($module_list, FALSE); 2109 } 2110 2111 /** 2112 * Add new 'view own unpublished content' permission for authenticated users. 2113 * Preserves legacy behavior from Drupal 6.x. 2114 */ 2115 function system_update_7029() { 2116 db_insert('role_permission') 2117 ->fields(array( 2118 'rid' => DRUPAL_AUTHENTICATED_RID, 2119 'permission' => 'view own unpublished content', 2120 )) 2121 ->execute(); 2122 } 2123 2124 /** 2125 * Alter field hostname to identifier in the {flood} table. 2126 */ 2127 function system_update_7032() { 2128 db_drop_index('flood', 'allow'); 2129 db_change_field('flood', 'hostname', 'identifier', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '')); 2130 db_add_index('flood', 'allow', array('event', 'identifier', 'timestamp')); 2131 } 2132 2133 /** 2134 * Move CACHE_AGGRESSIVE to CACHE_NORMAL. 2135 */ 2136 function system_update_7033() { 2137 if (variable_get('cache') == 2) { 2138 variable_set('cache', 1); 2139 return t('Aggressive caching was disabled and replaced with normal caching. Read the page caching section in default.settings.php for more information on how to enable similar functionality.'); 2140 } 2141 } 2142 2143 /** 2144 * Migrate the file path settings and create the new {file_managed} table. 2145 */ 2146 function system_update_7034() { 2147 $files_directory = variable_get('file_directory_path', NULL); 2148 if (variable_get('file_downloads', 1) == 1) { 2149 // Our default is public, so we don't need to set anything. 2150 if (!empty($files_directory)) { 2151 variable_set('file_public_path', $files_directory); 2152 } 2153 } 2154 elseif (variable_get('file_downloads', 1) == 2) { 2155 variable_set('file_default_scheme', 'private'); 2156 if (!empty($files_directory)) { 2157 variable_set('file_private_path', $files_directory); 2158 } 2159 } 2160 variable_del('file_downloads'); 2161 2162 $schema['file_managed'] = array( 2163 'description' => 'Stores information for uploaded files.', 2164 'fields' => array( 2165 'fid' => array( 2166 'description' => 'File ID.', 2167 'type' => 'serial', 2168 'unsigned' => TRUE, 2169 'not null' => TRUE, 2170 ), 2171 'uid' => array( 2172 'description' => 'The {user}.uid of the user who is associated with the file.', 2173 'type' => 'int', 2174 'unsigned' => TRUE, 2175 'not null' => TRUE, 2176 'default' => 0, 2177 ), 2178 'filename' => array( 2179 'description' => 'Name of the file with no path components. This may differ from the basename of the filepath if the file is renamed to avoid overwriting an existing file.', 2180 'type' => 'varchar', 2181 'length' => 255, 2182 'not null' => TRUE, 2183 'default' => '', 2184 'binary' => TRUE, 2185 ), 2186 'uri' => array( 2187 'description' => 'URI of file.', 2188 'type' => 'varchar', 2189 'length' => 255, 2190 'not null' => TRUE, 2191 'default' => '', 2192 'binary' => TRUE, 2193 ), 2194 'filemime' => array( 2195 'description' => "The file's MIME type.", 2196 'type' => 'varchar', 2197 'length' => 255, 2198 'not null' => TRUE, 2199 'default' => '', 2200 ), 2201 'filesize' => array( 2202 'description' => 'The size of the file in bytes.', 2203 'type' => 'int', 2204 'unsigned' => TRUE, 2205 'not null' => TRUE, 2206 'default' => 0, 2207 ), 2208 'status' => array( 2209 'description' => 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.', 2210 'type' => 'int', 2211 'not null' => TRUE, 2212 'default' => 0, 2213 'size' => 'tiny', 2214 ), 2215 'timestamp' => array( 2216 'description' => 'UNIX timestamp for when the file was added.', 2217 'type' => 'int', 2218 'unsigned' => TRUE, 2219 'not null' => TRUE, 2220 'default' => 0, 2221 ), 2222 ), 2223 'indexes' => array( 2224 'uid' => array('uid'), 2225 'status' => array('status'), 2226 'timestamp' => array('timestamp'), 2227 ), 2228 'unique keys' => array( 2229 'uri' => array('uri'), 2230 ), 2231 'primary key' => array('fid'), 2232 ); 2233 2234 db_create_table('file_managed', $schema['file_managed']); 2235 } 2236 2237 /** 2238 * Split the 'access site in maintenance mode' permission from 'administer site configuration'. 2239 */ 2240 function system_update_7036() { 2241 // Get existing roles that can 'administer site configuration'. 2242 $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer site configuration'))->fetchCol(); 2243 // None found. 2244 if (empty($rids)) { 2245 return; 2246 } 2247 $insert = db_insert('role_permission')->fields(array('rid', 'permission')); 2248 foreach ($rids as $rid) { 2249 $insert->values(array( 2250 'rid' => $rid, 2251 'permission' => 'access site in maintenance mode', 2252 )); 2253 } 2254 $insert->execute(); 2255 } 2256 2257 /** 2258 * Upgrade the {url_alias} table and create a cache bin for path aliases. 2259 */ 2260 function system_update_7042() { 2261 // update_fix_d7_requirements() adds 'fake' source and alias columns to 2262 // allow bootstrap to run without fatal errors. Remove those columns now 2263 // so that we can rename properly. 2264 db_drop_field('url_alias', 'source'); 2265 db_drop_field('url_alias', 'alias'); 2266 2267 // Drop indexes. 2268 db_drop_index('url_alias', 'src_language_pid'); 2269 db_drop_unique_key('url_alias', 'dst_language_pid'); 2270 // Rename the fields, and increase their length to 255 characters. 2271 db_change_field('url_alias', 'src', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); 2272 db_change_field('url_alias', 'dst', 'alias', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); 2273 // Add indexes back. We replace the unique key with an index since it never 2274 // provided any meaningful unique constraint ('pid' is a primary key). 2275 db_add_index('url_alias', 'source_language_pid', array('source', 'language', 'pid')); 2276 db_add_index('url_alias', 'alias_language_pid', array('alias', 'language', 'pid')); 2277 2278 // Now that the URL aliases are correct, we can rebuild the whitelist. 2279 drupal_path_alias_whitelist_rebuild(); 2280 } 2281 2282 /** 2283 * Drop the actions_aid table. 2284 */ 2285 function system_update_7044() { 2286 // The current value of the increment has been taken into account when 2287 // creating the sequences table in update_fix_d7_requirements(). 2288 db_drop_table('actions_aid'); 2289 } 2290 2291 /** 2292 * Add expiration field to the {flood} table. 2293 */ 2294 function system_update_7045() { 2295 db_add_field('flood', 'expiration', array('description' => 'Expiration timestamp. Expired events are purged on cron run.', 'type' => 'int', 'not null' => TRUE, 'default' => 0)); 2296 db_add_index('flood', 'purge', array('expiration')); 2297 } 2298 2299 /** 2300 * Switch from the Minnelli theme if it is the default or admin theme. 2301 */ 2302 function system_update_7046() { 2303 if (variable_get('theme_default') == 'minnelli' || variable_get('admin_theme') == 'minnelli') { 2304 // Make sure Garland is enabled. 2305 db_update('system') 2306 ->fields(array('status' => 1)) 2307 ->condition('type', 'theme') 2308 ->condition('name', 'garland') 2309 ->execute(); 2310 if (variable_get('theme_default') != 'garland') { 2311 // If the default theme isn't Garland, transfer all of Minnelli's old 2312 // settings to Garland. 2313 $settings = variable_get('theme_minnelli_settings', array()); 2314 // Set the theme setting width to "fixed" to match Minnelli's old layout. 2315 $settings['garland_width'] = 'fixed'; 2316 variable_set('theme_garland_settings', $settings); 2317 // Remove Garland's color files since they won't match Minnelli's. 2318 foreach (variable_get('color_garland_files', array()) as $file) { 2319 @drupal_unlink($file); 2320 } 2321 if (isset($file) && $file = dirname($file)) { 2322 @drupal_rmdir($file); 2323 } 2324 variable_del('color_garland_palette'); 2325 variable_del('color_garland_stylesheets'); 2326 variable_del('color_garland_logo'); 2327 variable_del('color_garland_files'); 2328 variable_del('color_garland_screenshot'); 2329 } 2330 if (variable_get('theme_default') == 'minnelli') { 2331 variable_set('theme_default', 'garland'); 2332 } 2333 if (variable_get('admin_theme') == 'minnelli') { 2334 variable_set('admin_theme', 'garland'); 2335 } 2336 } 2337 } 2338 2339 /** 2340 * Normalize the front page path variable. 2341 */ 2342 function system_update_7047() { 2343 variable_set('site_frontpage', drupal_get_normal_path(variable_get('site_frontpage', 'node'))); 2344 } 2345 2346 /** 2347 * Convert path languages from the empty string to LANGUAGE_NONE. 2348 */ 2349 function system_update_7048() { 2350 db_update('url_alias') 2351 ->fields(array('language' => LANGUAGE_NONE)) 2352 ->condition('language', '') 2353 ->execute(); 2354 } 2355 2356 /** 2357 * Rename 'Default' profile to 'Standard.' 2358 */ 2359 function system_update_7049() { 2360 if (variable_get('install_profile', 'standard') == 'default') { 2361 variable_set('install_profile', 'standard'); 2362 } 2363 } 2364 2365 /** 2366 * Change {batch}.id column from serial to regular int. 2367 */ 2368 function system_update_7050() { 2369 db_change_field('batch', 'bid', 'bid', array('description' => 'Primary Key: Unique batch ID.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE)); 2370 } 2371 2372 /** 2373 * make the IP field IPv6 compatible 2374 */ 2375 function system_update_7051() { 2376 db_change_field('blocked_ips', 'ip', 'ip', array('description' => 'IP address', 'type' => 'varchar', 'length' => 40, 'not null' => TRUE, 'default' => '')); 2377 } 2378 2379 /** 2380 * Rename file to include_file in {menu_router} table. 2381 */ 2382 function system_update_7052() { 2383 db_change_field('menu_router', 'file', 'include_file', array('type' => 'text', 'size' => 'medium')); 2384 } 2385 2386 /** 2387 * Upgrade standard blocks and menus. 2388 */ 2389 function system_update_7053() { 2390 if (db_table_exists('menu_custom')) { 2391 // Create the same menus as in menu_install(). 2392 db_insert('menu_custom') 2393 ->fields(array('menu_name' => 'user-menu', 'title' => 'User Menu', 'description' => "The <em>User</em> menu contains links related to the user's account, as well as the 'Log out' link.")) 2394 ->execute(); 2395 2396 db_insert('menu_custom') 2397 ->fields(array('menu_name' => 'management', 'title' => 'Management', 'description' => "The <em>Management</em> menu contains links for administrative tasks.")) 2398 ->execute(); 2399 } 2400 2401 block_flush_caches(); 2402 2403 // Show the new menu blocks along the navigation block. 2404 $blocks = db_query("SELECT theme, status, region, weight, visibility, pages FROM {block} WHERE module = 'system' AND delta = 'navigation'"); 2405 $deltas = db_or() 2406 ->condition('delta', 'user-menu') 2407 ->condition('delta', 'management'); 2408 2409 foreach ($blocks as $block) { 2410 db_update('block') 2411 ->fields(array( 2412 'status' => $block->status, 2413 'region' => $block->region, 2414 'weight' => $block->weight, 2415 'visibility' => $block->visibility, 2416 'pages' => $block->pages, 2417 )) 2418 ->condition('theme', $block->theme) 2419 ->condition('module', 'system') 2420 ->condition($deltas) 2421 ->execute(); 2422 } 2423 } 2424 2425 /** 2426 * Remove {cache_*}.headers columns. 2427 */ 2428 function system_update_7054() { 2429 // Update: update_fix_d7_requirements() installs this version for cache_path 2430 // already, so we don't include it in this particular update. It should be 2431 // included in later updates though. 2432 $cache_tables = array( 2433 'cache' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.', 2434 'cache_form' => 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.', 2435 'cache_page' => 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.', 2436 'cache_menu' => 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.', 2437 ); 2438 $schema = system_schema_cache_7054(); 2439 foreach ($cache_tables as $table => $description) { 2440 $schema['description'] = $description; 2441 db_drop_table($table); 2442 db_create_table($table, $schema); 2443 } 2444 } 2445 2446 /** 2447 * Converts fields that store serialized variables from text to blob. 2448 */ 2449 function system_update_7055() { 2450 $spec = array( 2451 'description' => 'The value of the variable.', 2452 'type' => 'blob', 2453 'not null' => TRUE, 2454 'size' => 'big', 2455 'translatable' => TRUE, 2456 ); 2457 db_change_field('variable', 'value', 'value', $spec); 2458 2459 $spec = array( 2460 'description' => 'Parameters to be passed to the callback function.', 2461 'type' => 'blob', 2462 'not null' => TRUE, 2463 'size' => 'big', 2464 ); 2465 db_change_field('actions', 'parameters', 'parameters', $spec); 2466 2467 $spec = array( 2468 'description' => 'A serialized array containing the processing data for the batch.', 2469 'type' => 'blob', 2470 'not null' => FALSE, 2471 'size' => 'big', 2472 ); 2473 db_change_field('batch', 'batch', 'batch', $spec); 2474 2475 $spec = array( 2476 'description' => 'A serialized array of function names (like node_load) to be called to load an object corresponding to a part of the current path.', 2477 'type' => 'blob', 2478 'not null' => TRUE, 2479 ); 2480 db_change_field('menu_router', 'load_functions', 'load_functions', $spec); 2481 2482 $spec = array( 2483 'description' => 'A serialized array of function names (like user_uid_optional_to_arg) to be called to replace a part of the router path with another string.', 2484 'type' => 'blob', 2485 'not null' => TRUE, 2486 ); 2487 db_change_field('menu_router', 'to_arg_functions', 'to_arg_functions', $spec); 2488 2489 $spec = array( 2490 'description' => 'A serialized array of arguments for the access callback.', 2491 'type' => 'blob', 2492 'not null' => FALSE, 2493 ); 2494 db_change_field('menu_router', 'access_arguments', 'access_arguments', $spec); 2495 2496 $spec = array( 2497 'description' => 'A serialized array of arguments for the page callback.', 2498 'type' => 'blob', 2499 'not null' => FALSE, 2500 ); 2501 db_change_field('menu_router', 'page_arguments', 'page_arguments', $spec); 2502 2503 $spec = array( 2504 'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.', 2505 'type' => 'blob', 2506 'not null' => FALSE, 2507 'translatable' => TRUE, 2508 ); 2509 db_change_field('menu_links', 'options', 'options', $spec); 2510 2511 $spec = array( 2512 'description' => 'The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.', 2513 'type' => 'blob', 2514 'not null' => FALSE, 2515 'size' => 'big', 2516 ); 2517 db_change_field('sessions', 'session', 'session', $spec); 2518 2519 $spec = array( 2520 'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.", 2521 'type' => 'blob', 2522 'not null' => FALSE, 2523 ); 2524 db_change_field('system', 'info', 'info', $spec); 2525 } 2526 2527 /** 2528 * Increase the size of session-ids. 2529 */ 2530 function system_update_7057() { 2531 $spec = array( 2532 'description' => "A session ID. The value is generated by PHP's Session API.", 2533 'type' => 'varchar', 2534 'length' => 128, 2535 'not null' => TRUE, 2536 'default' => '', 2537 ); 2538 db_change_field('sessions', 'sid', 'sid', $spec); 2539 } 2540 2541 /** 2542 * Remove cron semaphore variable. 2543 */ 2544 function system_update_7058() { 2545 variable_del('cron_semaphore'); 2546 } 2547 2548 /** 2549 * Create the {file_usage} table. 2550 */ 2551 function system_update_7059() { 2552 $spec = array( 2553 'description' => 'Track where a file is used.', 2554 'fields' => array( 2555 'fid' => array( 2556 'description' => 'File ID.', 2557 'type' => 'int', 2558 'unsigned' => TRUE, 2559 'not null' => TRUE, 2560 ), 2561 'module' => array( 2562 'description' => 'The name of the module that is using the file.', 2563 'type' => 'varchar', 2564 'length' => 255, 2565 'not null' => TRUE, 2566 'default' => '', 2567 ), 2568 'type' => array( 2569 'description' => 'The name of the object type in which the file is used.', 2570 'type' => 'varchar', 2571 'length' => 64, 2572 'not null' => TRUE, 2573 'default' => '', 2574 ), 2575 'id' => array( 2576 'description' => 'The primary key of the object using the file.', 2577 'type' => 'int', 2578 'unsigned' => TRUE, 2579 'not null' => TRUE, 2580 'default' => 0, 2581 ), 2582 'count' => array( 2583 'description' => 'The number of times this file is used by this object.', 2584 'type' => 'int', 2585 'unsigned' => TRUE, 2586 'not null' => TRUE, 2587 'default' => 0, 2588 ), 2589 ), 2590 'primary key' => array('fid', 'type', 'id', 'module'), 2591 'indexes' => array( 2592 'type_id' => array('type', 'id'), 2593 'fid_count' => array('fid', 'count'), 2594 'fid_module' => array('fid', 'module'), 2595 ), 2596 ); 2597 db_create_table('file_usage', $spec); 2598 } 2599 2600 /** 2601 * Create fields in preparation for migrating upload.module to file.module. 2602 */ 2603 function system_update_7060() { 2604 if (!db_table_exists('upload')) { 2605 return; 2606 } 2607 2608 if (!db_query_range('SELECT 1 FROM {upload}', 0, 1)->fetchField()) { 2609 // There is nothing to migrate. Delete variables and the empty table. There 2610 // is no need to create fields that are not going to be used. 2611 foreach (_update_7000_node_get_types() as $node_type) { 2612 variable_del('upload_' . $node_type->type); 2613 } 2614 db_drop_table('upload'); 2615 return; 2616 } 2617 2618 // Check which node types have upload.module attachments enabled. 2619 $context['types'] = array(); 2620 foreach (_update_7000_node_get_types() as $node_type) { 2621 if (variable_get('upload_' . $node_type->type, 0)) { 2622 $context['types'][$node_type->type] = $node_type->type; 2623 } 2624 } 2625 2626 // The {upload} table will be deleted when this update is complete so we 2627 // want to be careful to migrate all the data, even for node types that 2628 // may have had attachments disabled after files were uploaded. Look for 2629 // any other node types referenced by the upload records and add those to 2630 // the list. The admin can always remove the field later. 2631 $results = db_query('SELECT DISTINCT type FROM {node} n INNER JOIN {node_revision} nr ON n.nid = nr.nid INNER JOIN {upload} u ON nr.vid = u.vid'); 2632 foreach ($results as $row) { 2633 if (!isset($context['types'][$row->type])) { 2634 drupal_set_message(t('The content type %rowtype had uploads disabled but contained uploaded file data. Uploads have been re-enabled to migrate the existing data. You may delete the "File attachments" field in the %rowtype type if this data is not necessary.', array('%rowtype' => $row->type))); 2635 $context['types'][$row->type] = $row->type; 2636 } 2637 } 2638 2639 // Create a single "upload" field on all the content types that have uploads 2640 // enabled, then add an instance to each enabled type. 2641 if (count($context['types']) > 0) { 2642 module_enable(array('file')); 2643 $field = array( 2644 'field_name' => 'upload', 2645 'type' => 'file', 2646 'module' => 'file', 2647 'locked' => FALSE, 2648 'cardinality' => FIELD_CARDINALITY_UNLIMITED, 2649 'translatable' => FALSE, 2650 'settings' => array( 2651 'display_field' => 1, 2652 'display_default' => variable_get('upload_list_default', 1), 2653 'uri_scheme' => file_default_scheme(), 2654 'default_file' => 0, 2655 ), 2656 ); 2657 2658 $upload_size = variable_get('upload_uploadsize_default', 1); 2659 $instance = array( 2660 'field_name' => 'upload', 2661 'entity_type' => 'node', 2662 'bundle' => NULL, 2663 'label' => 'File attachments', 2664 'required' => 0, 2665 'description' => '', 2666 'widget' => array( 2667 'weight' => '1', 2668 'settings' => array( 2669 'progress_indicator' => 'throbber', 2670 ), 2671 'type' => 'file_generic', 2672 ), 2673 'settings' => array( 2674 'max_filesize' => $upload_size ? ($upload_size . ' MB') : '', 2675 'file_extensions' => variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'), 2676 'file_directory' => '', 2677 'description_field' => 1, 2678 ), 2679 'display' => array( 2680 'default' => array( 2681 'label' => 'hidden', 2682 'type' => 'file_table', 2683 'settings' => array(), 2684 'weight' => 0, 2685 'module' => 'file', 2686 ), 2687 'full' => array( 2688 'label' => 'hidden', 2689 'type' => 'file_table', 2690 'settings' => array(), 2691 'weight' => 0, 2692 'module' => 'file', 2693 ), 2694 'teaser' => array( 2695 'label' => 'hidden', 2696 'type' => 'hidden', 2697 'settings' => array(), 2698 'weight' => 0, 2699 'module' => NULL, 2700 ), 2701 'rss' => array( 2702 'label' => 'hidden', 2703 'type' => 'file_table', 2704 'settings' => array(), 2705 'weight' => 0, 2706 'module' => 'file', 2707 ), 2708 ), 2709 ); 2710 2711 // Create the field. 2712 _update_7000_field_create_field($field); 2713 2714 // Create the instances. 2715 foreach ($context['types'] as $bundle) { 2716 $instance['bundle'] = $bundle; 2717 _update_7000_field_create_instance($field, $instance); 2718 // Now that the instance is created, we can safely delete any legacy 2719 // node type information. 2720 variable_del('upload_' . $bundle); 2721 } 2722 } 2723 else { 2724 // No uploads or content types with uploads enabled. 2725 db_drop_table('upload'); 2726 } 2727 } 2728 2729 /** 2730 * Migrate upload.module data to the newly created file field. 2731 */ 2732 function system_update_7061(&$sandbox) { 2733 if (!db_table_exists('upload')) { 2734 return; 2735 } 2736 2737 if (!isset($sandbox['progress'])) { 2738 // Delete stale rows from {upload} where the fid is not in the {files} table. 2739 db_delete('upload') 2740 ->notExists( 2741 db_select('files', 'f') 2742 ->fields('f', array('fid')) 2743 ->where('f.fid = {upload}.fid') 2744 ) 2745 ->execute(); 2746 2747 // Delete stale rows from {upload} where the vid is not in the 2748 // {node_revision} table. The table has already been renamed in 2749 // node_update_7001(). 2750 db_delete('upload') 2751 ->notExists( 2752 db_select('node_revision', 'nr') 2753 ->fields('nr', array('vid')) 2754 ->where('nr.vid = {upload}.vid') 2755 ) 2756 ->execute(); 2757 2758 // Retrieve a list of node revisions that have uploaded files attached. 2759 // DISTINCT queries are expensive, especially when paged, so we store the 2760 // data in its own table for the duration of the update. 2761 $table = array( 2762 'description' => t('Stores temporary data for system_update_7061.'), 2763 'fields' => array('vid' => array('type' => 'int')), 2764 'primary key' => array('vid'), 2765 ); 2766 db_create_table('system_update_7061', $table); 2767 $query = db_select('upload', 'u'); 2768 $query->distinct(); 2769 $query->addField('u','vid'); 2770 db_insert('system_update_7061') 2771 ->from($query) 2772 ->execute(); 2773 2774 // Initialize batch update information. 2775 $sandbox['progress'] = 0; 2776 $sandbox['last_vid_processed'] = -1; 2777 $sandbox['max'] = db_query("SELECT COUNT(*) FROM {system_update_7061}")->fetchField(); 2778 } 2779 2780 // Determine vids for this batch. 2781 // Process all files attached to a given revision during the same batch. 2782 $limit = variable_get('upload_update_batch_size', 100); 2783 $vids = db_query_range('SELECT vid FROM {system_update_7061} WHERE vid > :lastvid ORDER BY vid', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed'])) 2784 ->fetchCol(); 2785 2786 // Retrieve information on all the files attached to these revisions. 2787 if (!empty($vids)) { 2788 $node_revisions = array(); 2789 $result = db_query('SELECT u.fid, u.vid, u.list, u.description, n.nid, n.type, u.weight FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid IN (:vids) ORDER BY u.vid, u.weight, u.fid', array(':vids' => $vids)); 2790 foreach ($result as $record) { 2791 // For each uploaded file, retrieve the corresponding data from the old 2792 // files table (since upload doesn't know about the new entry in the 2793 // file_managed table). 2794 $file = db_select('files', 'f') 2795 ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp')) 2796 ->condition('f.fid', $record->fid) 2797 ->execute() 2798 ->fetchAssoc(); 2799 if (!$file) { 2800 continue; 2801 } 2802 2803 // Add in the file information from the upload table. 2804 $file['description'] = $record->description; 2805 $file['display'] = $record->list; 2806 2807 // Create one record for each revision that contains all the uploaded 2808 // files. 2809 $node_revisions[$record->vid]['nid'] = $record->nid; 2810 $node_revisions[$record->vid]['vid'] = $record->vid; 2811 $node_revisions[$record->vid]['type'] = $record->type; 2812 $node_revisions[$record->vid]['file'][LANGUAGE_NONE][] = $file; 2813 } 2814 2815 // Now that we know which files belong to which revisions, update the 2816 // files'// database entries, and save a reference to each file in the 2817 // upload field on their node revisions. 2818 $basename = variable_get('file_directory_path', conf_path() . '/files'); 2819 $scheme = file_default_scheme() . '://'; 2820 foreach ($node_revisions as $vid => $revision) { 2821 foreach ($revision['file'][LANGUAGE_NONE] as $delta => $file) { 2822 // We will convert filepaths to URI using the default scheme 2823 // and stripping off the existing file directory path. 2824 $file['uri'] = $scheme . preg_replace('!^' . preg_quote($basename) . '!', '', $file['filepath']); 2825 $file['uri'] = file_stream_wrapper_uri_normalize($file['uri']); 2826 unset($file['filepath']); 2827 // Insert into the file_managed table. 2828 // Each fid should only be stored once in file_managed. 2829 db_merge('file_managed') 2830 ->key(array( 2831 'fid' => $file['fid'], 2832 )) 2833 ->fields(array( 2834 'uid' => $file['uid'], 2835 'filename' => $file['filename'], 2836 'uri' => $file['uri'], 2837 'filemime' => $file['filemime'], 2838 'filesize' => $file['filesize'], 2839 'status' => $file['status'], 2840 'timestamp' => $file['timestamp'], 2841 )) 2842 ->execute(); 2843 2844 // Add the usage entry for the file. 2845 $file = (object) $file; 2846 file_usage_add($file, 'file', 'node', $revision['nid']); 2847 2848 // Update the node revision's upload file field with the file data. 2849 $revision['file'][LANGUAGE_NONE][$delta] = array('fid' => $file->fid, 'display' => $file->display, 'description' => $file->description); 2850 } 2851 2852 // Write the revision's upload field data into the field_upload tables. 2853 $node = (object) $revision; 2854 _update_7000_field_sql_storage_write('node', $node->type, $node->nid, $node->vid, 'upload', $node->file); 2855 2856 // Update our progress information for the batch update. 2857 $sandbox['progress']++; 2858 $sandbox['last_vid_processed'] = $vid; 2859 } 2860 } 2861 2862 // If less than limit node revisions were processed, the update process is 2863 // finished. 2864 if (count($vids) < $limit) { 2865 $finished = TRUE; 2866 } 2867 2868 // If there's no max value then there's nothing to update and we're finished. 2869 if (empty($sandbox['max']) || isset($finished)) { 2870 db_drop_table('upload'); 2871 db_drop_table('system_update_7061'); 2872 return t('Upload module has been migrated to File module.'); 2873 } 2874 else { 2875 // Indicate our current progress to the batch update system. 2876 $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max']; 2877 } 2878 } 2879 2880 /** 2881 * Replace 'system_list' index with 'bootstrap' index on {system}. 2882 */ 2883 function system_update_7062() { 2884 db_drop_index('system', 'bootstrap'); 2885 db_drop_index('system', 'system_list'); 2886 db_add_index('system', 'system_list', array('status', 'bootstrap', 'type', 'weight', 'name')); 2887 } 2888 2889 /** 2890 * Delete {menu_links} records for 'type' => MENU_CALLBACK which would not appear in a fresh install. 2891 */ 2892 function system_update_7063() { 2893 // For router items where 'type' => MENU_CALLBACK, {menu_router}.type is 2894 // stored as 4 in Drupal 6, and 0 in Drupal 7. Fortunately Drupal 7 doesn't 2895 // store any types as 4, so delete both. 2896 $result = db_query('SELECT ml.mlid FROM {menu_links} ml INNER JOIN {menu_router} mr ON ml.router_path = mr.path WHERE ml.module = :system AND ml.customized = 0 AND mr.type IN(:callbacks)', array(':callbacks' => array(0, 4), ':system' => 'system')); 2897 foreach ($result as $record) { 2898 db_delete('menu_links')->condition('mlid', $record->mlid)->execute(); 2899 } 2900 } 2901 2902 /** 2903 * Remove block_callback field from {menu_router}. 2904 */ 2905 function system_update_7064() { 2906 db_drop_field('menu_router', 'block_callback'); 2907 } 2908 2909 /** 2910 * Remove the default value for sid. 2911 */ 2912 function system_update_7065() { 2913 $spec = array( 2914 'description' => "A session ID. The value is generated by Drupal's session handlers.", 2915 'type' => 'varchar', 2916 'length' => 128, 2917 'not null' => TRUE, 2918 ); 2919 db_drop_primary_key('sessions'); 2920 db_change_field('sessions', 'sid', 'sid', $spec, array('primary key' => array('sid', 'ssid'))); 2921 // Delete any sessions with empty session ID. 2922 db_delete('sessions')->condition('sid', '')->execute(); 2923 } 2924 2925 /** 2926 * Migrate the 'file_directory_temp' variable. 2927 */ 2928 function system_update_7066() { 2929 $d6_file_directory_temp = variable_get('file_directory_temp', file_directory_temp()); 2930 variable_set('file_temporary_path', $d6_file_directory_temp); 2931 variable_del('file_directory_temp'); 2932 } 2933 2934 /** 2935 * Grant administrators permission to view the administration theme. 2936 */ 2937 function system_update_7067() { 2938 // Users with access to administration pages already see the administration 2939 // theme in some places (if one is enabled on the site), so we want them to 2940 // continue seeing it. 2941 $admin_roles = user_roles(FALSE, 'access administration pages'); 2942 foreach (array_keys($admin_roles) as $rid) { 2943 _update_7000_user_role_grant_permissions($rid, array('view the administration theme'), 'system'); 2944 } 2945 // The above check is not guaranteed to reach all administrative users of the 2946 // site, so if the site is currently using an administration theme, display a 2947 // message also. 2948 if (variable_get('admin_theme')) { 2949 if (empty($admin_roles)) { 2950 drupal_set_message('The new "View the administration theme" permission is required in order to view your site\'s administration theme. You can grant this permission to your site\'s administrators on the <a href="' . url('admin/people/permissions', array('fragment' => 'module-system')) . '">permissions page</a>.'); 2951 } 2952 else { 2953 drupal_set_message('The new "View the administration theme" permission is required in order to view your site\'s administration theme. This permission has been automatically granted to the following roles: <em>' . check_plain(implode(', ', $admin_roles)) . '</em>. You can grant this permission to other roles on the <a href="' . url('admin/people/permissions', array('fragment' => 'module-system')) . '">permissions page</a>.'); 2954 } 2955 } 2956 } 2957 2958 /** 2959 * Update {url_alias}.language description. 2960 */ 2961 function system_update_7068() { 2962 $spec = array( 2963 'description' => "The language this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.", 2964 'type' => 'varchar', 2965 'length' => 12, 2966 'not null' => TRUE, 2967 'default' => '', 2968 ); 2969 db_change_field('url_alias', 'language', 'language', $spec); 2970 } 2971 2972 /** 2973 * Remove the obsolete 'site_offline' variable. 2974 * 2975 * @see update_fix_d7_requirements() 2976 */ 2977 function system_update_7069() { 2978 variable_del('site_offline'); 2979 } 2980 2981 /** 2982 * @} End of "defgroup updates-6.x-to-7.x". 2983 * The next series of updates should start at 8000. 2984 */ 2985 2986 /** 2987 * @defgroup updates-7.x-extra Extra updates for 7.x 2988 * @{ 2989 * Update functions between 7.x versions. 2990 */ 2991 2992 /** 2993 * Remove the obsolete 'drupal_badge_color' and 'drupal_badge_size' variables. 2994 */ 2995 function system_update_7070() { 2996 variable_del('drupal_badge_color'); 2997 variable_del('drupal_badge_size'); 2998 } 2999 3000 /** 3001 * Add index missed during upgrade, and fix field default. 3002 */ 3003 function system_update_7071() { 3004 db_drop_index('date_format_type', 'title'); 3005 db_add_index('date_format_type', 'title', array('title')); 3006 db_change_field('registry', 'filename', 'filename', array( 3007 'type' => 'varchar', 3008 'length' => 255, 3009 'not null' => TRUE, 3010 )); 3011 } 3012 3013 /** 3014 * Remove the obsolete 'site_offline_message' variable. 3015 * 3016 * @see update_fix_d7_requirements() 3017 */ 3018 function system_update_7072() { 3019 variable_del('site_offline_message'); 3020 } 3021 3022 /** 3023 * Add binary to {file_managed}, in case system_update_7034() was run without 3024 * it. 3025 */ 3026 function system_update_7073() { 3027 db_change_field('file_managed', 'filename', 'filename', array( 3028 'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.', 3029 'type' => 'varchar', 3030 'length' => 255, 3031 'not null' => TRUE, 3032 'default' => '', 3033 'binary' => TRUE, 3034 )); 3035 db_change_field('file_managed', 'uri', 'uri', array( 3036 'description' => 'The URI to access the file (either local or remote).', 3037 'type' => 'varchar', 3038 'length' => 255, 3039 'not null' => TRUE, 3040 'default' => '', 3041 'binary' => TRUE, 3042 )); 3043 } 3044 3045 /** 3046 * This update has been removed and will not run. 3047 */ 3048 function system_update_7074() { 3049 // This update function previously converted menu_links query strings to 3050 // arrays. It has been removed for now due to incompatibility with 3051 // PostgreSQL. 3052 } 3053 3054 /** 3055 * Convert menu_links query strings into arrays. 3056 */ 3057 function system_update_7076() { 3058 $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC)) 3059 ->fields('ml', array('mlid', 'options')); 3060 foreach ($query->execute() as $menu_link) { 3061 if (strpos($menu_link['options'], 'query') !== FALSE) { 3062 $menu_link['options'] = unserialize($menu_link['options']); 3063 if (isset($menu_link['options']['query']) && is_string($menu_link['options']['query'])) { 3064 $menu_link['options']['query'] = drupal_get_query_array($menu_link['options']['query']); 3065 db_update('menu_links') 3066 ->fields(array( 3067 'options' => serialize($menu_link['options']), 3068 )) 3069 ->condition('mlid', $menu_link['mlid'], '=') 3070 ->execute(); 3071 } 3072 } 3073 } 3074 } 3075 3076 /** 3077 * Revert {file_managed}.filename changed to a binary column. 3078 */ 3079 function system_update_7077() { 3080 db_change_field('file_managed', 'filename', 'filename', array( 3081 'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.', 3082 'type' => 'varchar', 3083 'length' => 255, 3084 'not null' => TRUE, 3085 'default' => '', 3086 )); 3087 } 3088 3089 /** 3090 * @} End of "defgroup updates-7.x-extra". 3091 * The next series of updates should start at 8000. 3092 */
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title