| webmaster@1 | 1 <?php | 
| webmaster@1 | 2 // $Id: system.install,v 1.238.2.1 2008/02/08 17:07:55 goba Exp $ | 
| webmaster@1 | 3 | 
| webmaster@1 | 4 /** | 
| webmaster@1 | 5  * Test and report Drupal installation requirements. | 
| webmaster@1 | 6  * | 
| webmaster@1 | 7  * @param $phase | 
| webmaster@1 | 8  *   The current system installation phase. | 
| webmaster@1 | 9  * @return | 
| webmaster@1 | 10  *   An array of system requirements. | 
| webmaster@1 | 11  */ | 
| webmaster@1 | 12 function system_requirements($phase) { | 
| webmaster@1 | 13   $requirements = array(); | 
| webmaster@1 | 14   // Ensure translations don't break at install time | 
| webmaster@1 | 15   $t = get_t(); | 
| webmaster@1 | 16 | 
| webmaster@1 | 17   // Report Drupal version | 
| webmaster@1 | 18   if ($phase == 'runtime') { | 
| webmaster@1 | 19     $requirements['drupal'] = array( | 
| webmaster@1 | 20       'title' => $t('Drupal'), | 
| webmaster@1 | 21       'value' => VERSION, | 
| webmaster@1 | 22       'severity' => REQUIREMENT_INFO, | 
| webmaster@1 | 23       'weight' => -10, | 
| webmaster@1 | 24     ); | 
| webmaster@1 | 25   } | 
| webmaster@1 | 26 | 
| webmaster@1 | 27   // Web server information. | 
| webmaster@1 | 28   $software = $_SERVER['SERVER_SOFTWARE']; | 
| webmaster@1 | 29   $requirements['webserver'] = array( | 
| webmaster@1 | 30     'title' => $t('Web server'), | 
| webmaster@1 | 31     'value' => $software, | 
| webmaster@1 | 32   ); | 
| webmaster@1 | 33 | 
| webmaster@1 | 34   // Test PHP version | 
| webmaster@1 | 35   $requirements['php'] = array( | 
| webmaster@1 | 36     'title' => $t('PHP'), | 
| webmaster@1 | 37     'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/reports/status/php') : phpversion(), | 
| webmaster@1 | 38   ); | 
| webmaster@1 | 39   if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) { | 
| webmaster@1 | 40     $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP)); | 
| webmaster@1 | 41     $requirements['php']['severity'] = REQUIREMENT_ERROR; | 
| webmaster@1 | 42   } | 
| webmaster@1 | 43 | 
| webmaster@1 | 44   // Test PHP register_globals setting. | 
| webmaster@1 | 45   $requirements['php_register_globals'] = array( | 
| webmaster@1 | 46     'title' => $t('PHP register globals'), | 
| webmaster@1 | 47   ); | 
| webmaster@1 | 48   $register_globals = trim(ini_get('register_globals')); | 
| webmaster@1 | 49   // Unfortunately, ini_get() may return many different values, and we can't | 
| webmaster@1 | 50   // be certain which values mean 'on', so we instead check for 'not off' | 
| webmaster@1 | 51   // since we never want to tell the user that their site is secure | 
| webmaster@1 | 52   // (register_globals off), when it is in fact on. We can only guarantee | 
| webmaster@1 | 53   // register_globals is off if the value returned is 'off', '', or 0. | 
| webmaster@1 | 54   if (!empty($register_globals) && strtolower($register_globals) != 'off') { | 
| webmaster@1 | 55     $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>.'); | 
| webmaster@1 | 56     $requirements['php_register_globals']['severity'] = REQUIREMENT_ERROR; | 
| webmaster@1 | 57     $requirements['php_register_globals']['value'] = $t("Enabled ('@value')", array('@value' => $register_globals)); | 
| webmaster@1 | 58   } | 
| webmaster@1 | 59   else { | 
| webmaster@1 | 60     $requirements['php_register_globals']['value'] = $t('Disabled'); | 
| webmaster@1 | 61   } | 
| webmaster@1 | 62 | 
| webmaster@1 | 63   // Test PHP memory_limit | 
| webmaster@1 | 64   $memory_limit = ini_get('memory_limit'); | 
| webmaster@1 | 65   $requirements['php_memory_limit'] = array( | 
| webmaster@1 | 66     'title' => $t('PHP memory limit'), | 
| webmaster@1 | 67     'value' => $memory_limit, | 
| webmaster@1 | 68   ); | 
| webmaster@1 | 69 | 
| webmaster@1 | 70   if ($memory_limit && parse_size($memory_limit) < parse_size(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)) { | 
| webmaster@1 | 71     $description = ''; | 
| webmaster@1 | 72     if ($phase == 'install') { | 
| webmaster@1 | 73       $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)); | 
| webmaster@1 | 74     } | 
| webmaster@1 | 75     elseif ($phase == 'update') { | 
| webmaster@1 | 76       $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)); | 
| webmaster@1 | 77     } | 
| webmaster@1 | 78     elseif ($phase == 'runtime') { | 
| webmaster@1 | 79       $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)); | 
| webmaster@1 | 80     } | 
| webmaster@1 | 81 | 
| webmaster@1 | 82     if (!empty($description)) { | 
| webmaster@1 | 83       if ($php_ini_path = get_cfg_var('cfg_file_path')) { | 
| webmaster@1 | 84         $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)); | 
| webmaster@1 | 85       } | 
| webmaster@1 | 86       else { | 
| webmaster@1 | 87         $description .= ' '. $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.'); | 
| webmaster@1 | 88       } | 
| webmaster@1 | 89 | 
| webmaster@1 | 90       $requirements['php_memory_limit']['description'] = $description .' '. $t('See the <a href="@url">Drupal requirements</a> for more information.', array('@url' => 'http://drupal.org/requirements')); | 
| webmaster@1 | 91       $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING; | 
| webmaster@1 | 92     } | 
| webmaster@1 | 93   } | 
| webmaster@1 | 94 | 
| webmaster@1 | 95   // Test DB version | 
| webmaster@1 | 96   global $db_type; | 
| webmaster@1 | 97   if (function_exists('db_status_report')) { | 
| webmaster@1 | 98     $requirements += db_status_report($phase); | 
| webmaster@1 | 99   } | 
| webmaster@1 | 100 | 
| webmaster@1 | 101   // Test settings.php file writability | 
| webmaster@1 | 102   if ($phase == 'runtime') { | 
| webmaster@1 | 103     $conf_dir = drupal_verify_install_file(conf_path(), FILE_NOT_WRITABLE, 'dir'); | 
| webmaster@1 | 104     $conf_file = drupal_verify_install_file(conf_path() .'/settings.php', FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE); | 
| webmaster@1 | 105     if (!$conf_dir || !$conf_file) { | 
| webmaster@1 | 106       $requirements['settings.php'] = array( | 
| webmaster@1 | 107         'value' => $t('Not protected'), | 
| webmaster@1 | 108         'severity' => REQUIREMENT_ERROR, | 
| webmaster@1 | 109         'description' => '', | 
| webmaster@1 | 110       ); | 
| webmaster@1 | 111       if (!$conf_dir) { | 
| webmaster@1 | 112         $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())); | 
| webmaster@1 | 113       } | 
| webmaster@1 | 114       if (!$conf_file) { | 
| webmaster@1 | 115         $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')); | 
| webmaster@1 | 116       } | 
| webmaster@1 | 117     } | 
| webmaster@1 | 118     else { | 
| webmaster@1 | 119       $requirements['settings.php'] = array( | 
| webmaster@1 | 120         'value' => $t('Protected'), | 
| webmaster@1 | 121       ); | 
| webmaster@1 | 122     } | 
| webmaster@1 | 123     $requirements['settings.php']['title'] = $t('Configuration file'); | 
| webmaster@1 | 124   } | 
| webmaster@1 | 125 | 
| webmaster@1 | 126   // Report cron status. | 
| webmaster@1 | 127   if ($phase == 'runtime') { | 
| webmaster@1 | 128     // Cron warning threshold defaults to two days. | 
| webmaster@1 | 129     $threshold_warning = variable_get('cron_threshold_warning', 172800); | 
| webmaster@1 | 130     // Cron error threshold defaults to two weeks. | 
| webmaster@1 | 131     $threshold_error = variable_get('cron_threshold_error', 1209600); | 
| webmaster@1 | 132     // Cron configuration help text. | 
| webmaster@1 | 133     $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')); | 
| webmaster@1 | 134 | 
| webmaster@1 | 135     // Determine when cron last ran. If never, use the install time to | 
| webmaster@1 | 136     // determine the warning or error status. | 
| webmaster@1 | 137     $cron_last = variable_get('cron_last', NULL); | 
| webmaster@1 | 138     $never_run = FALSE; | 
| webmaster@1 | 139     if (!is_numeric($cron_last)) { | 
| webmaster@1 | 140       $never_run = TRUE; | 
| webmaster@1 | 141       $cron_last = variable_get('install_time', 0); | 
| webmaster@1 | 142     } | 
| webmaster@1 | 143 | 
| webmaster@1 | 144     // Determine severity based on time since cron last ran. | 
| webmaster@1 | 145     $severity = REQUIREMENT_OK; | 
| webmaster@1 | 146     if (time() - $cron_last > $threshold_error) { | 
| webmaster@1 | 147       $severity = REQUIREMENT_ERROR; | 
| webmaster@1 | 148     } | 
| webmaster@1 | 149     else if ($never_run || (time() - $cron_last > $threshold_warning)) { | 
| webmaster@1 | 150       $severity = REQUIREMENT_WARNING; | 
| webmaster@1 | 151     } | 
| webmaster@1 | 152 | 
| webmaster@1 | 153     // If cron hasn't been run, and the user is viewing the main | 
| webmaster@1 | 154     // administration page, instead of an error, we display a helpful reminder | 
| webmaster@1 | 155     // to configure cron jobs. | 
| webmaster@1 | 156     if ($never_run && $severity != REQUIREMENT_ERROR && $_GET['q'] == 'admin' && user_access('administer site configuration')) { | 
| webmaster@1 | 157       drupal_set_message($t('Cron has not run. Please visit the <a href="@status">status report</a> for more information.', array('@status' => url('admin/reports/status')))); | 
| webmaster@1 | 158     } | 
| webmaster@1 | 159 | 
| webmaster@1 | 160     // Set summary and description based on values determined above. | 
| webmaster@1 | 161     if ($never_run) { | 
| webmaster@1 | 162       $summary = $t('Never run'); | 
| webmaster@1 | 163       $description = $t('Cron has not run.') .' '. $help; | 
| webmaster@1 | 164     } | 
| webmaster@1 | 165     else { | 
| webmaster@1 | 166       $summary = $t('Last run !time ago', array('!time' => format_interval(time() - $cron_last))); | 
| webmaster@1 | 167       $description = ''; | 
| webmaster@1 | 168       if ($severity != REQUIREMENT_OK) { | 
| webmaster@1 | 169         $description = $t('Cron has not run recently.') .' '. $help; | 
| webmaster@1 | 170       } | 
| webmaster@1 | 171     } | 
| webmaster@1 | 172 | 
| webmaster@1 | 173     $requirements['cron'] = array( | 
| webmaster@1 | 174       'title' => $t('Cron maintenance tasks'), | 
| webmaster@1 | 175       'severity' => $severity, | 
| webmaster@1 | 176       'value' => $summary, | 
| webmaster@1 | 177       'description' => $description .' '. $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron'))), | 
| webmaster@1 | 178     ); | 
| webmaster@1 | 179   } | 
| webmaster@1 | 180 | 
| webmaster@1 | 181   // Test files directory | 
| webmaster@1 | 182   $directory = file_directory_path(); | 
| webmaster@1 | 183   $requirements['file system'] = array( | 
| webmaster@1 | 184     'title' => $t('File system'), | 
| webmaster@1 | 185   ); | 
| webmaster@1 | 186 | 
| webmaster@1 | 187   // For installer, create the directory if possible. | 
| webmaster@1 | 188   if ($phase == 'install' && !is_dir($directory) && @mkdir($directory)) { | 
| webmaster@1 | 189     @chmod($directory, 0775); // Necessary for non-webserver users. | 
| webmaster@1 | 190   } | 
| webmaster@1 | 191 | 
| webmaster@1 | 192   $is_writable = is_writable($directory); | 
| webmaster@1 | 193   $is_directory = is_dir($directory); | 
| webmaster@1 | 194   if (!$is_writable || !$is_directory) { | 
| webmaster@1 | 195     $description = ''; | 
| webmaster@1 | 196     $requirements['file system']['value'] = $t('Not writable'); | 
| webmaster@1 | 197     if (!$is_directory) { | 
| webmaster@1 | 198       $error = $t('The directory %directory does not exist.', array('%directory' => $directory)); | 
| webmaster@1 | 199     } | 
| webmaster@1 | 200     else { | 
| webmaster@1 | 201       $error = $t('The directory %directory is not writable.', array('%directory' => $directory)); | 
| webmaster@1 | 202     } | 
| webmaster@1 | 203     // The files directory requirement check is done only during install and runtime. | 
| webmaster@1 | 204     if ($phase == 'runtime') { | 
| webmaster@1 | 205       $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/settings/file-system'))); | 
| webmaster@1 | 206     } | 
| webmaster@1 | 207     elseif ($phase == 'install') { | 
| webmaster@1 | 208       // For the installer UI, we need different wording. 'value' will | 
| webmaster@1 | 209       // be treated as version, so provide none there. | 
| webmaster@1 | 210       $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, please see INSTALL.txt or the <a href="@handbook_url">on-line handbook</a>.', array('@handbook_url' => 'http://drupal.org/server-permissions')); | 
| webmaster@1 | 211       $requirements['file system']['value'] = ''; | 
| webmaster@1 | 212     } | 
| webmaster@1 | 213     if (!empty($description)) { | 
| webmaster@1 | 214       $requirements['file system']['description'] = $description; | 
| webmaster@1 | 215       $requirements['file system']['severity'] = REQUIREMENT_ERROR; | 
| webmaster@1 | 216     } | 
| webmaster@1 | 217   } | 
| webmaster@1 | 218   else { | 
| webmaster@1 | 219     if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) { | 
| webmaster@1 | 220       $requirements['file system']['value'] = $t('Writable (<em>public</em> download method)'); | 
| webmaster@1 | 221     } | 
| webmaster@1 | 222     else { | 
| webmaster@1 | 223       $requirements['file system']['value'] = $t('Writable (<em>private</em> download method)'); | 
| webmaster@1 | 224     } | 
| webmaster@1 | 225   } | 
| webmaster@1 | 226 | 
| webmaster@1 | 227   // See if updates are available in update.php. | 
| webmaster@1 | 228   if ($phase == 'runtime') { | 
| webmaster@1 | 229     $requirements['update'] = array( | 
| webmaster@1 | 230       'title' => $t('Database updates'), | 
| webmaster@1 | 231       'severity' => REQUIREMENT_OK, | 
| webmaster@1 | 232       'value' => $t('Up to date'), | 
| webmaster@1 | 233     ); | 
| webmaster@1 | 234 | 
| webmaster@1 | 235     // Check installed modules. | 
| webmaster@1 | 236     foreach (module_list() as $module) { | 
| webmaster@1 | 237       $updates = drupal_get_schema_versions($module); | 
| webmaster@1 | 238       if ($updates !== FALSE) { | 
| webmaster@1 | 239         $default = drupal_get_installed_schema_version($module); | 
| webmaster@1 | 240         if (max($updates) > $default) { | 
| webmaster@1 | 241           $requirements['update']['severity'] = REQUIREMENT_ERROR; | 
| webmaster@1 | 242           $requirements['update']['value'] = $t('Out of date'); | 
| webmaster@1 | 243           $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')); | 
| webmaster@1 | 244           break; | 
| webmaster@1 | 245         } | 
| webmaster@1 | 246       } | 
| webmaster@1 | 247     } | 
| webmaster@1 | 248   } | 
| webmaster@1 | 249 | 
| webmaster@1 | 250   // Verify the update.php access setting | 
| webmaster@1 | 251   if ($phase == 'runtime') { | 
| webmaster@1 | 252     if (!empty($GLOBALS['update_free_access'])) { | 
| webmaster@1 | 253       $requirements['update access'] = array( | 
| webmaster@1 | 254         'value' => $t('Not protected'), | 
| webmaster@1 | 255         'severity' => REQUIREMENT_ERROR, | 
| webmaster@1 | 256         '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.'), | 
| webmaster@1 | 257       ); | 
| webmaster@1 | 258     } | 
| webmaster@1 | 259     else { | 
| webmaster@1 | 260       $requirements['update access'] = array( | 
| webmaster@1 | 261         'value' => $t('Protected'), | 
| webmaster@1 | 262       ); | 
| webmaster@1 | 263     } | 
| webmaster@1 | 264     $requirements['update access']['title'] = $t('Access to update.php'); | 
| webmaster@1 | 265   } | 
| webmaster@1 | 266 | 
| webmaster@1 | 267   // Test Unicode library | 
| webmaster@1 | 268   include_once './includes/unicode.inc'; | 
| webmaster@1 | 269   $requirements = array_merge($requirements, unicode_requirements()); | 
| webmaster@1 | 270 | 
| webmaster@1 | 271   // Check for update status module. | 
| webmaster@1 | 272   if ($phase == 'runtime') { | 
| webmaster@1 | 273     if (!module_exists('update')) { | 
| webmaster@1 | 274       $requirements['update status'] = array( | 
| webmaster@1 | 275         'value' => $t('Not enabled'), | 
| webmaster@1 | 276         'severity' => REQUIREMENT_ERROR, | 
| webmaster@1 | 277         'description' => $t('Update notifications are not enabled. It is <strong>highly recommended</strong> that you enable the update status module from the <a href="@module">module administration page</a> in order to stay up-to-date on new releases. For more information please read the <a href="@update">Update status handbook page</a>.', array('@update' => 'http://drupal.org/handbook/modules/update', '@module' => url('admin/build/modules'))), | 
| webmaster@1 | 278       ); | 
| webmaster@1 | 279     } | 
| webmaster@1 | 280     else { | 
| webmaster@1 | 281       $requirements['update status'] = array( | 
| webmaster@1 | 282         'value' => $t('Enabled'), | 
| webmaster@1 | 283       ); | 
| webmaster@1 | 284       if (variable_get('drupal_http_request_fails', FALSE)) { | 
| webmaster@1 | 285         $requirements['http requests'] = array( | 
| webmaster@1 | 286           'title' => $t('HTTP request status'), | 
| webmaster@1 | 287           'value' => $t('Fails'), | 
| webmaster@1 | 288           'severity' => REQUIREMENT_ERROR, | 
| webmaster@1 | 289           '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.'), | 
| webmaster@1 | 290         ); | 
| webmaster@1 | 291       } | 
| webmaster@1 | 292     } | 
| webmaster@1 | 293     $requirements['update status']['title'] = $t('Update notifications'); | 
| webmaster@1 | 294   } | 
| webmaster@1 | 295 | 
| webmaster@1 | 296   return $requirements; | 
| webmaster@1 | 297 } | 
| webmaster@1 | 298 | 
| webmaster@1 | 299 /** | 
| webmaster@1 | 300  * Implementation of hook_install(). | 
| webmaster@1 | 301  */ | 
| webmaster@1 | 302 function system_install() { | 
| webmaster@1 | 303   if ($GLOBALS['db_type'] == 'pgsql') { | 
| webmaster@1 | 304     // Create unsigned types. | 
| webmaster@1 | 305     db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)"); | 
| webmaster@1 | 306     db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)"); | 
| webmaster@1 | 307     db_query("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)"); | 
| webmaster@1 | 308 | 
| webmaster@1 | 309     // Create functions. | 
| webmaster@1 | 310     db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS | 
| webmaster@1 | 311       \'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\' | 
| webmaster@1 | 312       LANGUAGE \'sql\'' | 
| webmaster@1 | 313     ); | 
| webmaster@1 | 314     db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS | 
| webmaster@1 | 315       \'SELECT greatest($1, greatest($2, $3));\' | 
| webmaster@1 | 316       LANGUAGE \'sql\'' | 
| webmaster@1 | 317     ); | 
| webmaster@1 | 318     if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'"))) { | 
| webmaster@1 | 319       db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS | 
| webmaster@1 | 320         \'SELECT random();\' | 
| webmaster@1 | 321         LANGUAGE \'sql\'' | 
| webmaster@1 | 322       ); | 
| webmaster@1 | 323     } | 
| webmaster@1 | 324 | 
| webmaster@1 | 325     if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'"))) { | 
| webmaster@1 | 326       db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS | 
| webmaster@1 | 327         \'SELECT $1 || $2;\' | 
| webmaster@1 | 328         LANGUAGE \'sql\'' | 
| webmaster@1 | 329       ); | 
| webmaster@1 | 330     } | 
| webmaster@1 | 331     db_query('CREATE OR REPLACE FUNCTION "if"(boolean, text, text) RETURNS text AS | 
| webmaster@1 | 332       \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\' | 
| webmaster@1 | 333       LANGUAGE \'sql\'' | 
| webmaster@1 | 334     ); | 
| webmaster@1 | 335     db_query('CREATE OR REPLACE FUNCTION "if"(boolean, integer, integer) RETURNS integer AS | 
| webmaster@1 | 336       \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\' | 
| webmaster@1 | 337       LANGUAGE \'sql\'' | 
| webmaster@1 | 338     ); | 
| webmaster@1 | 339   } | 
| webmaster@1 | 340 | 
| webmaster@1 | 341   // Create tables. | 
| webmaster@1 | 342   $modules = array('system', 'filter', 'block', 'user', 'node', 'comment', 'taxonomy'); | 
| webmaster@1 | 343   foreach ($modules as $module) { | 
| webmaster@1 | 344     drupal_install_schema($module); | 
| webmaster@1 | 345   } | 
| webmaster@1 | 346 | 
| webmaster@1 | 347   // Load system theme data appropriately. | 
| webmaster@1 | 348   system_theme_data(); | 
| webmaster@1 | 349 | 
| webmaster@1 | 350   // Inserting uid 0 here confuses MySQL -- the next user might be created as | 
| webmaster@1 | 351   // uid 2 which is not what we want. So we insert the first user here, the | 
| webmaster@1 | 352   // anonymous user. uid is 1 here for now, but very soon it will be changed | 
| webmaster@1 | 353   // to 0. | 
| webmaster@1 | 354   db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', ''); | 
| webmaster@1 | 355   // We need some placeholders here as name and mail are uniques and data is | 
| webmaster@1 | 356   // presumed to be a serialized array. Install will change uid 1 immediately | 
| webmaster@1 | 357   // anyways. So we insert the superuser here, the uid is 2 here for now, but | 
| webmaster@1 | 358   // very soon it will be changed to 1. | 
| webmaster@1 | 359   db_query("INSERT INTO {users} (name, mail, created, data) VALUES('%s', '%s', %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', time(), serialize(array())); | 
| webmaster@1 | 360   // This sets the above two users uid 0 (anonymous). We avoid an explicit 0 | 
| webmaster@1 | 361   // otherwise MySQL might insert the next auto_increment value. | 
| webmaster@1 | 362   db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", ''); | 
| webmaster@1 | 363   // This sets uid 1 (superuser). We skip uid 2 but that's not a big problem. | 
| webmaster@1 | 364   db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1'); | 
| webmaster@1 | 365 | 
| webmaster@1 | 366   db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user'); | 
| webmaster@1 | 367   db_query("INSERT INTO {role} (name) VALUES ('%s')", 'authenticated user'); | 
| webmaster@1 | 368 | 
| webmaster@1 | 369   db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (%d, '%s', %d)", 1, 'access content', 0); | 
| webmaster@1 | 370   db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (%d, '%s', %d)", 2, 'access comments, access content, post comments, post comments without approval', 0); | 
| webmaster@1 | 371 | 
| webmaster@1 | 372   db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'theme_default', 's:7:"garland";'); | 
| webmaster@1 | 373   db_query("UPDATE {system} SET status = %d WHERE type = '%s' AND name = '%s'", 1, 'theme', 'garland'); | 
| webmaster@1 | 374   db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'user', '0', 'garland', 1, 0, 'left', '', -1); | 
| webmaster@1 | 375   db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'user', '1', 'garland', 1, 0, 'left', '', -1); | 
| webmaster@1 | 376   db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, pages, cache) VALUES ('%s', '%s', '%s', %d, %d, '%s', '%s', %d)", 'system', '0', 'garland', 1, 10, 'footer', '', -1); | 
| webmaster@1 | 377 | 
| webmaster@1 | 378   db_query("INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, '%s', %d, %d, %d)", 0, 0, 'all', 1, 0, 0); | 
| webmaster@1 | 379 | 
| webmaster@1 | 380   // Add input formats. | 
| webmaster@1 | 381   db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('%s', '%s', %d)", 'Filtered HTML', ',1,2,', 1); | 
| webmaster@1 | 382   db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('%s', '%s', %d)", 'Full HTML', '', 1); | 
| webmaster@1 | 383 | 
| webmaster@1 | 384   // Enable filters for each input format. | 
| webmaster@1 | 385 | 
| webmaster@1 | 386   // Filtered HTML: | 
| webmaster@1 | 387   // URL filter. | 
| webmaster@1 | 388   db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 2, 0); | 
| webmaster@1 | 389   // HTML filter. | 
| webmaster@1 | 390   db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 0, 1); | 
| webmaster@1 | 391   // Line break filter. | 
| webmaster@1 | 392   db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 1, 2); | 
| webmaster@1 | 393   // HTML corrector filter. | 
| webmaster@1 | 394   db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 3, 10); | 
| webmaster@1 | 395 | 
| webmaster@1 | 396   // Full HTML: | 
| webmaster@1 | 397   // URL filter. | 
| webmaster@1 | 398   db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 2, 0); | 
| webmaster@1 | 399   // Line break filter. | 
| webmaster@1 | 400   db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 1, 1); | 
| webmaster@1 | 401   // HTML corrector filter. | 
| webmaster@1 | 402   db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 3, 10); | 
| webmaster@1 | 403 | 
| webmaster@1 | 404   db_query("INSERT INTO {variable} (name, value) VALUES ('%s','%s')", 'filter_html_1', 'i:1;'); | 
| webmaster@1 | 405 | 
| webmaster@1 | 406   db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'node_options_forum', 'a:1:{i:0;s:6:"status";}'); | 
| webmaster@1 | 407 } | 
| webmaster@1 | 408 | 
| webmaster@1 | 409 /** | 
| webmaster@1 | 410  * Implementation of hook_schema(). | 
| webmaster@1 | 411  */ | 
| webmaster@1 | 412 function system_schema() { | 
| webmaster@1 | 413   // NOTE: {variable} needs to be created before all other tables, as | 
| webmaster@1 | 414   // some database drivers, e.g. Oracle and DB2, will require variable_get() | 
| webmaster@1 | 415   // and variable_set() for overcoming some database specific limitations. | 
| webmaster@1 | 416   $schema['variable'] = array( | 
| webmaster@1 | 417     'description' => t('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.'), | 
| webmaster@1 | 418     'fields' => array( | 
| webmaster@1 | 419       'name' => array( | 
| webmaster@1 | 420         'description' => t('The name of the variable.'), | 
| webmaster@1 | 421         'type' => 'varchar', | 
| webmaster@1 | 422         'length' => 128, | 
| webmaster@1 | 423         'not null' => TRUE, | 
| webmaster@1 | 424         'default' => ''), | 
| webmaster@1 | 425       'value' => array( | 
| webmaster@1 | 426         'description' => t('The value of the variable.'), | 
| webmaster@1 | 427         'type' => 'text', | 
| webmaster@1 | 428         'not null' => TRUE, | 
| webmaster@1 | 429         'size' => 'big'), | 
| webmaster@1 | 430       ), | 
| webmaster@1 | 431     'primary key' => array('name'), | 
| webmaster@1 | 432     ); | 
| webmaster@1 | 433 | 
| webmaster@1 | 434   $schema['actions'] = array( | 
| webmaster@1 | 435     'description' => t('Stores action information.'), | 
| webmaster@1 | 436     'fields' => array( | 
| webmaster@1 | 437       'aid' => array( | 
| webmaster@1 | 438         'description' => t('Primary Key: Unique actions ID.'), | 
| webmaster@1 | 439         'type' => 'varchar', | 
| webmaster@1 | 440         'length' => 255, | 
| webmaster@1 | 441         'not null' => TRUE, | 
| webmaster@1 | 442         'default' => '0'), | 
| webmaster@1 | 443       'type' => array( | 
| webmaster@1 | 444         'description' => t('The object that that action acts on (node, user, comment, system or custom types.)'), | 
| webmaster@1 | 445         'type' => 'varchar', | 
| webmaster@1 | 446         'length' => 32, | 
| webmaster@1 | 447         'not null' => TRUE, | 
| webmaster@1 | 448         'default' => ''), | 
| webmaster@1 | 449       'callback' => array( | 
| webmaster@1 | 450         'description' => t('The callback function that executes when the action runs.'), | 
| webmaster@1 | 451         'type' => 'varchar', | 
| webmaster@1 | 452         'length' => 255, | 
| webmaster@1 | 453         'not null' => TRUE, | 
| webmaster@1 | 454         'default' => ''), | 
| webmaster@1 | 455       'parameters' => array( | 
| webmaster@1 | 456         'description' => t('Parameters to be passed to the callback function.'), | 
| webmaster@1 | 457         'type' => 'text', | 
| webmaster@1 | 458         'not null' => TRUE, | 
| webmaster@1 | 459         'size' => 'big'), | 
| webmaster@1 | 460       'description' => array( | 
| webmaster@1 | 461         'description' => t('Description of the action.'), | 
| webmaster@1 | 462         'type' => 'varchar', | 
| webmaster@1 | 463         'length' => 255, | 
| webmaster@1 | 464         'not null' => TRUE, | 
| webmaster@1 | 465         'default' => '0'), | 
| webmaster@1 | 466       ), | 
| webmaster@1 | 467     'primary key' => array('aid'), | 
| webmaster@1 | 468     ); | 
| webmaster@1 | 469 | 
| webmaster@1 | 470   $schema['actions_aid'] = array( | 
| webmaster@1 | 471     'description' => t('Stores action IDs for non-default actions.'), | 
| webmaster@1 | 472     'fields' => array( | 
| webmaster@1 | 473       'aid' => array( | 
| webmaster@1 | 474         'description' => t('Primary Key: Unique actions ID.'), | 
| webmaster@1 | 475         'type' => 'serial', | 
| webmaster@1 | 476         'unsigned' => TRUE, | 
| webmaster@1 | 477         'not null' => TRUE), | 
| webmaster@1 | 478       ), | 
| webmaster@1 | 479     'primary key' => array('aid'), | 
| webmaster@1 | 480     ); | 
| webmaster@1 | 481 | 
| webmaster@1 | 482   $schema['batch'] = array( | 
| webmaster@1 | 483     'description' => t('Stores details about batches (processes that run in multiple HTTP requests).'), | 
| webmaster@1 | 484     'fields' => array( | 
| webmaster@1 | 485       'bid' => array( | 
| webmaster@1 | 486         'description' => t('Primary Key: Unique batch ID.'), | 
| webmaster@1 | 487         'type' => 'serial', | 
| webmaster@1 | 488         'unsigned' => TRUE, | 
| webmaster@1 | 489         'not null' => TRUE), | 
| webmaster@1 | 490       'token' => array( | 
| webmaster@1 | 491         'description' => t("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."), | 
| webmaster@1 | 492         'type' => 'varchar', | 
| webmaster@1 | 493         'length' => 64, | 
| webmaster@1 | 494         'not null' => TRUE), | 
| webmaster@1 | 495       'timestamp' => array( | 
| webmaster@1 | 496         'description' => t('A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.'), | 
| webmaster@1 | 497         'type' => 'int', | 
| webmaster@1 | 498         'not null' => TRUE), | 
| webmaster@1 | 499       'batch' => array( | 
| webmaster@1 | 500         'description' => t('A serialized array containing the processing data for the batch.'), | 
| webmaster@1 | 501         'type' => 'text', | 
| webmaster@1 | 502         'not null' => FALSE, | 
| webmaster@1 | 503         'size' => 'big') | 
| webmaster@1 | 504       ), | 
| webmaster@1 | 505     'primary key' => array('bid'), | 
| webmaster@1 | 506     'indexes' => array('token' => array('token')), | 
| webmaster@1 | 507     ); | 
| webmaster@1 | 508 | 
| webmaster@1 | 509   $schema['cache'] = array( | 
| webmaster@1 | 510     'description' => t('Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.'), | 
| webmaster@1 | 511     'fields' => array( | 
| webmaster@1 | 512       'cid' => array( | 
| webmaster@1 | 513         'description' => t('Primary Key: Unique cache ID.'), | 
| webmaster@1 | 514         'type' => 'varchar', | 
| webmaster@1 | 515         'length' => 255, | 
| webmaster@1 | 516         'not null' => TRUE, | 
| webmaster@1 | 517         'default' => ''), | 
| webmaster@1 | 518       'data' => array( | 
| webmaster@1 | 519         'description' => t('A collection of data to cache.'), | 
| webmaster@1 | 520         'type' => 'blob', | 
| webmaster@1 | 521         'not null' => FALSE, | 
| webmaster@1 | 522         'size' => 'big'), | 
| webmaster@1 | 523       'expire' => array( | 
| webmaster@1 | 524         'description' => t('A Unix timestamp indicating when the cache entry should expire, or 0 for never.'), | 
| webmaster@1 | 525         'type' => 'int', | 
| webmaster@1 | 526         'not null' => TRUE, | 
| webmaster@1 | 527         'default' => 0), | 
| webmaster@1 | 528       'created' => array( | 
| webmaster@1 | 529         'description' => t('A Unix timestamp indicating when the cache entry was created.'), | 
| webmaster@1 | 530         'type' => 'int', | 
| webmaster@1 | 531         'not null' => TRUE, | 
| webmaster@1 | 532         'default' => 0), | 
| webmaster@1 | 533       'headers' => array( | 
| webmaster@1 | 534         'description' => t('Any custom HTTP headers to be added to cached data.'), | 
| webmaster@1 | 535         'type' => 'text', | 
| webmaster@1 | 536         'not null' => FALSE), | 
| webmaster@1 | 537       'serialized' => array( | 
| webmaster@1 | 538         'description' => t('A flag to indicate whether content is serialized (1) or not (0).'), | 
| webmaster@1 | 539         'type' => 'int', | 
| webmaster@1 | 540         'size' => 'small', | 
| webmaster@1 | 541         'not null' => TRUE, | 
| webmaster@1 | 542         'default' => 0) | 
| webmaster@1 | 543       ), | 
| webmaster@1 | 544     'indexes' => array('expire' => array('expire')), | 
| webmaster@1 | 545     'primary key' => array('cid'), | 
| webmaster@1 | 546     ); | 
| webmaster@1 | 547 | 
| webmaster@1 | 548   $schema['cache_form'] = $schema['cache']; | 
| webmaster@1 | 549   $schema['cache_form']['description'] = t('Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.'); | 
| webmaster@1 | 550   $schema['cache_page'] = $schema['cache']; | 
| webmaster@1 | 551   $schema['cache_page']['description'] = t('Cache table used to store compressed pages for anonymous users, if page caching is enabled.'); | 
| webmaster@1 | 552   $schema['cache_menu'] = $schema['cache']; | 
| webmaster@1 | 553   $schema['cache_menu']['description'] = t('Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.'); | 
| webmaster@1 | 554 | 
| webmaster@1 | 555   $schema['files'] = array( | 
| webmaster@1 | 556     'description' => t('Stores information for uploaded files.'), | 
| webmaster@1 | 557     'fields' => array( | 
| webmaster@1 | 558       'fid' => array( | 
| webmaster@1 | 559         'description' => t('Primary Key: Unique files ID.'), | 
| webmaster@1 | 560         'type' => 'serial', | 
| webmaster@1 | 561         'unsigned' => TRUE, | 
| webmaster@1 | 562         'not null' => TRUE), | 
| webmaster@1 | 563       'uid' => array( | 
| webmaster@1 | 564         'description' => t('The {users}.uid of the user who is associated with the file.'), | 
| webmaster@1 | 565         'type' => 'int', | 
| webmaster@1 | 566         'unsigned' => TRUE, | 
| webmaster@1 | 567         'not null' => TRUE, | 
| webmaster@1 | 568         'default' => 0), | 
| webmaster@1 | 569       'filename' => array( | 
| webmaster@1 | 570         'description' => t('Name of the file.'), | 
| webmaster@1 | 571         'type' => 'varchar', | 
| webmaster@1 | 572         'length' => 255, | 
| webmaster@1 | 573         'not null' => TRUE, | 
| webmaster@1 | 574         'default' => ''), | 
| webmaster@1 | 575       'filepath' => array( | 
| webmaster@1 | 576         'description' => t('Path of the file relative to Drupal root.'), | 
| webmaster@1 | 577         'type' => 'varchar', | 
| webmaster@1 | 578         'length' => 255, | 
| webmaster@1 | 579         'not null' => TRUE, | 
| webmaster@1 | 580         'default' => ''), | 
| webmaster@1 | 581       'filemime' => array( | 
| webmaster@1 | 582         'description' => t('The file MIME type.'), | 
| webmaster@1 | 583         'type' => 'varchar', | 
| webmaster@1 | 584         'length' => 255, | 
| webmaster@1 | 585         'not null' => TRUE, | 
| webmaster@1 | 586         'default' => ''), | 
| webmaster@1 | 587       'filesize' => array( | 
| webmaster@1 | 588         'description' => t('The size of the file in bytes.'), | 
| webmaster@1 | 589         'type' => 'int', | 
| webmaster@1 | 590         'unsigned' => TRUE, | 
| webmaster@1 | 591         'not null' => TRUE, | 
| webmaster@1 | 592         'default' => 0), | 
| webmaster@1 | 593       'status' => array( | 
| webmaster@1 | 594         'description' => t('A flag indicating whether file is temporary (1) or permanent (0).'), | 
| webmaster@1 | 595         'type' => 'int', | 
| webmaster@1 | 596         'not null' => TRUE, | 
| webmaster@1 | 597         'default' => 0), | 
| webmaster@1 | 598       'timestamp' => array( | 
| webmaster@1 | 599         'description' => t('UNIX timestamp for when the file was added.'), | 
| webmaster@1 | 600         'type' => 'int', | 
| webmaster@1 | 601         'unsigned' => TRUE, | 
| webmaster@1 | 602         'not null' => TRUE, | 
| webmaster@1 | 603         'default' => 0), | 
| webmaster@1 | 604       ), | 
| webmaster@1 | 605     'indexes' => array( | 
| webmaster@1 | 606       'uid' => array('uid'), | 
| webmaster@1 | 607       'status' => array('status'), | 
| webmaster@1 | 608       'timestamp' => array('timestamp'), | 
| webmaster@1 | 609       ), | 
| webmaster@1 | 610     'primary key' => array('fid'), | 
| webmaster@1 | 611     ); | 
| webmaster@1 | 612 | 
| webmaster@1 | 613   $schema['flood'] = array( | 
| webmaster@1 | 614     'description' => t('Flood controls the threshold of events, such as the number of contact attempts.'), | 
| webmaster@1 | 615     'fields' => array( | 
| webmaster@1 | 616       'fid' => array( | 
| webmaster@1 | 617         'description' => t('Unique flood event ID.'), | 
| webmaster@1 | 618         'type' => 'serial', | 
| webmaster@1 | 619         'not null' => TRUE), | 
| webmaster@1 | 620       'event' => array( | 
| webmaster@1 | 621         'description' => t('Name of event (e.g. contact).'), | 
| webmaster@1 | 622         'type' => 'varchar', | 
| webmaster@1 | 623         'length' => 64, | 
| webmaster@1 | 624         'not null' => TRUE, | 
| webmaster@1 | 625         'default' => ''), | 
| webmaster@1 | 626       'hostname' => array( | 
| webmaster@1 | 627         'description' => t('Hostname of the visitor.'), | 
| webmaster@1 | 628         'type' => 'varchar', | 
| webmaster@1 | 629         'length' => 128, | 
| webmaster@1 | 630         'not null' => TRUE, | 
| webmaster@1 | 631         'default' => ''), | 
| webmaster@1 | 632       'timestamp' => array( | 
| webmaster@1 | 633         'description' => t('Timestamp of the event.'), | 
| webmaster@1 | 634         'type' => 'int', | 
| webmaster@1 | 635         'not null' => TRUE, | 
| webmaster@1 | 636         'default' => 0) | 
| webmaster@1 | 637       ), | 
| webmaster@1 | 638     'primary key' => array('fid'), | 
| webmaster@1 | 639     'indexes' => array( | 
| webmaster@1 | 640       'allow' => array('event', 'hostname', 'timestamp'), | 
| webmaster@1 | 641     ), | 
| webmaster@1 | 642     ); | 
| webmaster@1 | 643 | 
| webmaster@1 | 644   $schema['history'] = array( | 
| webmaster@1 | 645     'description' => t('A record of which {users} have read which {node}s.'), | 
| webmaster@1 | 646     'fields' => array( | 
| webmaster@1 | 647       'uid' => array( | 
| webmaster@1 | 648         'description' => t('The {users}.uid that read the {node} nid.'), | 
| webmaster@1 | 649         'type' => 'int', | 
| webmaster@1 | 650         'not null' => TRUE, | 
| webmaster@1 | 651         'default' => 0), | 
| webmaster@1 | 652       'nid' => array( | 
| webmaster@1 | 653         'description' => t('The {node}.nid that was read.'), | 
| webmaster@1 | 654         'type' => 'int', | 
| webmaster@1 | 655         'not null' => TRUE, | 
| webmaster@1 | 656         'default' => 0), | 
| webmaster@1 | 657       'timestamp' => array( | 
| webmaster@1 | 658         'description' => t('The Unix timestamp at which the read occurred.'), | 
| webmaster@1 | 659         'type' => 'int', | 
| webmaster@1 | 660         'not null' => TRUE, | 
| webmaster@1 | 661         'default' => 0) | 
| webmaster@1 | 662       ), | 
| webmaster@1 | 663     'primary key' => array('uid', 'nid'), | 
| webmaster@1 | 664     'indexes' => array( | 
| webmaster@1 | 665       'nid' => array('nid'), | 
| webmaster@1 | 666     ), | 
| webmaster@1 | 667     ); | 
| webmaster@1 | 668   $schema['menu_router'] = array( | 
| webmaster@1 | 669     'description' => t('Maps paths to various callbacks (access, page and title)'), | 
| webmaster@1 | 670     'fields' => array( | 
| webmaster@1 | 671       'path' => array( | 
| webmaster@1 | 672         'description' => t('Primary Key: the Drupal path this entry describes'), | 
| webmaster@1 | 673         'type' => 'varchar', | 
| webmaster@1 | 674         'length' => 255, | 
| webmaster@1 | 675         'not null' => TRUE, | 
| webmaster@1 | 676         'default' => ''), | 
| webmaster@1 | 677       'load_functions' => array( | 
| webmaster@1 | 678         'description' => t('A serialized array of function names (like node_load) to be called to load an object corresponding to a part of the current path.'), | 
| webmaster@1 | 679         'type' => 'varchar', | 
| webmaster@1 | 680         'length' => 255, | 
| webmaster@1 | 681         'not null' => TRUE, | 
| webmaster@1 | 682         'default' => ''), | 
| webmaster@1 | 683       'to_arg_functions' => array( | 
| webmaster@1 | 684         'description' => t('A serialized array of function names (like user_current_to_arg) to be called to replace a part of the router path with another string.'), | 
| webmaster@1 | 685         'type' => 'varchar', | 
| webmaster@1 | 686         'length' => 255, | 
| webmaster@1 | 687         'not null' => TRUE, | 
| webmaster@1 | 688         'default' => ''), | 
| webmaster@1 | 689       'access_callback' => array( | 
| webmaster@1 | 690         'description' => t('The callback which determines the access to this router path. Defaults to user_access.'), | 
| webmaster@1 | 691         'type' => 'varchar', | 
| webmaster@1 | 692         'length' => 255, | 
| webmaster@1 | 693         'not null' => TRUE, | 
| webmaster@1 | 694         'default' => ''), | 
| webmaster@1 | 695       'access_arguments' => array( | 
| webmaster@1 | 696         'description' => t('A serialized array of arguments for the access callback.'), | 
| webmaster@1 | 697         'type' => 'text', | 
| webmaster@1 | 698         'not null' => FALSE), | 
| webmaster@1 | 699       'page_callback' => array( | 
| webmaster@1 | 700         'description' => t('The name of the function that renders the page.'), | 
| webmaster@1 | 701         'type' => 'varchar', | 
| webmaster@1 | 702         'length' => 255, | 
| webmaster@1 | 703         'not null' => TRUE, | 
| webmaster@1 | 704         'default' => ''), | 
| webmaster@1 | 705       'page_arguments' => array( | 
| webmaster@1 | 706         'description' => t('A serialized array of arguments for the page callback.'), | 
| webmaster@1 | 707         'type' => 'text', | 
| webmaster@1 | 708         'not null' => FALSE), | 
| webmaster@1 | 709       'fit' => array( | 
| webmaster@1 | 710         'description' => t('A numeric representation of how specific the path is.'), | 
| webmaster@1 | 711         'type' => 'int', | 
| webmaster@1 | 712         'not null' => TRUE, | 
| webmaster@1 | 713         'default' => 0), | 
| webmaster@1 | 714       'number_parts' => array( | 
| webmaster@1 | 715         'description' => t('Number of parts in this router path.'), | 
| webmaster@1 | 716         'type' => 'int', | 
| webmaster@1 | 717         'not null' => TRUE, | 
| webmaster@1 | 718         'default' => 0, | 
| webmaster@1 | 719         'size' => 'small'), | 
| webmaster@1 | 720       'tab_parent' => array( | 
| webmaster@1 | 721         'description' => t('Only for local tasks (tabs) - the router path of the parent page (which may also be a local task).'), | 
| webmaster@1 | 722         'type' => 'varchar', | 
| webmaster@1 | 723         'length' => 255, | 
| webmaster@1 | 724         'not null' => TRUE, | 
| webmaster@1 | 725         'default' => ''), | 
| webmaster@1 | 726       'tab_root' => array( | 
| webmaster@1 | 727         'description' => t('Router path of the closest non-tab parent page. For pages that are not local tasks, this will be the same as the path.'), | 
| webmaster@1 | 728         'type' => 'varchar', | 
| webmaster@1 | 729         'length' => 255, | 
| webmaster@1 | 730         'not null' => TRUE, | 
| webmaster@1 | 731         'default' => ''), | 
| webmaster@1 | 732       'title' => array( | 
| webmaster@1 | 733         'description' => t('The title for the current page, or the title for the tab if this is a local task.'), | 
| webmaster@1 | 734         'type' => 'varchar', | 
| webmaster@1 | 735         'length' => 255, | 
| webmaster@1 | 736         'not null' => TRUE, | 
| webmaster@1 | 737         'default' => ''), | 
| webmaster@1 | 738       'title_callback' => array( | 
| webmaster@1 | 739         'description' => t('A function which will alter the title. Defaults to t()'), | 
| webmaster@1 | 740         'type' => 'varchar', | 
| webmaster@1 | 741         'length' => 255, | 
| webmaster@1 | 742         'not null' => TRUE, | 
| webmaster@1 | 743         'default' => ''), | 
| webmaster@1 | 744       'title_arguments' => array( | 
| webmaster@1 | 745         'description' => t('A serialized array of arguments for the title callback. If empty, the title will be used as the sole argument for the title callback.'), | 
| webmaster@1 | 746         'type' => 'varchar', | 
| webmaster@1 | 747         'length' => 255, | 
| webmaster@1 | 748         'not null' => TRUE, | 
| webmaster@1 | 749         'default' => ''), | 
| webmaster@1 | 750       'type' => array( | 
| webmaster@1 | 751         'description' => t('Numeric representation of the type of the menu item, like MENU_LOCAL_TASK.'), | 
| webmaster@1 | 752         'type' => 'int', | 
| webmaster@1 | 753         'not null' => TRUE, | 
| webmaster@1 | 754         'default' => 0), | 
| webmaster@1 | 755       'block_callback' => array( | 
| webmaster@1 | 756         'description' => t('Name of a function used to render the block on the system administration page for this item.'), | 
| webmaster@1 | 757         'type' => 'varchar', | 
| webmaster@1 | 758         'length' => 255, | 
| webmaster@1 | 759         'not null' => TRUE, | 
| webmaster@1 | 760         'default' => ''), | 
| webmaster@1 | 761       'description' => array( | 
| webmaster@1 | 762         'description' => t('A description of this item.'), | 
| webmaster@1 | 763         'type' => 'text', | 
| webmaster@1 | 764         'not null' => TRUE), | 
| webmaster@1 | 765       'position' => array( | 
| webmaster@1 | 766         'description' => t('The position of the block (left or right) on the system administration page for this item.'), | 
| webmaster@1 | 767         'type' => 'varchar', | 
| webmaster@1 | 768         'length' => 255, | 
| webmaster@1 | 769         'not null' => TRUE, | 
| webmaster@1 | 770         'default' => ''), | 
| webmaster@1 | 771       'weight' => array( | 
| webmaster@1 | 772         'description' => t('Weight of the element. Lighter weights are higher up, heavier weights go down.'), | 
| webmaster@1 | 773         'type' => 'int', | 
| webmaster@1 | 774         'not null' => TRUE, | 
| webmaster@1 | 775         'default' => 0), | 
| webmaster@1 | 776       'file' => array( | 
| webmaster@1 | 777         'description' => t('The file to include for this element, usually the page callback function lives in this file.'), | 
| webmaster@1 | 778         'type' => 'text', | 
| webmaster@1 | 779         'size' => 'medium') | 
| webmaster@1 | 780       ), | 
| webmaster@1 | 781     'indexes' => array( | 
| webmaster@1 | 782       'fit' => array('fit'), | 
| webmaster@1 | 783       'tab_parent' => array('tab_parent') | 
| webmaster@1 | 784       ), | 
| webmaster@1 | 785     'primary key' => array('path'), | 
| webmaster@1 | 786     ); | 
| webmaster@1 | 787 | 
| webmaster@1 | 788   $schema['menu_links'] = array( | 
| webmaster@1 | 789     'description' => t('Contains the individual links within a menu.'), | 
| webmaster@1 | 790     'fields' => array( | 
| webmaster@1 | 791      'menu_name' => array( | 
| webmaster@1 | 792         'description' => t("The menu name. All links with the same menu name (such as 'navigation') are part of the same menu."), | 
| webmaster@1 | 793         'type' => 'varchar', | 
| webmaster@1 | 794         'length' => 32, | 
| webmaster@1 | 795         'not null' => TRUE, | 
| webmaster@1 | 796         'default' => ''), | 
| webmaster@1 | 797       'mlid' => array( | 
| webmaster@1 | 798         'description' => t('The menu link ID (mlid) is the integer primary key.'), | 
| webmaster@1 | 799         'type' => 'serial', | 
| webmaster@1 | 800         'unsigned' => TRUE, | 
| webmaster@1 | 801         'not null' => TRUE), | 
| webmaster@1 | 802       'plid' => array( | 
| webmaster@1 | 803         'description' => t('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.'), | 
| webmaster@1 | 804         'type' => 'int', | 
| webmaster@1 | 805         'unsigned' => TRUE, | 
| webmaster@1 | 806         'not null' => TRUE, | 
| webmaster@1 | 807         'default' => 0), | 
| webmaster@1 | 808       'link_path' => array( | 
| webmaster@1 | 809         'description' => t('The Drupal path or external path this link points to.'), | 
| webmaster@1 | 810         'type' => 'varchar', | 
| webmaster@1 | 811         'length' => 255, | 
| webmaster@1 | 812         'not null' => TRUE, | 
| webmaster@1 | 813         'default' => ''), | 
| webmaster@1 | 814       'router_path' => array( | 
| webmaster@1 | 815         'description' => t('For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.'), | 
| webmaster@1 | 816         'type' => 'varchar', | 
| webmaster@1 | 817         'length' => 255, | 
| webmaster@1 | 818         'not null' => TRUE, | 
| webmaster@1 | 819         'default' => ''), | 
| webmaster@1 | 820       'link_title' => array( | 
| webmaster@1 | 821       'description' => t('The text displayed for the link, which may be modified by a title callback stored in {menu_router}.'), | 
| webmaster@1 | 822         'type' => 'varchar', | 
| webmaster@1 | 823         'length' => 255, | 
| webmaster@1 | 824         'not null' => TRUE, | 
| webmaster@1 | 825         'default' => ''), | 
| webmaster@1 | 826       'options' => array( | 
| webmaster@1 | 827         'description' => t('A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.'), | 
| webmaster@1 | 828         'type' => 'text', | 
| webmaster@1 | 829         'not null' => FALSE), | 
| webmaster@1 | 830       'module' => array( | 
| webmaster@1 | 831         'description' => t('The name of the module that generated this link.'), | 
| webmaster@1 | 832         'type' => 'varchar', | 
| webmaster@1 | 833         'length' => 255, | 
| webmaster@1 | 834         'not null' => TRUE, | 
| webmaster@1 | 835         'default' => 'system'), | 
| webmaster@1 | 836       'hidden' => array( | 
| webmaster@1 | 837         'description' => t('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)'), | 
| webmaster@1 | 838         'type' => 'int', | 
| webmaster@1 | 839         'not null' => TRUE, | 
| webmaster@1 | 840         'default' => 0, | 
| webmaster@1 | 841         'size' => 'small'), | 
| webmaster@1 | 842       'external' => array( | 
| webmaster@1 | 843         'description' => t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).'), | 
| webmaster@1 | 844         'type' => 'int', | 
| webmaster@1 | 845         'not null' => TRUE, | 
| webmaster@1 | 846         'default' => 0, | 
| webmaster@1 | 847         'size' => 'small'), | 
| webmaster@1 | 848       'has_children' => array( | 
| webmaster@1 | 849         'description' => t('Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).'), | 
| webmaster@1 | 850         'type' => 'int', | 
| webmaster@1 | 851         'not null' => TRUE, | 
| webmaster@1 | 852         'default' => 0, | 
| webmaster@1 | 853         'size' => 'small'), | 
| webmaster@1 | 854       'expanded' => array( | 
| webmaster@1 | 855         'description' => t('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)'), | 
| webmaster@1 | 856         'type' => 'int', | 
| webmaster@1 | 857         'not null' => TRUE, | 
| webmaster@1 | 858         'default' => 0, | 
| webmaster@1 | 859         'size' => 'small'), | 
| webmaster@1 | 860       'weight' => array( | 
| webmaster@1 | 861         'description' => t('Link weight among links in the same menu at the same depth.'), | 
| webmaster@1 | 862         'type' => 'int', | 
| webmaster@1 | 863         'not null' => TRUE, | 
| webmaster@1 | 864         'default' => 0), | 
| webmaster@1 | 865       'depth' => array( | 
| webmaster@1 | 866         'description' => t('The depth relative to the top level. A link with plid == 0 will have depth == 1.'), | 
| webmaster@1 | 867         'type' => 'int', | 
| webmaster@1 | 868         'not null' => TRUE, | 
| webmaster@1 | 869         'default' => 0, | 
| webmaster@1 | 870         'size' => 'small'), | 
| webmaster@1 | 871       'customized' => array( | 
| webmaster@1 | 872         'description' => t('A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).'), | 
| webmaster@1 | 873         'type' => 'int', | 
| webmaster@1 | 874         'not null' => TRUE, | 
| webmaster@1 | 875         'default' => 0, | 
| webmaster@1 | 876         'size' => 'small'), | 
| webmaster@1 | 877       'p1' => array( | 
| webmaster@1 | 878         'description' => t('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.'), | 
| webmaster@1 | 879         'type' => 'int', | 
| webmaster@1 | 880         'unsigned' => TRUE, | 
| webmaster@1 | 881         'not null' => TRUE, | 
| webmaster@1 | 882         'default' => 0), | 
| webmaster@1 | 883       'p2' => array( | 
| webmaster@1 | 884         'description' => t('The second mlid in the materialized path. See p1.'), | 
| webmaster@1 | 885         'type' => 'int', | 
| webmaster@1 | 886         'unsigned' => TRUE, | 
| webmaster@1 | 887         'not null' => TRUE, | 
| webmaster@1 | 888         'default' => 0), | 
| webmaster@1 | 889       'p3' => array( | 
| webmaster@1 | 890         'description' => t('The third mlid in the materialized path. See p1.'), | 
| webmaster@1 | 891         'type' => 'int', | 
| webmaster@1 | 892         'unsigned' => TRUE, | 
| webmaster@1 | 893         'not null' => TRUE, | 
| webmaster@1 | 894         'default' => 0), | 
| webmaster@1 | 895       'p4' => array( | 
| webmaster@1 | 896         'description' => t('The fourth mlid in the materialized path. See p1.'), | 
| webmaster@1 | 897         'type' => 'int', | 
| webmaster@1 | 898         'unsigned' => TRUE, | 
| webmaster@1 | 899         'not null' => TRUE, | 
| webmaster@1 | 900         'default' => 0), | 
| webmaster@1 | 901       'p5' => array( | 
| webmaster@1 | 902         'description' => t('The fifth mlid in the materialized path. See p1.'), | 
| webmaster@1 | 903         'type' => 'int', | 
| webmaster@1 | 904         'unsigned' => TRUE, | 
| webmaster@1 | 905         'not null' => TRUE, | 
| webmaster@1 | 906         'default' => 0), | 
| webmaster@1 | 907       'p6' => array( | 
| webmaster@1 | 908         'description' => t('The sixth mlid in the materialized path. See p1.'), | 
| webmaster@1 | 909         'type' => 'int', | 
| webmaster@1 | 910         'unsigned' => TRUE, | 
| webmaster@1 | 911         'not null' => TRUE, | 
| webmaster@1 | 912         'default' => 0), | 
| webmaster@1 | 913       'p7' => array( | 
| webmaster@1 | 914         'description' => t('The seventh mlid in the materialized path. See p1.'), | 
| webmaster@1 | 915         'type' => 'int', | 
| webmaster@1 | 916         'unsigned' => TRUE, | 
| webmaster@1 | 917         'not null' => TRUE, | 
| webmaster@1 | 918         'default' => 0), | 
| webmaster@1 | 919       'p8' => array( | 
| webmaster@1 | 920         'description' => t('The eighth mlid in the materialized path. See p1.'), | 
| webmaster@1 | 921         'type' => 'int', | 
| webmaster@1 | 922         'unsigned' => TRUE, | 
| webmaster@1 | 923         'not null' => TRUE, | 
| webmaster@1 | 924         'default' => 0), | 
| webmaster@1 | 925       'p9' => array( | 
| webmaster@1 | 926         'description' => t('The ninth mlid in the materialized path. See p1.'), | 
| webmaster@1 | 927         'type' => 'int', | 
| webmaster@1 | 928         'unsigned' => TRUE, | 
| webmaster@1 | 929         'not null' => TRUE, | 
| webmaster@1 | 930         'default' => 0), | 
| webmaster@1 | 931       'updated' => array( | 
| webmaster@1 | 932         'description' => t('Flag that indicates that this link was generated during the update from Drupal 5.'), | 
| webmaster@1 | 933         'type' => 'int', | 
| webmaster@1 | 934         'not null' => TRUE, | 
| webmaster@1 | 935         'default' => 0, | 
| webmaster@1 | 936         'size' => 'small'), | 
| webmaster@1 | 937       ), | 
| webmaster@1 | 938     'indexes' => array( | 
| webmaster@1 | 939       'path_menu' => array(array('link_path', 128), 'menu_name'), | 
| webmaster@1 | 940       'menu_plid_expand_child' => array( | 
| webmaster@1 | 941         'menu_name', 'plid', 'expanded', 'has_children'), | 
| webmaster@1 | 942       'menu_parents' => array( | 
| webmaster@1 | 943         'menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'), | 
| webmaster@1 | 944       'router_path' => array(array('router_path', 128)), | 
| webmaster@1 | 945       ), | 
| webmaster@1 | 946     'primary key' => array('mlid'), | 
| webmaster@1 | 947     ); | 
| webmaster@1 | 948 | 
| webmaster@1 | 949   $schema['sessions'] = array( | 
| webmaster@1 | 950     'description' => t("Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated."), | 
| webmaster@1 | 951     'fields' => array( | 
| webmaster@1 | 952       'uid' => array( | 
| webmaster@1 | 953         'description' => t('The {users}.uid corresponding to a session, or 0 for anonymous user.'), | 
| webmaster@1 | 954         'type' => 'int', | 
| webmaster@1 | 955         'unsigned' => TRUE, | 
| webmaster@1 | 956         'not null' => TRUE), | 
| webmaster@1 | 957       'sid' => array( | 
| webmaster@1 | 958         'description' => t("Primary key: A session ID. The value is generated by PHP's Session API."), | 
| webmaster@1 | 959         'type' => 'varchar', | 
| webmaster@1 | 960         'length' => 64, | 
| webmaster@1 | 961         'not null' => TRUE, | 
| webmaster@1 | 962         'default' => ''), | 
| webmaster@1 | 963       'hostname' => array( | 
| webmaster@1 | 964         'description' => t('The IP address that last used this session ID (sid).'), | 
| webmaster@1 | 965         'type' => 'varchar', | 
| webmaster@1 | 966         'length' => 128, | 
| webmaster@1 | 967         'not null' => TRUE, | 
| webmaster@1 | 968         'default' => ''), | 
| webmaster@1 | 969       'timestamp' => array( | 
| webmaster@1 | 970         'description' => t('The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.'), | 
| webmaster@1 | 971         'type' => 'int', | 
| webmaster@1 | 972         'not null' => TRUE, | 
| webmaster@1 | 973         'default' => 0), | 
| webmaster@1 | 974       'cache' => array( | 
| webmaster@1 | 975         'description' => t("The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get()."), | 
| webmaster@1 | 976         'type' => 'int', | 
| webmaster@1 | 977         'not null' => TRUE, | 
| webmaster@1 | 978         'default' => 0), | 
| webmaster@1 | 979       'session' => array( | 
| webmaster@1 | 980         'description' => t('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.'), | 
| webmaster@1 | 981         'type' => 'text', | 
| webmaster@1 | 982         'not null' => FALSE, | 
| webmaster@1 | 983         'size' => 'big') | 
| webmaster@1 | 984       ), | 
| webmaster@1 | 985     'primary key' => array('sid'), | 
| webmaster@1 | 986     'indexes' => array( | 
| webmaster@1 | 987       'timestamp' => array('timestamp'), | 
| webmaster@1 | 988       'uid' => array('uid') | 
| webmaster@1 | 989       ), | 
| webmaster@1 | 990     ); | 
| webmaster@1 | 991 | 
| webmaster@1 | 992   $schema['system'] = array( | 
| webmaster@1 | 993     'description' => t("A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system."), | 
| webmaster@1 | 994     'fields' => array( | 
| webmaster@1 | 995       'filename' => array( | 
| webmaster@1 | 996         'description' => t('The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.'), | 
| webmaster@1 | 997         'type' => 'varchar', | 
| webmaster@1 | 998         'length' => 255, | 
| webmaster@1 | 999         'not null' => TRUE, | 
| webmaster@1 | 1000         'default' => ''), | 
| webmaster@1 | 1001       'name' => array( | 
| webmaster@1 | 1002         'description' => t('The name of the item; e.g. node.'), | 
| webmaster@1 | 1003         'type' => 'varchar', | 
| webmaster@1 | 1004         'length' => 255, | 
| webmaster@1 | 1005         'not null' => TRUE, | 
| webmaster@1 | 1006         'default' => ''), | 
| webmaster@1 | 1007       'type' => array( | 
| webmaster@1 | 1008         'description' => t('The type of the item, either module, theme, or theme_engine.'), | 
| webmaster@1 | 1009         'type' => 'varchar', | 
| webmaster@1 | 1010         'length' => 255, | 
| webmaster@1 | 1011         'not null' => TRUE, | 
| webmaster@1 | 1012         'default' => ''), | 
| webmaster@1 | 1013       'owner' => array( | 
| webmaster@1 | 1014         'description' => t("A theme's 'parent'. Can be either a theme or an engine."), | 
| webmaster@1 | 1015         'type' => 'varchar', | 
| webmaster@1 | 1016         'length' => 255, | 
| webmaster@1 | 1017         'not null' => TRUE, | 
| webmaster@1 | 1018         'default' => ''), | 
| webmaster@1 | 1019       'status' => array( | 
| webmaster@1 | 1020         'description' => t('Boolean indicating whether or not this item is enabled.'), | 
| webmaster@1 | 1021         'type' => 'int', | 
| webmaster@1 | 1022         'not null' => TRUE, | 
| webmaster@1 | 1023         'default' => 0), | 
| webmaster@1 | 1024       'throttle' => array( | 
| webmaster@1 | 1025         'description' => t('Boolean indicating whether this item is disabled when the throttle.module disables throttleable items.'), | 
| webmaster@1 | 1026         'type' => 'int', | 
| webmaster@1 | 1027         'not null' => TRUE, | 
| webmaster@1 | 1028         'default' => 0, | 
| webmaster@1 | 1029         'size' => 'tiny'), | 
| webmaster@1 | 1030       'bootstrap' => array( | 
| webmaster@1 | 1031         'description' => t("Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted)."), | 
| webmaster@1 | 1032         'type' => 'int', | 
| webmaster@1 | 1033         'not null' => TRUE, | 
| webmaster@1 | 1034         'default' => 0), | 
| webmaster@1 | 1035       'schema_version' => array( | 
| webmaster@1 | 1036         'description' => t("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."), | 
| webmaster@1 | 1037         'type' => 'int', | 
| webmaster@1 | 1038         'not null' => TRUE, | 
| webmaster@1 | 1039         'default' => -1, | 
| webmaster@1 | 1040         'size' => 'small'), | 
| webmaster@1 | 1041       'weight' => array( | 
| webmaster@1 | 1042         'description' => t("The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name."), | 
| webmaster@1 | 1043         'type' => 'int', | 
| webmaster@1 | 1044         'not null' => TRUE, | 
| webmaster@1 | 1045         'default' => 0), | 
| webmaster@1 | 1046       'info' => array( | 
| webmaster@1 | 1047         'description' => t("A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, dependents, and php."), | 
| webmaster@1 | 1048         'type' => 'text', | 
| webmaster@1 | 1049         'not null' => FALSE) | 
| webmaster@1 | 1050       ), | 
| webmaster@1 | 1051     'primary key' => array('filename'), | 
| webmaster@1 | 1052     'indexes' => | 
| webmaster@1 | 1053       array( | 
| webmaster@1 | 1054         'modules' => array(array('type', 12), 'status', 'weight', 'filename'), | 
| webmaster@1 | 1055         'bootstrap' => array(array('type', 12), 'status', 'bootstrap', 'weight', 'filename'), | 
| webmaster@1 | 1056       ), | 
| webmaster@1 | 1057     ); | 
| webmaster@1 | 1058 | 
| webmaster@1 | 1059   $schema['url_alias'] = array( | 
| webmaster@1 | 1060     'description' => t('A list of URL aliases for Drupal paths; a user may visit either the source or destination path.'), | 
| webmaster@1 | 1061     'fields' => array( | 
| webmaster@1 | 1062       'pid' => array( | 
| webmaster@1 | 1063         'description' => t('A unique path alias identifier.'), | 
| webmaster@1 | 1064         'type' => 'serial', | 
| webmaster@1 | 1065         'unsigned' => TRUE, | 
| webmaster@1 | 1066         'not null' => TRUE), | 
| webmaster@1 | 1067       'src' => array( | 
| webmaster@1 | 1068         'description' => t('The Drupal path this alias is for; e.g. node/12.'), | 
| webmaster@1 | 1069         'type' => 'varchar', | 
| webmaster@1 | 1070         'length' => 128, | 
| webmaster@1 | 1071         'not null' => TRUE, | 
| webmaster@1 | 1072         'default' => ''), | 
| webmaster@1 | 1073       'dst' => array( | 
| webmaster@1 | 1074         'description' => t('The alias for this path; e.g. title-of-the-story.'), | 
| webmaster@1 | 1075         'type' => 'varchar', | 
| webmaster@1 | 1076         'length' => 128, | 
| webmaster@1 | 1077         'not null' => TRUE, | 
| webmaster@1 | 1078         'default' => ''), | 
| webmaster@1 | 1079       'language' => array( | 
| webmaster@1 | 1080         'description' => t('The language this alias is for; if blank, the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.'), | 
| webmaster@1 | 1081         'type' => 'varchar', | 
| webmaster@1 | 1082         'length' => 12, | 
| webmaster@1 | 1083         'not null' => TRUE, | 
| webmaster@1 | 1084         'default' => '') | 
| webmaster@1 | 1085       ), | 
| webmaster@1 | 1086     'unique keys' => array('dst_language' => array('dst', 'language')), | 
| webmaster@1 | 1087     'primary key' => array('pid'), | 
| webmaster@1 | 1088     'indexes' => array('src' => array('src')), | 
| webmaster@1 | 1089     ); | 
| webmaster@1 | 1090 | 
| webmaster@1 | 1091   return $schema; | 
| webmaster@1 | 1092 } | 
| webmaster@1 | 1093 | 
| webmaster@1 | 1094 // Updates for core. | 
| webmaster@1 | 1095 | 
| webmaster@1 | 1096 function system_update_last_removed() { | 
| webmaster@1 | 1097   return 1021; | 
| webmaster@1 | 1098 } | 
| webmaster@1 | 1099 | 
| webmaster@1 | 1100 /** | 
| webmaster@1 | 1101  * @defgroup updates-5.x-extra Extra system updates for 5.x | 
| webmaster@1 | 1102  * @{ | 
| webmaster@1 | 1103  */ | 
| webmaster@1 | 1104 | 
| webmaster@1 | 1105 /** | 
| webmaster@1 | 1106  * Add index on users created column. | 
| webmaster@1 | 1107  */ | 
| webmaster@1 | 1108 function system_update_1022() { | 
| webmaster@1 | 1109   $ret = array(); | 
| webmaster@1 | 1110   db_add_index($ret, 'users', 'created', array('created')); | 
| webmaster@1 | 1111   // Also appears as system_update_6004(). Ensure we don't update twice. | 
| webmaster@1 | 1112   variable_set('system_update_1022', TRUE); | 
| webmaster@1 | 1113   return $ret; | 
| webmaster@1 | 1114 } | 
| webmaster@1 | 1115 | 
| webmaster@1 | 1116 /** | 
| webmaster@1 | 1117  * @} End of "defgroup updates-5.x-extra" | 
| webmaster@1 | 1118  */ | 
| webmaster@1 | 1119 | 
| webmaster@1 | 1120 /** | 
| webmaster@1 | 1121  * @defgroup updates-5.x-to-6.x System updates from 5.x to 6.x | 
| webmaster@1 | 1122  * @{ | 
| webmaster@1 | 1123  */ | 
| webmaster@1 | 1124 | 
| webmaster@1 | 1125 /** | 
| webmaster@1 | 1126  * Remove auto_increment from {boxes} to allow adding custom blocks with | 
| webmaster@1 | 1127  * visibility settings. | 
| webmaster@1 | 1128  */ | 
| webmaster@1 | 1129 function system_update_6000() { | 
| webmaster@1 | 1130   $ret = array(); | 
| webmaster@1 | 1131   switch ($GLOBALS['db_type']) { | 
| webmaster@1 | 1132     case 'mysql': | 
| webmaster@1 | 1133     case 'mysqli': | 
| webmaster@1 | 1134       $max = (int)db_result(db_query('SELECT MAX(bid) FROM {boxes}')); | 
| webmaster@1 | 1135       $ret[] = update_sql('ALTER TABLE {boxes} CHANGE COLUMN bid bid int NOT NULL'); | 
| webmaster@1 | 1136       $ret[] = update_sql("REPLACE INTO {sequences} VALUES ('{boxes}_bid', $max)"); | 
| webmaster@1 | 1137       break; | 
| webmaster@1 | 1138   } | 
| webmaster@1 | 1139   return $ret; | 
| webmaster@1 | 1140 } | 
| webmaster@1 | 1141 | 
| webmaster@1 | 1142 /** | 
| webmaster@1 | 1143  * Add version id column to {term_node} to allow taxonomy module to use revisions. | 
| webmaster@1 | 1144  */ | 
| webmaster@1 | 1145 function system_update_6001() { | 
| webmaster@1 | 1146   $ret = array(); | 
| webmaster@1 | 1147 | 
| webmaster@1 | 1148   // Add vid to term-node relation.  The schema says it is unsigned. | 
| webmaster@1 | 1149   db_add_field($ret, 'term_node', 'vid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1150   db_drop_primary_key($ret, 'term_node'); | 
| webmaster@1 | 1151   db_add_primary_key($ret, 'term_node', array('vid', 'tid', 'nid')); | 
| webmaster@1 | 1152   db_add_index($ret, 'term_node', 'vid', array('vid')); | 
| webmaster@1 | 1153 | 
| webmaster@1 | 1154   db_query('UPDATE {term_node} t SET vid = (SELECT vid FROM {node} n WHERE t.nid = n.nid)'); | 
| webmaster@1 | 1155   return $ret; | 
| webmaster@1 | 1156 } | 
| webmaster@1 | 1157 | 
| webmaster@1 | 1158 /** | 
| webmaster@1 | 1159  * Increase the maximum length of variable names from 48 to 128. | 
| webmaster@1 | 1160  */ | 
| webmaster@1 | 1161 function system_update_6002() { | 
| webmaster@1 | 1162   $ret = array(); | 
| webmaster@1 | 1163   db_drop_primary_key($ret, 'variable'); | 
| webmaster@1 | 1164   db_change_field($ret, 'variable', 'name', 'name', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '')); | 
| webmaster@1 | 1165   db_add_primary_key($ret, 'variable', array('name')); | 
| webmaster@1 | 1166   return $ret; | 
| webmaster@1 | 1167 } | 
| webmaster@1 | 1168 | 
| webmaster@1 | 1169 /** | 
| webmaster@1 | 1170  * Add index on comments status column. | 
| webmaster@1 | 1171  */ | 
| webmaster@1 | 1172 function system_update_6003() { | 
| webmaster@1 | 1173   $ret = array(); | 
| webmaster@1 | 1174   db_add_index($ret, 'comments', 'status', array('status')); | 
| webmaster@1 | 1175   return $ret; | 
| webmaster@1 | 1176 } | 
| webmaster@1 | 1177 | 
| webmaster@1 | 1178 /** | 
| webmaster@1 | 1179  * This update used to add an index on users created column (#127941). | 
| webmaster@1 | 1180  * However, system_update_1022() does the same thing.  This update | 
| webmaster@1 | 1181  * tried to detect if 1022 had already run but failed to do so, | 
| webmaster@1 | 1182  * resulting in an "index already exists" error. | 
| webmaster@1 | 1183  * | 
| webmaster@1 | 1184  * Adding the index here is never necessary.  Sites installed before | 
| webmaster@1 | 1185  * 1022 will run 1022, getting the update.  Sites installed on/after 1022 | 
| webmaster@1 | 1186  * got the index when the table was first created.  Therefore, this | 
| webmaster@1 | 1187  * function is now a no-op. | 
| webmaster@1 | 1188  */ | 
| webmaster@1 | 1189 function system_update_6004() { | 
| webmaster@1 | 1190   return array(); | 
| webmaster@1 | 1191 } | 
| webmaster@1 | 1192 | 
| webmaster@1 | 1193 /** | 
| webmaster@1 | 1194  * Add language to url_alias table and modify indexes. | 
| webmaster@1 | 1195  */ | 
| webmaster@1 | 1196 function system_update_6005() { | 
| webmaster@1 | 1197   $ret = array(); | 
| webmaster@1 | 1198   switch ($GLOBALS['db_type']) { | 
| webmaster@1 | 1199     case 'pgsql': | 
| webmaster@1 | 1200       db_add_column($ret, 'url_alias', 'language', 'varchar(12)', array('default' => "''", 'not null' => TRUE)); | 
| webmaster@1 | 1201 | 
| webmaster@1 | 1202       // As of system.install:1.85 (before the new language | 
| webmaster@1 | 1203       // subsystem), new installs got a unique key named | 
| webmaster@1 | 1204       // url_alias_dst_key on url_alias.dst.  Unfortunately, | 
| webmaster@1 | 1205       // system_update_162 created a unique key inconsistently named | 
| webmaster@1 | 1206       // url_alias_dst_idx on url_alias.dst (keys should have the _key | 
| webmaster@1 | 1207       // suffix, indexes the _idx suffix).  Therefore, sites installed | 
| webmaster@1 | 1208       // before system_update_162 have a unique key with a different | 
| webmaster@1 | 1209       // name than sites installed after system_update_162().  Now, we | 
| webmaster@1 | 1210       // want to drop the unique key on dst which may have either one | 
| webmaster@1 | 1211       // of two names and create a new unique key on (dst, language). | 
| webmaster@1 | 1212       // There is no way to know which key name exists so we have to | 
| webmaster@1 | 1213       // drop both, causing an SQL error.  Thus, we just hide the | 
| webmaster@1 | 1214       // error and only report the update_sql results that work. | 
| webmaster@1 | 1215       $err = error_reporting(0); | 
| webmaster@1 | 1216       $ret1 = update_sql('DROP INDEX {url_alias}_dst_idx'); | 
| webmaster@1 | 1217       if ($ret1['success']) { | 
| webmaster@1 | 1218   $ret[] = $ret1; | 
| webmaster@1 | 1219       } | 
| webmaster@1 | 1220       $ret1 = array(); | 
| webmaster@1 | 1221       db_drop_unique_key($ret, 'url_alias', 'dst'); | 
| webmaster@1 | 1222       foreach ($ret1 as $r) { | 
| webmaster@1 | 1223   if ($r['success']) { | 
| webmaster@1 | 1224     $ret[] = $r; | 
| webmaster@1 | 1225   } | 
| webmaster@1 | 1226       } | 
| webmaster@1 | 1227       error_reporting($err); | 
| webmaster@1 | 1228 | 
| webmaster@1 | 1229       $ret[] = update_sql('CREATE UNIQUE INDEX {url_alias}_dst_language_idx ON {url_alias}(dst, language)'); | 
| webmaster@1 | 1230       break; | 
| webmaster@1 | 1231     case 'mysql': | 
| webmaster@1 | 1232     case 'mysqli': | 
| webmaster@1 | 1233       $ret[] = update_sql("ALTER TABLE {url_alias} ADD language varchar(12) NOT NULL default ''"); | 
| webmaster@1 | 1234       $ret[] = update_sql("ALTER TABLE {url_alias} DROP INDEX dst"); | 
| webmaster@1 | 1235       $ret[] = update_sql("ALTER TABLE {url_alias} ADD UNIQUE dst_language (dst, language)"); | 
| webmaster@1 | 1236       break; | 
| webmaster@1 | 1237   } | 
| webmaster@1 | 1238   return $ret; | 
| webmaster@1 | 1239 } | 
| webmaster@1 | 1240 | 
| webmaster@1 | 1241 /** | 
| webmaster@1 | 1242  * Drop useless indices on node_counter table. | 
| webmaster@1 | 1243  */ | 
| webmaster@1 | 1244 function system_update_6006() { | 
| webmaster@1 | 1245   $ret = array(); | 
| webmaster@1 | 1246   switch ($GLOBALS['db_type']) { | 
| webmaster@1 | 1247     case 'pgsql': | 
| webmaster@1 | 1248       $ret[] = update_sql('DROP INDEX {node_counter}_daycount_idx'); | 
| webmaster@1 | 1249       $ret[] = update_sql('DROP INDEX {node_counter}_totalcount_idx'); | 
| webmaster@1 | 1250       $ret[] = update_sql('DROP INDEX {node_counter}_timestamp_idx'); | 
| webmaster@1 | 1251       break; | 
| webmaster@1 | 1252     case 'mysql': | 
| webmaster@1 | 1253     case 'mysqli': | 
| webmaster@1 | 1254       $ret[] = update_sql("ALTER TABLE {node_counter} DROP INDEX daycount"); | 
| webmaster@1 | 1255       $ret[] = update_sql("ALTER TABLE {node_counter} DROP INDEX totalcount"); | 
| webmaster@1 | 1256       $ret[] = update_sql("ALTER TABLE {node_counter} DROP INDEX timestamp"); | 
| webmaster@1 | 1257       break; | 
| webmaster@1 | 1258   } | 
| webmaster@1 | 1259   return $ret; | 
| webmaster@1 | 1260 } | 
| webmaster@1 | 1261 | 
| webmaster@1 | 1262 /** | 
| webmaster@1 | 1263  * Change the severity column in the watchdog table to the new values. | 
| webmaster@1 | 1264  */ | 
| webmaster@1 | 1265 function system_update_6007() { | 
| webmaster@1 | 1266   $ret = array(); | 
| webmaster@1 | 1267   $ret[] = update_sql("UPDATE {watchdog} SET severity = ". WATCHDOG_NOTICE ." WHERE severity = 0"); | 
| webmaster@1 | 1268   $ret[] = update_sql("UPDATE {watchdog} SET severity = ". WATCHDOG_WARNING ." WHERE severity = 1"); | 
| webmaster@1 | 1269   $ret[] = update_sql("UPDATE {watchdog} SET severity = ". WATCHDOG_ERROR ." WHERE severity = 2"); | 
| webmaster@1 | 1270   return $ret; | 
| webmaster@1 | 1271 } | 
| webmaster@1 | 1272 | 
| webmaster@1 | 1273 /** | 
| webmaster@1 | 1274  * Add info files to themes.  The info and owner columns are added by | 
| webmaster@1 | 1275  * update_fix_d6_requirements() in update.php to avoid a large number | 
| webmaster@1 | 1276  * of error messages from update.php.  All we need to do here is copy | 
| webmaster@1 | 1277  * description to owner and then drop description. | 
| webmaster@1 | 1278  */ | 
| webmaster@1 | 1279 function system_update_6008() { | 
| webmaster@1 | 1280   $ret = array(); | 
| webmaster@1 | 1281   $ret[] = update_sql('UPDATE {system} SET owner = description'); | 
| webmaster@1 | 1282   db_drop_field($ret, 'system', 'description'); | 
| webmaster@1 | 1283 | 
| webmaster@1 | 1284   // Rebuild system table contents. | 
| webmaster@1 | 1285   module_rebuild_cache(); | 
| webmaster@1 | 1286   system_theme_data(); | 
| webmaster@1 | 1287 | 
| webmaster@1 | 1288   return $ret; | 
| webmaster@1 | 1289 } | 
| webmaster@1 | 1290 | 
| webmaster@1 | 1291 /** | 
| webmaster@1 | 1292  * The PHP filter is now a separate module. | 
| webmaster@1 | 1293  */ | 
| webmaster@1 | 1294 function system_update_6009() { | 
| webmaster@1 | 1295   $ret = array(); | 
| webmaster@1 | 1296 | 
| webmaster@1 | 1297   // If any input format used the Drupal 5 PHP filter. | 
| webmaster@1 | 1298   if (db_result(db_query("SELECT COUNT(format) FROM {filters} WHERE module = 'filter' AND delta = 1"))) { | 
| webmaster@1 | 1299     // Enable the PHP filter module. | 
| webmaster@1 | 1300     $ret[] = update_sql("UPDATE {system} SET status = 1 WHERE name = 'php' AND type = 'module'"); | 
| webmaster@1 | 1301     // Update the input filters. | 
| webmaster@1 | 1302     $ret[] = update_sql("UPDATE {filters} SET delta = 0, module = 'php' WHERE module = 'filter' AND delta = 1"); | 
| webmaster@1 | 1303   } | 
| webmaster@1 | 1304 | 
| webmaster@1 | 1305   // With the removal of the PHP evaluator filter, the deltas of the line break | 
| webmaster@1 | 1306   // and URL filter have changed. | 
| webmaster@1 | 1307   $ret[] = update_sql("UPDATE {filters} SET delta = 1 WHERE module = 'filter' AND delta = 2"); | 
| webmaster@1 | 1308   $ret[] = update_sql("UPDATE {filters} SET delta = 2 WHERE module = 'filter' AND delta = 3"); | 
| webmaster@1 | 1309 | 
| webmaster@1 | 1310   return $ret; | 
| webmaster@1 | 1311 } | 
| webmaster@1 | 1312 | 
| webmaster@1 | 1313 /** | 
| webmaster@1 | 1314  * Add variable replacement for watchdog messages. | 
| webmaster@1 | 1315  * | 
| webmaster@1 | 1316  * The variables field is NOT NULL and does not have a default value. | 
| webmaster@1 | 1317  * Existing log messages should not be translated in the new system, | 
| webmaster@1 | 1318  * so we insert 'N;' (serialize(NULL)) as the temporary default but | 
| webmaster@1 | 1319  * then remove the default value to match the schema. | 
| webmaster@1 | 1320  */ | 
| webmaster@1 | 1321 function system_update_6010() { | 
| webmaster@1 | 1322   $ret = array(); | 
| webmaster@1 | 1323   db_add_field($ret, 'watchdog', 'variables', array('type' => 'text', 'size' => 'big', 'not null' => TRUE, 'initial' => 'N;')); | 
| webmaster@1 | 1324   return $ret; | 
| webmaster@1 | 1325 } | 
| webmaster@1 | 1326 | 
| webmaster@1 | 1327 /** | 
| webmaster@1 | 1328  * Add language support to nodes | 
| webmaster@1 | 1329  */ | 
| webmaster@1 | 1330 function system_update_6011() { | 
| webmaster@1 | 1331   $ret = array(); | 
| webmaster@1 | 1332   switch ($GLOBALS['db_type']) { | 
| webmaster@1 | 1333     case 'pgsql': | 
| webmaster@1 | 1334       db_add_column($ret, 'node', 'language', 'varchar(12)', array('default' => "''", 'not null' => TRUE)); | 
| webmaster@1 | 1335       break; | 
| webmaster@1 | 1336     case 'mysql': | 
| webmaster@1 | 1337     case 'mysqli': | 
| webmaster@1 | 1338       $ret[] = update_sql("ALTER TABLE {node} ADD language varchar(12) NOT NULL default ''"); | 
| webmaster@1 | 1339       break; | 
| webmaster@1 | 1340   } | 
| webmaster@1 | 1341   return $ret; | 
| webmaster@1 | 1342 } | 
| webmaster@1 | 1343 | 
| webmaster@1 | 1344 /** | 
| webmaster@1 | 1345  * Add serialized field to cache tables.  This is now handled directly | 
| webmaster@1 | 1346  * by update.php, so this function is a no-op. | 
| webmaster@1 | 1347  */ | 
| webmaster@1 | 1348 function system_update_6012() { | 
| webmaster@1 | 1349   return array(); | 
| webmaster@1 | 1350 } | 
| webmaster@1 | 1351 | 
| webmaster@1 | 1352 /** | 
| webmaster@1 | 1353  * Rebuild cache data for theme system changes | 
| webmaster@1 | 1354  */ | 
| webmaster@1 | 1355 function system_update_6013() { | 
| webmaster@1 | 1356   // Rebuild system table contents. | 
| webmaster@1 | 1357   module_rebuild_cache(); | 
| webmaster@1 | 1358   system_theme_data(); | 
| webmaster@1 | 1359 | 
| webmaster@1 | 1360   return array(array('success' => TRUE, 'query' => 'Cache rebuilt.')); | 
| webmaster@1 | 1361 } | 
| webmaster@1 | 1362 | 
| webmaster@1 | 1363 /** | 
| webmaster@1 | 1364  * Record that the installer is done, so it is not | 
| webmaster@1 | 1365  * possible to run the installer on upgraded sites. | 
| webmaster@1 | 1366  */ | 
| webmaster@1 | 1367 function system_update_6014() { | 
| webmaster@1 | 1368   variable_set('install_task', 'done'); | 
| webmaster@1 | 1369 | 
| webmaster@1 | 1370   return array(array('success' => TRUE, 'query' => "variable_set('install_task')")); | 
| webmaster@1 | 1371 } | 
| webmaster@1 | 1372 | 
| webmaster@1 | 1373 /** | 
| webmaster@1 | 1374  * Add the form cache table. | 
| webmaster@1 | 1375  */ | 
| webmaster@1 | 1376 function system_update_6015() { | 
| webmaster@1 | 1377   $ret = array(); | 
| webmaster@1 | 1378 | 
| webmaster@1 | 1379   switch ($GLOBALS['db_type']) { | 
| webmaster@1 | 1380     case 'pgsql': | 
| webmaster@1 | 1381       $ret[] = update_sql("CREATE TABLE {cache_form} ( | 
| webmaster@1 | 1382         cid varchar(255) NOT NULL default '', | 
| webmaster@1 | 1383         data bytea, | 
| webmaster@1 | 1384         expire int NOT NULL default '0', | 
| webmaster@1 | 1385         created int NOT NULL default '0', | 
| webmaster@1 | 1386         headers text, | 
| webmaster@1 | 1387         serialized smallint NOT NULL default '0', | 
| webmaster@1 | 1388         PRIMARY KEY (cid) | 
| webmaster@1 | 1389     )"); | 
| webmaster@1 | 1390       $ret[] = update_sql("CREATE INDEX {cache_form}_expire_idx ON {cache_form} (expire)"); | 
| webmaster@1 | 1391       break; | 
| webmaster@1 | 1392     case 'mysql': | 
| webmaster@1 | 1393     case 'mysqli': | 
| webmaster@1 | 1394       $ret[] = update_sql("CREATE TABLE {cache_form} ( | 
| webmaster@1 | 1395         cid varchar(255) NOT NULL default '', | 
| webmaster@1 | 1396         data longblob, | 
| webmaster@1 | 1397         expire int NOT NULL default '0', | 
| webmaster@1 | 1398         created int NOT NULL default '0', | 
| webmaster@1 | 1399         headers text, | 
| webmaster@1 | 1400         serialized int(1) NOT NULL default '0', | 
| webmaster@1 | 1401         PRIMARY KEY (cid), | 
| webmaster@1 | 1402         INDEX expire (expire) | 
| webmaster@1 | 1403       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); | 
| webmaster@1 | 1404       break; | 
| webmaster@1 | 1405   } | 
| webmaster@1 | 1406 | 
| webmaster@1 | 1407   return $ret; | 
| webmaster@1 | 1408 } | 
| webmaster@1 | 1409 | 
| webmaster@1 | 1410 /** | 
| webmaster@1 | 1411  * Make {node}'s primary key be nid, change nid,vid to a unique key. | 
| webmaster@1 | 1412  * Add primary keys to block, filters, flood, permission, and term_relation. | 
| webmaster@1 | 1413  */ | 
| webmaster@1 | 1414 function system_update_6016() { | 
| webmaster@1 | 1415   $ret = array(); | 
| webmaster@1 | 1416 | 
| webmaster@1 | 1417   switch ($GLOBALS['db_type']) { | 
| webmaster@1 | 1418     case 'pgsql': | 
| webmaster@1 | 1419       $ret[] = update_sql("ALTER TABLE {node} ADD CONSTRAINT {node}_nid_vid_key UNIQUE (nid, vid)"); | 
| webmaster@1 | 1420       db_add_column($ret, 'blocks', 'bid', 'serial'); | 
| webmaster@1 | 1421       $ret[] = update_sql("ALTER TABLE {blocks} ADD PRIMARY KEY (bid)"); | 
| webmaster@1 | 1422       db_add_column($ret, 'filters', 'fid', 'serial'); | 
| webmaster@1 | 1423       $ret[] = update_sql("ALTER TABLE {filters} ADD PRIMARY KEY (fid)"); | 
| webmaster@1 | 1424       db_add_column($ret, 'flood', 'fid', 'serial'); | 
| webmaster@1 | 1425       $ret[] = update_sql("ALTER TABLE {flood} ADD PRIMARY KEY (fid)"); | 
| webmaster@1 | 1426       db_add_column($ret, 'permission', 'pid', 'serial'); | 
| webmaster@1 | 1427       $ret[] = update_sql("ALTER TABLE {permission} ADD PRIMARY KEY (pid)"); | 
| webmaster@1 | 1428       db_add_column($ret, 'term_relation', 'trid', 'serial'); | 
| webmaster@1 | 1429       $ret[] = update_sql("ALTER TABLE {term_relation} ADD PRIMARY KEY (trid)"); | 
| webmaster@1 | 1430       db_add_column($ret, 'term_synonym', 'tsid', 'serial'); | 
| webmaster@1 | 1431       $ret[] = update_sql("ALTER TABLE {term_synonym} ADD PRIMARY KEY (tsid)"); | 
| webmaster@1 | 1432       break; | 
| webmaster@1 | 1433     case 'mysql': | 
| webmaster@1 | 1434     case 'mysqli': | 
| webmaster@1 | 1435       $ret[] = update_sql('ALTER TABLE {node} ADD UNIQUE KEY nid_vid (nid, vid)'); | 
| webmaster@1 | 1436       $ret[] = update_sql("ALTER TABLE {blocks} ADD bid int NOT NULL AUTO_INCREMENT PRIMARY KEY"); | 
| webmaster@1 | 1437       $ret[] = update_sql("ALTER TABLE {filters} ADD fid int NOT NULL AUTO_INCREMENT PRIMARY KEY"); | 
| webmaster@1 | 1438       $ret[] = update_sql("ALTER TABLE {flood} ADD fid int NOT NULL AUTO_INCREMENT PRIMARY KEY"); | 
| webmaster@1 | 1439       $ret[] = update_sql("ALTER TABLE {permission} ADD pid int NOT NULL AUTO_INCREMENT PRIMARY KEY"); | 
| webmaster@1 | 1440       $ret[] = update_sql("ALTER TABLE {term_relation} ADD trid int NOT NULL AUTO_INCREMENT PRIMARY KEY"); | 
| webmaster@1 | 1441       $ret[] = update_sql("ALTER TABLE {term_synonym} ADD tsid int NOT NULL AUTO_INCREMENT PRIMARY KEY"); | 
| webmaster@1 | 1442       break; | 
| webmaster@1 | 1443   } | 
| webmaster@1 | 1444 | 
| webmaster@1 | 1445   return $ret; | 
| webmaster@1 | 1446 } | 
| webmaster@1 | 1447 | 
| webmaster@1 | 1448 /** | 
| webmaster@1 | 1449  * Rename settings related to user.module email notifications. | 
| webmaster@1 | 1450  */ | 
| webmaster@1 | 1451 function system_update_6017() { | 
| webmaster@1 | 1452   $ret = array(); | 
| webmaster@1 | 1453   // Maps old names to new ones. | 
| webmaster@1 | 1454   $var_names = array( | 
| webmaster@1 | 1455     'admin'    => 'register_admin_created', | 
| webmaster@1 | 1456     'approval' => 'register_pending_approval', | 
| webmaster@1 | 1457     'welcome'  => 'register_no_approval_required', | 
| webmaster@1 | 1458     'pass'     => 'password_reset', | 
| webmaster@1 | 1459   ); | 
| webmaster@1 | 1460   foreach ($var_names as $old => $new) { | 
| webmaster@1 | 1461     foreach (array('_subject', '_body') as $suffix) { | 
| webmaster@1 | 1462       $old_name = 'user_mail_'. $old . $suffix; | 
| webmaster@1 | 1463       $new_name = 'user_mail_'. $new . $suffix; | 
| webmaster@1 | 1464       if ($old_val = variable_get($old_name, FALSE)) { | 
| webmaster@1 | 1465         variable_set($new_name, $old_val); | 
| webmaster@1 | 1466         variable_del($old_name); | 
| webmaster@1 | 1467         $ret[] = array('success' => TRUE, 'query' => "variable_set($new_name)"); | 
| webmaster@1 | 1468         $ret[] = array('success' => TRUE, 'query' => "variable_del($old_name)"); | 
| webmaster@1 | 1469         if ($old_name == 'user_mail_approval_body') { | 
| webmaster@1 | 1470           drupal_set_message('Saving an old value of the welcome message body for users that are pending administrator approval. However, you should consider modifying this text, since Drupal can now be configured to automatically notify users and send them their login information when their accounts are approved. See the <a href="'. url('admin/user/settings') .'">User settings</a> page for details.'); | 
| webmaster@1 | 1471         } | 
| webmaster@1 | 1472       } | 
| webmaster@1 | 1473     } | 
| webmaster@1 | 1474   } | 
| webmaster@1 | 1475   return $ret; | 
| webmaster@1 | 1476 } | 
| webmaster@1 | 1477 | 
| webmaster@1 | 1478 /** | 
| webmaster@1 | 1479  * Add HTML corrector to HTML formats or replace the old module if it was in use. | 
| webmaster@1 | 1480  */ | 
| webmaster@1 | 1481 function system_update_6018() { | 
| webmaster@1 | 1482   $ret = array(); | 
| webmaster@1 | 1483 | 
| webmaster@1 | 1484   // Disable htmlcorrector.module, if it exists and replace its filter. | 
| webmaster@1 | 1485   if (module_exists('htmlcorrector')) { | 
| webmaster@1 | 1486     module_disable(array('htmlcorrector')); | 
| webmaster@1 | 1487     $ret[] = update_sql("UPDATE {filter_formats} SET module = 'filter', delta = 3 WHERE module = 'htmlcorrector'"); | 
| webmaster@1 | 1488     $ret[] = array('success' => TRUE, 'query' => 'HTML Corrector module was disabled; this functionality has now been added to core.'); | 
| webmaster@1 | 1489     return $ret; | 
| webmaster@1 | 1490   } | 
| webmaster@1 | 1491 | 
| webmaster@1 | 1492   // Otherwise, find any format with 'HTML' in its name and add the filter at the end. | 
| webmaster@1 | 1493   $result = db_query("SELECT format, name FROM {filter_formats} WHERE name LIKE '%HTML%'"); | 
| webmaster@1 | 1494   while ($format = db_fetch_object($result)) { | 
| webmaster@1 | 1495     $weight = db_result(db_query("SELECT MAX(weight) FROM {filters} WHERE format = %d", $format->format)); | 
| webmaster@1 | 1496     db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", $format->format, 'filter', 3, max(10, $weight + 1)); | 
| webmaster@1 | 1497     $ret[] = array('success' => TRUE, 'query' => "HTML corrector filter added to the '". $format->name ."' input format."); | 
| webmaster@1 | 1498   } | 
| webmaster@1 | 1499 | 
| webmaster@1 | 1500   return $ret; | 
| webmaster@1 | 1501 } | 
| webmaster@1 | 1502 | 
| webmaster@1 | 1503 /** | 
| webmaster@1 | 1504  * Reconcile small differences in the previous, manually created mysql | 
| webmaster@1 | 1505  * and pgsql schemas so they are the same and can be represented by a | 
| webmaster@1 | 1506  * single schema structure. | 
| webmaster@1 | 1507  * | 
| webmaster@1 | 1508  * Note that the mysql and pgsql cases make different changes.  This | 
| webmaster@1 | 1509  * is because each schema needs to be tweaked in different ways to | 
| webmaster@1 | 1510  * conform to the new schema structure.  Also, since they operate on | 
| webmaster@1 | 1511  * tables defined by many optional core modules which may not ever | 
| webmaster@1 | 1512  * have been installed, they must test each table for existence.  If | 
| webmaster@1 | 1513  * the modules are first installed after this update exists the tables | 
| webmaster@1 | 1514  * will be created from the schema structure and will start out | 
| webmaster@1 | 1515  * correct. | 
| webmaster@1 | 1516  */ | 
| webmaster@1 | 1517 function system_update_6019() { | 
| webmaster@1 | 1518   $ret = array(); | 
| webmaster@1 | 1519 | 
| webmaster@1 | 1520   switch ($GLOBALS['db_type']) { | 
| webmaster@1 | 1521     case 'pgsql': | 
| webmaster@1 | 1522       // Remove default ''. | 
| webmaster@1 | 1523       if (db_table_exists('aggregator_feed')) { | 
| webmaster@1 | 1524         db_field_set_no_default($ret, 'aggregator_feed', 'description'); | 
| webmaster@1 | 1525         db_field_set_no_default($ret, 'aggregator_feed', 'image'); | 
| webmaster@1 | 1526       } | 
| webmaster@1 | 1527       db_field_set_no_default($ret, 'blocks', 'pages'); | 
| webmaster@1 | 1528       if (db_table_exists('contact')) { | 
| webmaster@1 | 1529         db_field_set_no_default($ret, 'contact', 'recipients'); | 
| webmaster@1 | 1530         db_field_set_no_default($ret, 'contact', 'reply'); | 
| webmaster@1 | 1531       } | 
| webmaster@1 | 1532       db_field_set_no_default($ret, 'watchdog', 'location'); | 
| webmaster@1 | 1533       db_field_set_no_default($ret, 'node_revisions', 'body'); | 
| webmaster@1 | 1534       db_field_set_no_default($ret, 'node_revisions', 'teaser'); | 
| webmaster@1 | 1535       db_field_set_no_default($ret, 'node_revisions', 'log'); | 
| webmaster@1 | 1536 | 
| webmaster@1 | 1537       // Update from pgsql 'float' (which means 'double precision') to | 
| webmaster@1 | 1538       // schema 'float' (which in pgsql means 'real'). | 
| webmaster@1 | 1539       if (db_table_exists('search_index')) { | 
| webmaster@1 | 1540         db_change_field($ret, 'search_index', 'score', 'score', array('type' => 'float')); | 
| webmaster@1 | 1541       } | 
| webmaster@1 | 1542       if (db_table_exists('search_total')) { | 
| webmaster@1 | 1543         db_change_field($ret, 'search_total', 'count', 'count', array('type' => 'float')); | 
| webmaster@1 | 1544       } | 
| webmaster@1 | 1545 | 
| webmaster@1 | 1546       // Replace unique index dst_language with a unique constraint.  The | 
| webmaster@1 | 1547       // result is the same but the unique key fits our current schema | 
| webmaster@1 | 1548       // structure.  Also, the postgres documentation implies that | 
| webmaster@1 | 1549       // unique constraints are preferable to unique indexes.  See | 
| webmaster@1 | 1550       // http://www.postgresql.org/docs/8.2/interactive/indexes-unique.html. | 
| webmaster@1 | 1551       if (db_table_exists('url_alias')) { | 
| webmaster@1 | 1552         db_drop_index($ret, 'url_alias', 'dst_language'); | 
| webmaster@1 | 1553         db_add_unique_key($ret, 'url_alias', 'dst_language', | 
| webmaster@1 | 1554           array('dst', 'language')); | 
| webmaster@1 | 1555       } | 
| webmaster@1 | 1556 | 
| webmaster@1 | 1557       // Fix term_node pkey: mysql and pgsql code had different orders. | 
| webmaster@1 | 1558       if (db_table_exists('term_node')) { | 
| webmaster@1 | 1559         db_drop_primary_key($ret, 'term_node'); | 
| webmaster@1 | 1560         db_add_primary_key($ret, 'term_node', array('vid', 'tid', 'nid')); | 
| webmaster@1 | 1561       } | 
| webmaster@1 | 1562 | 
| webmaster@1 | 1563       // Make boxes.bid unsigned. | 
| webmaster@1 | 1564       db_drop_primary_key($ret, 'boxes'); | 
| webmaster@1 | 1565       db_change_field($ret, 'boxes', 'bid', 'bid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('bid'))); | 
| webmaster@1 | 1566 | 
| webmaster@1 | 1567       // Fix primary key | 
| webmaster@1 | 1568       db_drop_primary_key($ret, 'node'); | 
| webmaster@1 | 1569       db_add_primary_key($ret, 'node', array('nid')); | 
| webmaster@1 | 1570 | 
| webmaster@1 | 1571       break; | 
| webmaster@1 | 1572 | 
| webmaster@1 | 1573     case 'mysql': | 
| webmaster@1 | 1574     case 'mysqli': | 
| webmaster@1 | 1575       // Rename key 'link' to 'url'. | 
| webmaster@1 | 1576       if (db_table_exists('aggregator_feed')) { | 
| webmaster@1 | 1577         db_drop_unique_key($ret, 'aggregator_feed', 'link'); | 
| webmaster@1 | 1578         db_add_unique_key($ret, 'aggregator_feed', 'url', array('url')); | 
| webmaster@1 | 1579       } | 
| webmaster@1 | 1580 | 
| webmaster@1 | 1581       // Change to size => small. | 
| webmaster@1 | 1582       if (db_table_exists('boxes')) { | 
| webmaster@1 | 1583         db_change_field($ret, 'boxes', 'format', 'format', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1584       } | 
| webmaster@1 | 1585 | 
| webmaster@1 | 1586       // Change to size => small. | 
| webmaster@1 | 1587       // Rename index 'lid' to 'nid'. | 
| webmaster@1 | 1588       if (db_table_exists('comments')) { | 
| webmaster@1 | 1589         db_change_field($ret, 'comments', 'format', 'format', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1590         db_drop_index($ret, 'comments', 'lid'); | 
| webmaster@1 | 1591         db_add_index($ret, 'comments', 'nid', array('nid')); | 
| webmaster@1 | 1592       } | 
| webmaster@1 | 1593 | 
| webmaster@1 | 1594       // Change to size => small. | 
| webmaster@1 | 1595       db_change_field($ret, 'cache', 'serialized', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1596       db_change_field($ret, 'cache_filter', 'serialized', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1597       db_change_field($ret, 'cache_page', 'serialized', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1598       db_change_field($ret, 'cache_form', 'serialized', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1599 | 
| webmaster@1 | 1600       // Remove default => 0, set auto increment. | 
| webmaster@1 | 1601       $new_uid = 1 + db_result(db_query('SELECT MAX(uid) FROM {users}')); | 
| webmaster@1 | 1602       $ret[] = update_sql('UPDATE {users} SET uid = '. $new_uid .' WHERE uid = 0'); | 
| webmaster@1 | 1603       db_drop_primary_key($ret, 'users'); | 
| webmaster@1 | 1604       db_change_field($ret, 'users', 'uid', 'uid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('uid'))); | 
| webmaster@1 | 1605       $ret[] = update_sql('UPDATE {users} SET uid = 0 WHERE uid = '. $new_uid); | 
| webmaster@1 | 1606 | 
| webmaster@1 | 1607       // Special field names. | 
| webmaster@1 | 1608       $map = array('node_revisions' => 'vid'); | 
| webmaster@1 | 1609       // Make sure these tables have proper auto_increment fields. | 
| webmaster@1 | 1610       foreach (array('boxes', 'files', 'node', 'node_revisions') as $table) { | 
| webmaster@1 | 1611         $field = isset($map[$table]) ? $map[$table] : $table[0] .'id'; | 
| webmaster@1 | 1612         db_drop_primary_key($ret, $table); | 
| webmaster@1 | 1613         db_change_field($ret, $table, $field, $field, array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array($field))); | 
| webmaster@1 | 1614       } | 
| webmaster@1 | 1615 | 
| webmaster@1 | 1616       break; | 
| webmaster@1 | 1617   } | 
| webmaster@1 | 1618 | 
| webmaster@1 | 1619   return $ret; | 
| webmaster@1 | 1620 } | 
| webmaster@1 | 1621 | 
| webmaster@1 | 1622 /** | 
| webmaster@1 | 1623  * Create the tables for the new menu system. | 
| webmaster@1 | 1624  */ | 
| webmaster@1 | 1625 function system_update_6020() { | 
| webmaster@1 | 1626   $ret = array(); | 
| webmaster@1 | 1627 | 
| webmaster@1 | 1628   $schema['menu_router'] = array( | 
| webmaster@1 | 1629     'fields' => array( | 
| webmaster@1 | 1630       'path'             => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1631       'load_functions'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1632       'to_arg_functions' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1633       'access_callback'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1634       'access_arguments' => array('type' => 'text', 'not null' => FALSE), | 
| webmaster@1 | 1635       'page_callback'    => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1636       'page_arguments'   => array('type' => 'text', 'not null' => FALSE), | 
| webmaster@1 | 1637       'fit'              => array('type' => 'int', 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1638       'number_parts'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), | 
| webmaster@1 | 1639       'tab_parent'       => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1640       'tab_root'         => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1641       'title'            => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1642       'title_callback'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1643       'title_arguments'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1644       'type'             => array('type' => 'int', 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1645       'block_callback'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1646       'description'      => array('type' => 'text', 'not null' => TRUE), | 
| webmaster@1 | 1647       'position'         => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1648       'weight'           => array('type' => 'int', 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1649       'file'             => array('type' => 'text', 'size' => 'medium') | 
| webmaster@1 | 1650     ), | 
| webmaster@1 | 1651     'indexes' => array( | 
| webmaster@1 | 1652       'fit'        => array('fit'), | 
| webmaster@1 | 1653       'tab_parent' => array('tab_parent') | 
| webmaster@1 | 1654     ), | 
| webmaster@1 | 1655     'primary key' => array('path'), | 
| webmaster@1 | 1656   ); | 
| webmaster@1 | 1657 | 
| webmaster@1 | 1658   $schema['menu_links'] = array( | 
| webmaster@1 | 1659     'fields' => array( | 
| webmaster@1 | 1660       'menu_name'    => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1661       'mlid'         => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), | 
| webmaster@1 | 1662       'plid'         => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1663       'link_path'    => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1664       'router_path'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1665       'link_title'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1666       'options'      => array('type' => 'text', 'not null' => FALSE), | 
| webmaster@1 | 1667       'module'       => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'system'), | 
| webmaster@1 | 1668       'hidden'       => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), | 
| webmaster@1 | 1669       'external'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), | 
| webmaster@1 | 1670       'has_children' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), | 
| webmaster@1 | 1671       'expanded'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), | 
| webmaster@1 | 1672       'weight'       => array('type' => 'int', 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1673       'depth'        => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), | 
| webmaster@1 | 1674       'customized'   => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), | 
| webmaster@1 | 1675       'p1'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1676       'p2'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1677       'p3'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1678       'p4'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1679       'p5'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1680       'p6'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1681       'p7'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1682       'p8'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1683       'p9'           => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 1684       'updated'      => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), | 
| webmaster@1 | 1685     ), | 
| webmaster@1 | 1686     'indexes' => array( | 
| webmaster@1 | 1687       'path_menu'              => array(array('link_path', 128), 'menu_name'), | 
| webmaster@1 | 1688       'menu_plid_expand_child' => array('menu_name', 'plid', 'expanded', 'has_children'), | 
| webmaster@1 | 1689       'menu_parents'           => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'), | 
| webmaster@1 | 1690       'router_path'            => array(array('router_path', 128)), | 
| webmaster@1 | 1691     ), | 
| webmaster@1 | 1692     'primary key' => array('mlid'), | 
| webmaster@1 | 1693   ); | 
| webmaster@1 | 1694 | 
| webmaster@1 | 1695   foreach ($schema as $name => $table) { | 
| webmaster@1 | 1696     db_create_table($ret, $name, $table); | 
| webmaster@1 | 1697   } | 
| webmaster@1 | 1698   return $ret; | 
| webmaster@1 | 1699 } | 
| webmaster@1 | 1700 | 
| webmaster@1 | 1701 /** | 
| webmaster@1 | 1702  * Migrate the menu items from the old menu system to the new menu_links table. | 
| webmaster@1 | 1703  */ | 
| webmaster@1 | 1704 function system_update_6021() { | 
| webmaster@1 | 1705   $ret = array('#finished' => 0); | 
| webmaster@1 | 1706   $menus = array( | 
| webmaster@1 | 1707     'navigation' => array( | 
| webmaster@1 | 1708       'menu_name' => 'navigation', | 
| webmaster@1 | 1709       'title' => 'Navigation', | 
| webmaster@1 | 1710       'description' => 'The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.', | 
| webmaster@1 | 1711     ), | 
| webmaster@1 | 1712     'primary-links' => array( | 
| webmaster@1 | 1713       'menu_name' => 'primary-links', | 
| webmaster@1 | 1714       'title' => 'Primary links', | 
| webmaster@1 | 1715       'description' => 'Primary links are often used at the theme layer to show the major sections of a site. A typical representation for primary links would be tabs along the top.', | 
| webmaster@1 | 1716     ), | 
| webmaster@1 | 1717     'secondary-links' => array( | 
| webmaster@1 | 1718       'menu_name' => 'secondary-links', | 
| webmaster@1 | 1719       'title' => 'Secondary links', | 
| webmaster@1 | 1720       'description' => 'Secondary links are often used for pages like legal notices, contact details, and other secondary navigation items that play a lesser role than primary links', | 
| webmaster@1 | 1721     ), | 
| webmaster@1 | 1722   ); | 
| webmaster@1 | 1723   // Multi-part update | 
| webmaster@1 | 1724   if (!isset($_SESSION['system_update_6021'])) { | 
| webmaster@1 | 1725     db_add_field($ret, 'menu', 'converted', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')); | 
| webmaster@1 | 1726     $_SESSION['system_update_6021_max'] = db_result(db_query('SELECT COUNT(*) FROM {menu}')); | 
| webmaster@1 | 1727     $_SESSION['menu_menu_map'] = array(1 => 'navigation'); | 
| webmaster@1 | 1728     // 0 => FALSE is for new menus, 1 => FALSE is for the navigation. | 
| webmaster@1 | 1729     $_SESSION['menu_item_map'] = array(0 => FALSE, 1 => FALSE); | 
| webmaster@1 | 1730     $table = array( | 
| webmaster@1 | 1731       'fields' => array( | 
| webmaster@1 | 1732         'menu_name'   => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1733         'title'       => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 1734         'description' => array('type' => 'text', 'not null' => FALSE), | 
| webmaster@1 | 1735       ), | 
| webmaster@1 | 1736       'primary key' => array('menu_name'), | 
| webmaster@1 | 1737     ); | 
| webmaster@1 | 1738     db_create_table($ret, 'menu_custom', $table); | 
| webmaster@1 | 1739     db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menus['navigation']); | 
| webmaster@1 | 1740     $_SESSION['system_update_6021'] = 0; | 
| webmaster@1 | 1741   } | 
| webmaster@1 | 1742 | 
| webmaster@1 | 1743   $limit = 50; | 
| webmaster@1 | 1744   while ($limit-- && ($item = db_fetch_array(db_query_range('SELECT * FROM {menu} WHERE converted = 0', 0, 1)))) { | 
| webmaster@1 | 1745     // If it's not a menu... | 
| webmaster@1 | 1746     if ($item['pid']) { | 
| webmaster@1 | 1747       // Let's climb up until we find an item with a converted parent. | 
| webmaster@1 | 1748       $item_original = $item; | 
| webmaster@1 | 1749       while ($item && !isset($_SESSION['menu_item_map'][$item['pid']])) { | 
| webmaster@1 | 1750         $item = db_fetch_array(db_query('SELECT * FROM {menu} WHERE mid = %d', $item['pid'])); | 
| webmaster@1 | 1751       } | 
| webmaster@1 | 1752       // This can only occur if the menu entry is a leftover in the menu table. | 
| webmaster@1 | 1753       // These do not appear in Drupal 5 anyways, so we skip them. | 
| webmaster@1 | 1754       if (!$item) { | 
| webmaster@1 | 1755         db_query('UPDATE {menu} SET converted = %d WHERE mid = %d', 1, $item_original['mid']); | 
| webmaster@1 | 1756         $_SESSION['system_update_6021']++; | 
| webmaster@1 | 1757         continue; | 
| webmaster@1 | 1758       } | 
| webmaster@1 | 1759     } | 
| webmaster@1 | 1760     // We need to recheck because item might have changed. | 
| webmaster@1 | 1761     if ($item['pid']) { | 
| webmaster@1 | 1762       // Fill the new fields. | 
| webmaster@1 | 1763       $item['link_title'] = $item['title']; | 
| webmaster@1 | 1764       $item['link_path'] = drupal_get_normal_path($item['path']); | 
| webmaster@1 | 1765       // We know the parent is already set. If it's not FALSE then it's an item. | 
| webmaster@1 | 1766       if ($_SESSION['menu_item_map'][$item['pid']]) { | 
| webmaster@1 | 1767         // The new menu system parent link id. | 
| webmaster@1 | 1768         $item['plid'] = $_SESSION['menu_item_map'][$item['pid']]['mlid']; | 
| webmaster@1 | 1769         // The new menu system menu name. | 
| webmaster@1 | 1770         $item['menu_name'] = $_SESSION['menu_item_map'][$item['pid']]['menu_name']; | 
| webmaster@1 | 1771       } | 
| webmaster@1 | 1772       else { | 
| webmaster@1 | 1773         // This a top level element. | 
| webmaster@1 | 1774         $item['plid'] = 0; | 
| webmaster@1 | 1775         // The menu name is stored among the menus. | 
| webmaster@1 | 1776         $item['menu_name'] = $_SESSION['menu_menu_map'][$item['pid']]; | 
| webmaster@1 | 1777       } | 
| webmaster@1 | 1778       // Is the element visible in the menu block? | 
| webmaster@1 | 1779       $item['hidden'] = !($item['type'] & MENU_VISIBLE_IN_TREE); | 
| webmaster@1 | 1780       // Is it a custom(ized) element? | 
| webmaster@1 | 1781       if ($item['type'] & (MENU_CREATED_BY_ADMIN | MENU_MODIFIED_BY_ADMIN)) { | 
| webmaster@1 | 1782         $item['customized'] = TRUE; | 
| webmaster@1 | 1783       } | 
| webmaster@1 | 1784       // Items created via the menu module need to be assigned to it. | 
| webmaster@1 | 1785       if ($item['type'] & MENU_CREATED_BY_ADMIN) { | 
| webmaster@1 | 1786         $item['module'] = 'menu'; | 
| webmaster@1 | 1787         $item['router_path'] = ''; | 
| webmaster@1 | 1788         $item['updated'] = TRUE; | 
| webmaster@1 | 1789       } | 
| webmaster@1 | 1790       else { | 
| webmaster@1 | 1791         $item['module'] = 'system'; | 
| webmaster@1 | 1792         $item['router_path'] = $item['path']; | 
| webmaster@1 | 1793         $item['updated'] = FALSE; | 
| webmaster@1 | 1794       } | 
| webmaster@1 | 1795       // Save the link. | 
| webmaster@1 | 1796       menu_link_save($item); | 
| webmaster@1 | 1797       $_SESSION['menu_item_map'][$item['mid']] = array('mlid' => $item['mlid'], 'menu_name' => $item['menu_name']); | 
| webmaster@1 | 1798     } | 
| webmaster@1 | 1799     elseif (!isset($_SESSION['menu_menu_map'][$item['mid']])) { | 
| webmaster@1 | 1800       $item['menu_name'] = 'menu-'. preg_replace('/[^a-zA-Z0-9]/', '-', strtolower($item['title'])); | 
| webmaster@1 | 1801       $item['menu_name'] = substr($item['menu_name'], 0, 20); | 
| webmaster@1 | 1802       $original_menu_name = $item['menu_name']; | 
| webmaster@1 | 1803       $i = 0; | 
| webmaster@1 | 1804       while (db_result(db_query("SELECT menu_name FROM {menu_custom} WHERE menu_name = '%s'", $item['menu_name']))) { | 
| webmaster@1 | 1805         $item['menu_name'] = $original_menu_name . ($i++); | 
| webmaster@1 | 1806       } | 
| webmaster@1 | 1807       if ($item['path']) { | 
| webmaster@1 | 1808         // Another bunch of bogus entries. Apparently, these are leftovers | 
| webmaster@1 | 1809         // from Drupal 4.7 . | 
| webmaster@1 | 1810         $_SESSION['menu_bogus_menus'][] = $item['menu_name']; | 
| webmaster@1 | 1811       } | 
| webmaster@1 | 1812       else { | 
| webmaster@1 | 1813         // Add this menu to the list of custom menus. | 
| webmaster@1 | 1814         db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '')", $item['menu_name'], $item['title']); | 
| webmaster@1 | 1815       } | 
| webmaster@1 | 1816       $_SESSION['menu_menu_map'][$item['mid']] = $item['menu_name']; | 
| webmaster@1 | 1817       $_SESSION['menu_item_map'][$item['mid']] = FALSE; | 
| webmaster@1 | 1818     } | 
| webmaster@1 | 1819     db_query('UPDATE {menu} SET converted = %d WHERE mid = %d', 1, $item['mid']); | 
| webmaster@1 | 1820     $_SESSION['system_update_6021']++; | 
| webmaster@1 | 1821   } | 
| webmaster@1 | 1822 | 
| webmaster@1 | 1823   if ($_SESSION['system_update_6021'] >= $_SESSION['system_update_6021_max']) { | 
| webmaster@1 | 1824     if (!empty($_SESSION['menu_bogus_menus'])) { | 
| webmaster@1 | 1825       // Remove entries in bogus menus. This is secure because we deleted | 
| webmaster@1 | 1826       // every non-alpanumeric character from the menu name. | 
| webmaster@1 | 1827       $ret[] = update_sql("DELETE FROM {menu_links} WHERE menu_name IN ('". implode("', '", $_SESSION['menu_bogus_menus']) ."')"); | 
| webmaster@1 | 1828     } | 
| webmaster@1 | 1829 | 
| webmaster@1 | 1830     $menu_primary_menu = variable_get('menu_primary_menu', 0); | 
| webmaster@1 | 1831     // Ensure that we wind up with a system menu named 'primary-links'. | 
| webmaster@1 | 1832     if (isset($_SESSION['menu_menu_map'][2])) { | 
| webmaster@1 | 1833       // The primary links menu that ships with Drupal 5 has mid = 2.  If this | 
| webmaster@1 | 1834       // menu hasn't been deleted by the site admin, we use that. | 
| webmaster@1 | 1835       $updated_primary_links_menu = 2; | 
| webmaster@1 | 1836     } | 
| webmaster@1 | 1837     elseif (isset($_SESSION['menu_menu_map'][$menu_primary_menu]) && $menu_primary_menu > 1) { | 
| webmaster@1 | 1838       // Otherwise, we use the menu that is currently assigned to the primary | 
| webmaster@1 | 1839       // links region of the theme, as long as it exists and isn't the | 
| webmaster@1 | 1840       // Navigation menu. | 
| webmaster@1 | 1841       $updated_primary_links_menu = $menu_primary_menu; | 
| webmaster@1 | 1842     } | 
| webmaster@1 | 1843     else { | 
| webmaster@1 | 1844       // As a last resort, create 'primary-links' as a new menu. | 
| webmaster@1 | 1845       $updated_primary_links_menu = 0; | 
| webmaster@1 | 1846       db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menus['primary-links']); | 
| webmaster@1 | 1847     } | 
| webmaster@1 | 1848 | 
| webmaster@1 | 1849     if ($updated_primary_links_menu) { | 
| webmaster@1 | 1850       // Change the existing menu name to 'primary-links'. | 
| webmaster@1 | 1851       $replace = array('%new_name' => 'primary-links', '%desc' => $menus['primary-links']['description'], '%old_name' => $_SESSION['menu_menu_map'][$updated_primary_links_menu]); | 
| webmaster@1 | 1852       $ret[] = update_sql(strtr("UPDATE {menu_custom} SET menu_name = '%new_name', description = '%desc' WHERE menu_name = '%old_name'", $replace)); | 
| webmaster@1 | 1853       $ret[] = update_sql("UPDATE {menu_links} SET menu_name = 'primary-links' WHERE menu_name = '". $_SESSION['menu_menu_map'][$updated_primary_links_menu] ."'"); | 
| webmaster@1 | 1854       $_SESSION['menu_menu_map'][$updated_primary_links_menu] = 'primary-links'; | 
| webmaster@1 | 1855     } | 
| webmaster@1 | 1856 | 
| webmaster@1 | 1857     $menu_secondary_menu = variable_get('menu_secondary_menu', 0); | 
| webmaster@1 | 1858     // Ensure that we wind up with a system menu named 'secondary-links'. | 
| webmaster@1 | 1859     if (isset($_SESSION['menu_menu_map'][$menu_secondary_menu]) && $menu_secondary_menu > 1 && $menu_secondary_menu != $updated_primary_links_menu) { | 
| webmaster@1 | 1860       // We use the menu that is currently assigned to the secondary links | 
| webmaster@1 | 1861       // region of the theme, as long as (a) it exists, (b) it isn't the | 
| webmaster@1 | 1862       // Navigation menu, (c) it isn't the same menu we assigned as the | 
| webmaster@1 | 1863       // system 'primary-links' menu above, and (d) it isn't the same menu | 
| webmaster@1 | 1864       // assigned to the primary links region of the theme. | 
| webmaster@1 | 1865       $updated_secondary_links_menu = $menu_secondary_menu; | 
| webmaster@1 | 1866     } | 
| webmaster@1 | 1867     else { | 
| webmaster@1 | 1868       // Otherwise, create 'secondary-links' as a new menu. | 
| webmaster@1 | 1869       $updated_secondary_links_menu = 0; | 
| webmaster@1 | 1870       db_query("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('%s', '%s', '%s')", $menus['secondary-links']); | 
| webmaster@1 | 1871     } | 
| webmaster@1 | 1872 | 
| webmaster@1 | 1873     if ($updated_secondary_links_menu) { | 
| webmaster@1 | 1874       // Change the existing menu name to 'secondary-links'. | 
| webmaster@1 | 1875       $replace = array('%new_name' => 'secondary-links', '%desc' => $menus['secondary-links']['description'], '%old_name' => $_SESSION['menu_menu_map'][$updated_secondary_links_menu]); | 
| webmaster@1 | 1876       $ret[] = update_sql(strtr("UPDATE {menu_custom} SET menu_name = '%new_name', description = '%desc' WHERE menu_name = '%old_name'", $replace)); | 
| webmaster@1 | 1877       $ret[] = update_sql("UPDATE {menu_links} SET menu_name = 'secondary-links' WHERE menu_name = '". $_SESSION['menu_menu_map'][$updated_secondary_links_menu] ."'"); | 
| webmaster@1 | 1878       $_SESSION['menu_menu_map'][$updated_secondary_links_menu] = 'secondary-links'; | 
| webmaster@1 | 1879     } | 
| webmaster@1 | 1880 | 
| webmaster@1 | 1881     // Update menu OTF preferences. | 
| webmaster@1 | 1882     $mid = variable_get('menu_parent_items', 0); | 
| webmaster@1 | 1883     $menu_name = ($mid && isset($_SESSION['menu_menu_map'][$mid])) ? $_SESSION['menu_menu_map'][$mid] : 'navigation'; | 
| webmaster@1 | 1884     variable_set('menu_default_node_menu', $menu_name); | 
| webmaster@1 | 1885     variable_del('menu_parent_items'); | 
| webmaster@1 | 1886 | 
| webmaster@1 | 1887     // Update the source of the primary and secondary links. | 
| webmaster@1 | 1888     $menu_name = ($menu_primary_menu && isset($_SESSION['menu_menu_map'][$menu_primary_menu])) ? $_SESSION['menu_menu_map'][$menu_primary_menu] : ''; | 
| webmaster@1 | 1889     variable_set('menu_primary_links_source', $menu_name); | 
| webmaster@1 | 1890     variable_del('menu_primary_menu'); | 
| webmaster@1 | 1891 | 
| webmaster@1 | 1892     $menu_name = ($menu_secondary_menu && isset($_SESSION['menu_menu_map'][$menu_secondary_menu])) ? $_SESSION['menu_menu_map'][$menu_secondary_menu] : ''; | 
| webmaster@1 | 1893     variable_set('menu_secondary_links_source', $menu_name); | 
| webmaster@1 | 1894     variable_del('menu_secondary_menu'); | 
| webmaster@1 | 1895 | 
| webmaster@1 | 1896     // Skip the navigation menu - it is handled by the user module. | 
| webmaster@1 | 1897     unset($_SESSION['menu_menu_map'][1]); | 
| webmaster@1 | 1898     // Update the deltas for all menu module blocks. | 
| webmaster@1 | 1899     foreach ($_SESSION['menu_menu_map'] as $mid => $menu_name) { | 
| webmaster@1 | 1900       // This is again secure because we deleted every non-alpanumeric | 
| webmaster@1 | 1901       // character from the menu name. | 
| webmaster@1 | 1902       $ret[] = update_sql("UPDATE {blocks} SET delta = '". $menu_name ."' WHERE module = 'menu' AND delta = '". $mid ."'"); | 
| webmaster@1 | 1903       $ret[] = update_sql("UPDATE {blocks_roles} SET delta = '". $menu_name ."' WHERE module = 'menu' AND delta = '". $mid ."'"); | 
| webmaster@1 | 1904     } | 
| webmaster@1 | 1905     $ret[] = array('success' => TRUE, 'query' => 'Relocated '. $_SESSION['system_update_6021'] .' existing items to the new menu system.'); | 
| webmaster@1 | 1906     $ret[] = update_sql("DROP TABLE {menu}"); | 
| webmaster@1 | 1907     unset($_SESSION['system_update_6021'], $_SESSION['system_update_6021_max'], $_SESSION['menu_menu_map'], $_SESSION['menu_item_map'], $_SESSION['menu_bogus_menus']); | 
| webmaster@1 | 1908     // Create the menu overview links - also calls menu_rebuild(). If menu is | 
| webmaster@1 | 1909     // disabled, then just call menu_rebuild. | 
| webmaster@1 | 1910     if (function_exists('menu_enable')) { | 
| webmaster@1 | 1911       menu_enable(); | 
| webmaster@1 | 1912     } | 
| webmaster@1 | 1913     else { | 
| webmaster@1 | 1914       menu_rebuild(); | 
| webmaster@1 | 1915     } | 
| webmaster@1 | 1916     $ret['#finished'] = 1; | 
| webmaster@1 | 1917   } | 
| webmaster@1 | 1918   else { | 
| webmaster@1 | 1919     $ret['#finished'] = $_SESSION['system_update_6021'] / $_SESSION['system_update_6021_max']; | 
| webmaster@1 | 1920   } | 
| webmaster@1 | 1921   return $ret; | 
| webmaster@1 | 1922 } | 
| webmaster@1 | 1923 | 
| webmaster@1 | 1924 /** | 
| webmaster@1 | 1925  * Update files tables to associate files to a uid by default instead of a nid. | 
| webmaster@1 | 1926  * Rename file_revisions to upload since it should only be used by the upload | 
| webmaster@1 | 1927  * module used by upload to link files to nodes. | 
| webmaster@1 | 1928  */ | 
| webmaster@1 | 1929 function system_update_6022() { | 
| webmaster@1 | 1930   $ret = array(); | 
| webmaster@1 | 1931 | 
| webmaster@1 | 1932   // Rename the nid field to vid, add status and timestamp fields, and indexes. | 
| webmaster@1 | 1933   db_drop_index($ret, 'files', 'nid'); | 
| webmaster@1 | 1934   db_change_field($ret, 'files', 'nid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1935   db_add_field($ret, 'files', 'status', array('type' => 'int', 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1936   db_add_field($ret, 'files', 'timestamp', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1937   db_add_index($ret, 'files', 'uid', array('uid')); | 
| webmaster@1 | 1938   db_add_index($ret, 'files', 'status', array('status')); | 
| webmaster@1 | 1939   db_add_index($ret, 'files', 'timestamp', array('timestamp')); | 
| webmaster@1 | 1940 | 
| webmaster@1 | 1941   // Rename the file_revisions table to upload then add nid column. Since we're | 
| webmaster@1 | 1942   // changing the table name we need to drop and re-add the indexes and | 
| webmaster@1 | 1943   // the primary key so both mysql and pgsql end up with the correct index | 
| webmaster@1 | 1944   // names. | 
| webmaster@1 | 1945   db_drop_primary_key($ret, 'file_revisions'); | 
| webmaster@1 | 1946   db_drop_index($ret, 'file_revisions', 'vid'); | 
| webmaster@1 | 1947   db_rename_table($ret, 'file_revisions', 'upload'); | 
| webmaster@1 | 1948   db_add_field($ret, 'upload', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1949   db_add_index($ret, 'upload', 'nid', array('nid')); | 
| webmaster@1 | 1950   db_add_primary_key($ret, 'upload', array('vid', 'fid')); | 
| webmaster@1 | 1951   db_add_index($ret, 'upload', 'fid', array('fid')); | 
| webmaster@1 | 1952 | 
| webmaster@1 | 1953   // The nid column was renamed to uid. Use the old nid to find the node's uid. | 
| webmaster@1 | 1954   update_sql('UPDATE {files} SET uid = (SELECT n.uid FROM {node} n WHERE {files}.uid = n.nid)'); | 
| webmaster@1 | 1955   update_sql('UPDATE {upload} SET nid = (SELECT r.nid FROM {node_revisions} r WHERE {upload}.vid = r.vid)'); | 
| webmaster@1 | 1956 | 
| webmaster@1 | 1957   // Mark all existing files as FILE_STATUS_PERMANENT. | 
| webmaster@1 | 1958   $ret[] = update_sql('UPDATE {files} SET status = 1'); | 
| webmaster@1 | 1959 | 
| webmaster@1 | 1960   return $ret; | 
| webmaster@1 | 1961 } | 
| webmaster@1 | 1962 | 
| webmaster@1 | 1963 function system_update_6023() { | 
| webmaster@1 | 1964   $ret = array(); | 
| webmaster@1 | 1965 | 
| webmaster@1 | 1966   // nid is DEFAULT 0 | 
| webmaster@1 | 1967   db_drop_index($ret, 'node_revisions', 'nid'); | 
| webmaster@1 | 1968   db_change_field($ret, 'node_revisions', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1969   db_add_index($ret, 'node_revisions', 'nid', array('nid')); | 
| webmaster@1 | 1970   return $ret; | 
| webmaster@1 | 1971 } | 
| webmaster@1 | 1972 | 
| webmaster@1 | 1973 /** | 
| webmaster@1 | 1974  * Add translation fields to nodes used by translation module. | 
| webmaster@1 | 1975  */ | 
| webmaster@1 | 1976 function system_update_6024() { | 
| webmaster@1 | 1977   $ret = array(); | 
| webmaster@1 | 1978   db_add_field($ret, 'node', 'tnid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1979   db_add_field($ret, 'node', 'translate', array('type' => 'int', 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 1980   db_add_index($ret, 'node', 'tnid', array('tnid')); | 
| webmaster@1 | 1981   db_add_index($ret, 'node', 'translate', array('translate')); | 
| webmaster@1 | 1982   return $ret; | 
| webmaster@1 | 1983 } | 
| webmaster@1 | 1984 | 
| webmaster@1 | 1985 /** | 
| webmaster@1 | 1986  * Increase the maximum length of node titles from 128 to 255. | 
| webmaster@1 | 1987  */ | 
| webmaster@1 | 1988 function system_update_6025() { | 
| webmaster@1 | 1989   $ret = array(); | 
| webmaster@1 | 1990   db_drop_index($ret, 'node', 'node_title_type'); | 
| webmaster@1 | 1991   db_change_field($ret, 'node', 'title', 'title', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); | 
| webmaster@1 | 1992   db_add_index($ret, 'node', 'node_title_type', array('title', array('type', 4))); | 
| webmaster@1 | 1993   db_change_field($ret, 'node_revisions', 'title', 'title', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); | 
| webmaster@1 | 1994   return $ret; | 
| webmaster@1 | 1995 } | 
| webmaster@1 | 1996 | 
| webmaster@1 | 1997 /** | 
| webmaster@1 | 1998  * Display warning about new Update status module. | 
| webmaster@1 | 1999  */ | 
| webmaster@1 | 2000 function system_update_6026() { | 
| webmaster@1 | 2001   $ret = array(); | 
| webmaster@1 | 2002 | 
| webmaster@1 | 2003   // Notify user that new update module exists. | 
| webmaster@1 | 2004   drupal_set_message('Drupal can check periodically for important bug fixes and security releases using the new update status module. This module can be turned on from the <a href="'. url('admin/build/modules') .'">modules administration page</a>. For more information please read the <a href="http://drupal.org/handbook/modules/update">Update status handbook page</a>.'); | 
| webmaster@1 | 2005 | 
| webmaster@1 | 2006   return $ret; | 
| webmaster@1 | 2007 } | 
| webmaster@1 | 2008 | 
| webmaster@1 | 2009 /** | 
| webmaster@1 | 2010  * Add block cache. | 
| webmaster@1 | 2011  */ | 
| webmaster@1 | 2012 function system_update_6027() { | 
| webmaster@1 | 2013   $ret = array(); | 
| webmaster@1 | 2014 | 
| webmaster@1 | 2015   // Create the blocks.cache column. | 
| webmaster@1 | 2016   db_add_field($ret, 'blocks', 'cache', array('type' => 'int', 'not null' => TRUE, 'default' => 1, 'size' => 'tiny')); | 
| webmaster@1 | 2017 | 
| webmaster@1 | 2018   // The cache_block table is created in update_fix_d6_requirements() since | 
| webmaster@1 | 2019   // calls to cache_clear_all() would otherwise cause warnings. | 
| webmaster@1 | 2020 | 
| webmaster@1 | 2021   // Fill in the values for the new 'cache' column in the {blocks} table. | 
| webmaster@1 | 2022   foreach (module_list() as $module) { | 
| webmaster@1 | 2023     if ($module_blocks = module_invoke($module, 'block', 'list')) { | 
| webmaster@1 | 2024       foreach ($module_blocks as $delta => $block) { | 
| webmaster@1 | 2025         if (isset($block['cache'])) { | 
| webmaster@1 | 2026           db_query("UPDATE {blocks} SET cache = %d WHERE module = '%s' AND delta = %d", $block['cache'], $module, $delta); | 
| webmaster@1 | 2027         } | 
| webmaster@1 | 2028       } | 
| webmaster@1 | 2029     } | 
| webmaster@1 | 2030   } | 
| webmaster@1 | 2031 | 
| webmaster@1 | 2032   return $ret; | 
| webmaster@1 | 2033 } | 
| webmaster@1 | 2034 | 
| webmaster@1 | 2035 /** | 
| webmaster@1 | 2036  * Add the node load cache table. | 
| webmaster@1 | 2037  */ | 
| webmaster@1 | 2038 function system_update_6028() { | 
| webmaster@1 | 2039   // Removed node_load cache to discuss it more for Drupal 7. | 
| webmaster@1 | 2040   return array(); | 
| webmaster@1 | 2041 } | 
| webmaster@1 | 2042 | 
| webmaster@1 | 2043 /** | 
| webmaster@1 | 2044  * Enable the dblog module on sites that upgrade, since otherwise | 
| webmaster@1 | 2045  * watchdog logging will stop unexpectedly. | 
| webmaster@1 | 2046  */ | 
| webmaster@1 | 2047 function system_update_6029() { | 
| webmaster@1 | 2048   // The watchdog table is now owned by dblog, which is not yet | 
| webmaster@1 | 2049   // "installed" according to the system table, but the table already | 
| webmaster@1 | 2050   // exists.  We set the module as "installed" here to avoid an error | 
| webmaster@1 | 2051   // later. | 
| webmaster@1 | 2052   // | 
| webmaster@1 | 2053   // Although not the case for the initial D6 release, it is likely | 
| webmaster@1 | 2054   // that dblog.install will have its own update functions eventually. | 
| webmaster@1 | 2055   // However, dblog did not exist in D5 and this update is part of the | 
| webmaster@1 | 2056   // initial D6 release, so we know that dblog is not installed yet. | 
| webmaster@1 | 2057   // It is therefore correct to install it as version 0.  If | 
| webmaster@1 | 2058   // dblog updates exist, the next run of update.php will get them. | 
| webmaster@1 | 2059   drupal_set_installed_schema_version('dblog', 0); | 
| webmaster@1 | 2060   module_enable(array('dblog')); | 
| webmaster@1 | 2061   menu_rebuild(); | 
| webmaster@1 | 2062   return array(array('success' => TRUE, 'query' => "'dblog' module enabled.")); | 
| webmaster@1 | 2063 } | 
| webmaster@1 | 2064 | 
| webmaster@1 | 2065 /** | 
| webmaster@1 | 2066  * Add the tables required by actions.inc. | 
| webmaster@1 | 2067  */ | 
| webmaster@1 | 2068 function system_update_6030() { | 
| webmaster@1 | 2069   $ret = array(); | 
| webmaster@1 | 2070 | 
| webmaster@1 | 2071   // Rename the old contrib actions table if it exists so the contrib version | 
| webmaster@1 | 2072   // of the module can do something with the old data. | 
| webmaster@1 | 2073   if (db_table_exists('actions')) { | 
| webmaster@1 | 2074     db_rename_table($ret, 'actions', 'actions_old_contrib'); | 
| webmaster@1 | 2075   } | 
| webmaster@1 | 2076 | 
| webmaster@1 | 2077   $schema['actions'] = array( | 
| webmaster@1 | 2078     'fields' => array( | 
| webmaster@1 | 2079       'aid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'), | 
| webmaster@1 | 2080       'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 2081       'callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 2082       'parameters' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'), | 
| webmaster@1 | 2083       'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'), | 
| webmaster@1 | 2084     ), | 
| webmaster@1 | 2085     'primary key' => array('aid'), | 
| webmaster@1 | 2086   ); | 
| webmaster@1 | 2087 | 
| webmaster@1 | 2088   $schema['actions_aid'] = array( | 
| webmaster@1 | 2089     'fields' => array( | 
| webmaster@1 | 2090       'aid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), | 
| webmaster@1 | 2091     ), | 
| webmaster@1 | 2092     'primary key' => array('aid'), | 
| webmaster@1 | 2093   ); | 
| webmaster@1 | 2094 | 
| webmaster@1 | 2095   db_create_table($ret, 'actions', $schema['actions']); | 
| webmaster@1 | 2096   db_create_table($ret, 'actions_aid', $schema['actions_aid']); | 
| webmaster@1 | 2097 | 
| webmaster@1 | 2098   return $ret; | 
| webmaster@1 | 2099 } | 
| webmaster@1 | 2100 | 
| webmaster@1 | 2101 /** | 
| webmaster@1 | 2102  * Ensure that installer cannot be run again after updating from Drupal 5.x to 6.x | 
| webmaster@1 | 2103  * Actually, this is already done by system_update_6014(), so this is now a no-op. | 
| webmaster@1 | 2104  */ | 
| webmaster@1 | 2105 function system_update_6031() { | 
| webmaster@1 | 2106   return array(); | 
| webmaster@1 | 2107 } | 
| webmaster@1 | 2108 | 
| webmaster@1 | 2109 /** | 
| webmaster@1 | 2110  * profile_fields.name used to be nullable but is part of a unique key | 
| webmaster@1 | 2111  * and so shouldn't be. | 
| webmaster@1 | 2112  */ | 
| webmaster@1 | 2113 function system_update_6032() { | 
| webmaster@1 | 2114   $ret = array(); | 
| webmaster@1 | 2115   if (db_table_exists('profile_fields')) { | 
| webmaster@1 | 2116     db_drop_unique_key($ret, 'profile_fields', 'name'); | 
| webmaster@1 | 2117     db_change_field($ret, 'profile_fields', 'name', 'name', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '')); | 
| webmaster@1 | 2118     db_add_unique_key($ret, 'profile_fields', 'name', array('name')); | 
| webmaster@1 | 2119   } | 
| webmaster@1 | 2120   return $ret; | 
| webmaster@1 | 2121 } | 
| webmaster@1 | 2122 | 
| webmaster@1 | 2123 /** | 
| webmaster@1 | 2124  * Change node_comment_statistics to be not autoincrement. | 
| webmaster@1 | 2125  */ | 
| webmaster@1 | 2126 function system_update_6033() { | 
| webmaster@1 | 2127   $ret = array(); | 
| webmaster@1 | 2128   if (db_table_exists('node_comment_statistics')) { | 
| webmaster@1 | 2129     // On pgsql but not mysql, db_change_field() drops all keys | 
| webmaster@1 | 2130     // involving the changed field, which in this case is the primary | 
| webmaster@1 | 2131     // key.  The normal approach is explicitly drop the pkey, change the | 
| webmaster@1 | 2132     // field, and re-create the pkey. | 
| webmaster@1 | 2133     // | 
| webmaster@1 | 2134     // Unfortunately, in this case that won't work on mysql; we CANNOT | 
| webmaster@1 | 2135     // drop the pkey because on mysql auto-increment fields must be | 
| webmaster@1 | 2136     // included in at least one key or index. | 
| webmaster@1 | 2137     // | 
| webmaster@1 | 2138     // Since we cannot drop the pkey before db_change_field(), after | 
| webmaster@1 | 2139     // db_change_field() we may or may not still have a pkey.  The | 
| webmaster@1 | 2140     // simple way out is to re-create the pkey only when using pgsql. | 
| webmaster@1 | 2141     // Realistic requirements trump idealistic purity. | 
| webmaster@1 | 2142     db_change_field($ret, 'node_comment_statistics', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 2143     if ($GLOBALS['db_type'] == 'pgsql') { | 
| webmaster@1 | 2144       db_add_primary_key($ret, 'node_comment_statistics', array('nid')); | 
| webmaster@1 | 2145     } | 
| webmaster@1 | 2146   } | 
| webmaster@1 | 2147   return $ret; | 
| webmaster@1 | 2148 } | 
| webmaster@1 | 2149 | 
| webmaster@1 | 2150 /** | 
| webmaster@1 | 2151  * Rename permission "administer access control" to "administer permissions". | 
| webmaster@1 | 2152  */ | 
| webmaster@1 | 2153 function system_update_6034() { | 
| webmaster@1 | 2154   $ret = array(); | 
| webmaster@1 | 2155   $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid"); | 
| webmaster@1 | 2156   while ($role = db_fetch_object($result)) { | 
| webmaster@1 | 2157     $renamed_permission = preg_replace('/administer access control/', 'administer permissions', $role->perm); | 
| webmaster@1 | 2158     if ($renamed_permission != $role->perm) { | 
| webmaster@1 | 2159       $ret[] = update_sql("UPDATE {permission} SET perm = '$renamed_permission' WHERE rid = $role->rid"); | 
| webmaster@1 | 2160     } | 
| webmaster@1 | 2161   } | 
| webmaster@1 | 2162   return $ret; | 
| webmaster@1 | 2163 } | 
| webmaster@1 | 2164 | 
| webmaster@1 | 2165 /** | 
| webmaster@1 | 2166  * Change index on system table for better performance. | 
| webmaster@1 | 2167  */ | 
| webmaster@1 | 2168 function system_update_6035() { | 
| webmaster@1 | 2169   $ret = array(); | 
| webmaster@1 | 2170   db_drop_index($ret, 'system', 'weight'); | 
| webmaster@1 | 2171   db_add_index($ret, 'system', 'modules', array(array('type', 12), 'status', 'weight', 'filename')); | 
| webmaster@1 | 2172   db_add_index($ret, 'system', 'bootstrap', array(array('type', 12), 'status', 'bootstrap', 'weight', 'filename')); | 
| webmaster@1 | 2173   return $ret; | 
| webmaster@1 | 2174 } | 
| webmaster@1 | 2175 | 
| webmaster@1 | 2176 /** | 
| webmaster@1 | 2177  * Change the search schema and indexing. | 
| webmaster@1 | 2178  * | 
| webmaster@1 | 2179  * The table data is preserved where possible in MYSQL and MYSQLi using | 
| webmaster@1 | 2180  * ALTER IGNORE. Other databases don't support that, so for them the | 
| webmaster@1 | 2181  * tables are dropped and re-created, and will need to be re-indexed | 
| webmaster@1 | 2182  * from scratch. | 
| webmaster@1 | 2183  */ | 
| webmaster@1 | 2184 function system_update_6036() { | 
| webmaster@1 | 2185   $ret = array(); | 
| webmaster@1 | 2186   if (db_table_exists('search_index')) { | 
| webmaster@1 | 2187     // Create the search_dataset.reindex column. | 
| webmaster@1 | 2188     db_add_field($ret, 'search_dataset', 'reindex', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); | 
| webmaster@1 | 2189 | 
| webmaster@1 | 2190     // Drop the search_index.from fields which are no longer used. | 
| webmaster@1 | 2191     db_drop_index($ret, 'search_index', 'from_sid_type'); | 
| webmaster@1 | 2192     db_drop_field($ret, 'search_index', 'fromsid'); | 
| webmaster@1 | 2193     db_drop_field($ret, 'search_index', 'fromtype'); | 
| webmaster@1 | 2194 | 
| webmaster@1 | 2195     // Drop the search_dataset.sid_type index, so that it can be made unique. | 
| webmaster@1 | 2196     db_drop_index($ret, 'search_dataset', 'sid_type'); | 
| webmaster@1 | 2197 | 
| webmaster@1 | 2198     // Create the search_node_links Table. | 
| webmaster@1 | 2199     $search_node_links_schema = array( | 
| webmaster@1 | 2200       'fields' => array( | 
| webmaster@1 | 2201         'sid'      => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 2202         'type'     => array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''), | 
| webmaster@1 | 2203         'nid'      => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), | 
| webmaster@1 | 2204         'caption'    => array('type' => 'text', 'size' => 'big', 'not null' => FALSE), | 
| webmaster@1 | 2205       ), | 
| webmaster@1 | 2206       'primary key' => array('sid', 'type', 'nid'), | 
| webmaster@1 | 2207       'indexes' => array('nid' => array('nid')), | 
| webmaster@1 | 2208     ); | 
| webmaster@1 | 2209     db_create_table($ret, 'search_node_links', $search_node_links_schema); | 
| webmaster@1 | 2210 | 
| webmaster@1 | 2211     // with the change to search_dataset.reindex, the search queue is handled differently, | 
| webmaster@1 | 2212     // and this is no longer needed | 
| webmaster@1 | 2213     variable_del('node_cron_last'); | 
| webmaster@1 | 2214 | 
| webmaster@1 | 2215     // Add a unique index for the search_index. | 
| webmaster@1 | 2216     if ($GLOBALS['db_type'] == 'mysql' || $GLOBALS['db_type'] == 'mysqli') { | 
| webmaster@1 | 2217       // Since it's possible that some existing sites have duplicates, | 
| webmaster@1 | 2218       // create the index using the IGNORE keyword, which ignores duplicate errors. | 
| webmaster@1 | 2219       // However, pgsql doesn't support it | 
| webmaster@1 | 2220       $ret[] = update_sql("ALTER IGNORE TABLE {search_index} ADD UNIQUE KEY word_sid_type (word, sid, type)"); | 
| webmaster@1 | 2221       $ret[] = update_sql("ALTER IGNORE TABLE {search_dataset} ADD UNIQUE KEY sid_type (sid, type)"); | 
| webmaster@1 | 2222 | 
| webmaster@1 | 2223       // Everything needs to be reindexed. | 
| webmaster@1 | 2224       $ret[] = update_sql("UPDATE {search_dataset} SET reindex = 1"); | 
| webmaster@1 | 2225     } | 
| webmaster@1 | 2226     else { | 
| webmaster@1 | 2227       // Delete the existing tables if there are duplicate values | 
| webmaster@1 | 2228       if (db_result(db_query("SELECT sid FROM {search_dataset} GROUP BY sid, type HAVING COUNT(*) > 1")) || db_result(db_query("SELECT sid FROM {search_index} GROUP BY word, sid, type HAVING COUNT(*) > 1"))) { | 
| webmaster@1 | 2229         $ret[] = update_sql('DELETE FROM {search_dataset}'); | 
| webmaster@1 | 2230         $ret[] = update_sql('DELETE FROM {search_index}'); | 
| webmaster@1 | 2231         $ret[] = update_sql('DELETE FROM {search_total}'); | 
| webmaster@1 | 2232       } | 
| webmaster@1 | 2233       else { | 
| webmaster@1 | 2234         // Everything needs to be reindexed. | 
| webmaster@1 | 2235         $ret[] = update_sql("UPDATE {search_dataset} SET reindex = 1"); | 
| webmaster@1 | 2236       } | 
| webmaster@1 | 2237 | 
| webmaster@1 | 2238       // create the new indexes | 
| webmaster@1 | 2239       db_add_unique_key($ret, 'search_index', 'word_sid_type', array('word', 'sid', 'type')); | 
| webmaster@1 | 2240       db_add_unique_key($ret, 'search_dataset', 'sid_type', array('sid', 'type')); | 
| webmaster@1 | 2241     } | 
| webmaster@1 | 2242   } | 
| webmaster@1 | 2243   return $ret; | 
| webmaster@1 | 2244 } | 
| webmaster@1 | 2245 | 
| webmaster@1 | 2246 /** | 
| webmaster@1 | 2247  * Create consistent empty region for disabled blocks. | 
| webmaster@1 | 2248  */ | 
| webmaster@1 | 2249 function system_update_6037() { | 
| webmaster@1 | 2250   $ret = array(); | 
| webmaster@1 | 2251   db_change_field($ret, 'blocks', 'region', 'region', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => '')); | 
| webmaster@1 | 2252   $ret[] = update_sql("UPDATE {blocks} SET region = '' WHERE status = 0"); | 
| webmaster@1 | 2253   return $ret; | 
| webmaster@1 | 2254 } | 
| webmaster@1 | 2255 | 
| webmaster@1 | 2256 /** | 
| webmaster@1 | 2257  * Ensure that "Account" is not used as a Profile category. | 
| webmaster@1 | 2258  */ | 
| webmaster@1 | 2259 function system_update_6038() { | 
| webmaster@1 | 2260   $ret = array(); | 
| webmaster@1 | 2261   if (db_table_exists('profile_fields')) { | 
| webmaster@1 | 2262     $ret[] = update_sql("UPDATE {profile_fields} SET category = 'Account settings' WHERE LOWER(category) = 'account'"); | 
| webmaster@1 | 2263     if ($affectedrows = db_affected_rows()) { | 
| webmaster@1 | 2264       drupal_set_message('There were '. $affectedrows .' profile fields that used a reserved category name. They have been assigned to the category "Account settings".'); | 
| webmaster@1 | 2265     } | 
| webmaster@1 | 2266   } | 
| webmaster@1 | 2267   return $ret; | 
| webmaster@1 | 2268 } | 
| webmaster@1 | 2269 | 
| webmaster@1 | 2270 /** | 
| webmaster@1 | 2271  * Rename permissions "edit foo content" to "edit any foo content". | 
| webmaster@1 | 2272  * Also update poll module permission "create polls" to "create | 
| webmaster@1 | 2273  * poll content". | 
| webmaster@1 | 2274  */ | 
| webmaster@1 | 2275 function system_update_6039() { | 
| webmaster@1 | 2276   $ret = array(); | 
| webmaster@1 | 2277   $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid"); | 
| webmaster@1 | 2278   while ($role = db_fetch_object($result)) { | 
| webmaster@1 | 2279     $renamed_permission = preg_replace('/(?<=^|,\ )edit\ ([a-zA-Z0-9_\-]+)\ content(?=,|$)/', 'edit any $1 content', $role->perm); | 
| webmaster@1 | 2280     $renamed_permission = preg_replace('/(?<=^|,\ )create\ polls(?=,|$)/', 'create poll content', $renamed_permission); | 
| webmaster@1 | 2281     if ($renamed_permission != $role->perm) { | 
| webmaster@1 | 2282       $ret[] = update_sql("UPDATE {permission} SET perm = '$renamed_permission' WHERE rid = $role->rid"); | 
| webmaster@1 | 2283     } | 
| webmaster@1 | 2284   } | 
| webmaster@1 | 2285   return $ret; | 
| webmaster@1 | 2286 } | 
| webmaster@1 | 2287 | 
| webmaster@1 | 2288 /** | 
| webmaster@1 | 2289  * Add a weight column to the upload table. | 
| webmaster@1 | 2290  */ | 
| webmaster@1 | 2291 function system_update_6040() { | 
| webmaster@1 | 2292   $ret = array(); | 
| webmaster@1 | 2293   if (db_table_exists('upload')) { | 
| webmaster@1 | 2294     db_add_field($ret, 'upload', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')); | 
| webmaster@1 | 2295   } | 
| webmaster@1 | 2296   return $ret; | 
| webmaster@1 | 2297 } | 
| webmaster@1 | 2298 | 
| webmaster@1 | 2299 /** | 
| webmaster@1 | 2300  * Change forum vocabulary not to be required by default and set the weight of the forum.module 1 higher than the taxonomy.module. | 
| webmaster@1 | 2301  */ | 
| webmaster@1 | 2302 function system_update_6041() { | 
| webmaster@1 | 2303   $weight = intval((db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"))) + 1); | 
| webmaster@1 | 2304   $ret = array(); | 
| webmaster@1 | 2305   $vid = intval(variable_get('forum_nav_vocabulary', '')); | 
| webmaster@1 | 2306   if (db_table_exists('vocabulary') && $vid) { | 
| webmaster@1 | 2307     $ret[] = update_sql("UPDATE {vocabulary} SET required = 0 WHERE vid = " . $vid); | 
| webmaster@1 | 2308     $ret[] = update_sql("UPDATE {system} SET weight = ". $weight ." WHERE name = 'forum'"); | 
| webmaster@1 | 2309   } | 
| webmaster@1 | 2310   return $ret; | 
| webmaster@1 | 2311 } | 
| webmaster@1 | 2312 | 
| webmaster@1 | 2313 /** | 
| webmaster@1 | 2314  * Upgrade recolored theme stylesheets to new array structure. | 
| webmaster@1 | 2315  */ | 
| webmaster@1 | 2316 function system_update_6042() { | 
| webmaster@1 | 2317   foreach (list_themes() as $theme) { | 
| webmaster@1 | 2318     $stylesheet = variable_get('color_'. $theme->name .'_stylesheet', NULL); | 
| webmaster@1 | 2319     if (!empty($stylesheet)) { | 
| webmaster@1 | 2320       variable_set('color_'. $theme->name .'_stylesheets', array($stylesheet)); | 
| webmaster@1 | 2321       variable_del('color_'. $theme->name .'_stylesheet'); | 
| webmaster@1 | 2322     } | 
| webmaster@1 | 2323   } | 
| webmaster@1 | 2324   return array(); | 
| webmaster@1 | 2325 } | 
| webmaster@1 | 2326 | 
| webmaster@1 | 2327 /** | 
| webmaster@1 | 2328  * Update table indices to make them more rational and useful. | 
| webmaster@1 | 2329  */ | 
| webmaster@1 | 2330 function system_update_6043() { | 
| webmaster@1 | 2331   $ret = array(); | 
| webmaster@1 | 2332   // Required modules first. | 
| webmaster@1 | 2333   // Add new system module indexes. | 
| webmaster@1 | 2334   db_add_index($ret, 'flood', 'allow', array('event', 'hostname', 'timestamp')); | 
| webmaster@1 | 2335   db_add_index($ret, 'history', 'nid', array('nid')); | 
| webmaster@1 | 2336   // Change length of theme field in {blocks} to be consistent with module, and | 
| webmaster@1 | 2337   // to avoid a MySQL error regarding a too-long index.  Also add new indices. | 
| webmaster@1 | 2338   db_change_field($ret, 'blocks', 'theme', 'theme', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''),array( | 
| webmaster@1 | 2339                   'unique keys' => array('tmd' => array('theme', 'module', 'delta'),), | 
| webmaster@1 | 2340                   'indexes' => array('list' => array('theme', 'status', 'region', 'weight', 'module'),),)); | 
| webmaster@1 | 2341   db_add_index($ret, 'blocks_roles', 'rid', array('rid')); | 
| webmaster@1 | 2342   // Improve filter module indices. | 
| webmaster@1 | 2343   db_drop_index($ret, 'filters', 'weight'); | 
| webmaster@1 | 2344   db_add_unique_key($ret, 'filters', 'fmd', array('format', 'module', 'delta')); | 
| webmaster@1 | 2345   db_add_index($ret, 'filters', 'list', array('format', 'weight', 'module', 'delta')); | 
| webmaster@1 | 2346   // Drop unneeded keys form the node table. | 
| webmaster@1 | 2347   db_drop_index($ret, 'node', 'status'); | 
| webmaster@1 | 2348   db_drop_unique_key($ret, 'node', 'nid_vid'); | 
| webmaster@1 | 2349   // Improve user module indices. | 
| webmaster@1 | 2350   db_add_index($ret, 'users', 'mail', array('mail')); | 
| webmaster@1 | 2351   db_add_index($ret, 'users_roles', 'rid', array('rid')); | 
| webmaster@1 | 2352 | 
| webmaster@1 | 2353   // Optional modules - need to check if the tables exist. | 
| webmaster@1 | 2354   // Alter aggregator module's tables primary keys to make them more useful. | 
| webmaster@1 | 2355   if (db_table_exists('aggregator_category_feed')) { | 
| webmaster@1 | 2356     db_drop_primary_key($ret, 'aggregator_category_feed'); | 
| webmaster@1 | 2357     db_add_primary_key($ret, 'aggregator_category_feed', array('cid', 'fid')); | 
| webmaster@1 | 2358     db_add_index($ret, 'aggregator_category_feed', 'fid', array('fid')); | 
| webmaster@1 | 2359   } | 
| webmaster@1 | 2360   if (db_table_exists('aggregator_category_item')) { | 
| webmaster@1 | 2361     db_drop_primary_key($ret, 'aggregator_category_item'); | 
| webmaster@1 | 2362     db_add_primary_key($ret, 'aggregator_category_item', array('cid', 'iid')); | 
| webmaster@1 | 2363     db_add_index($ret, 'aggregator_category_item', 'iid', array('iid')); | 
| webmaster@1 | 2364   } | 
| webmaster@1 | 2365   // Alter contact module's table to add an index. | 
| webmaster@1 | 2366   if (db_table_exists('contact')) { | 
| webmaster@1 | 2367     db_add_index($ret, 'contact', 'list', array('weight', 'category')); | 
| webmaster@1 | 2368   } | 
| webmaster@1 | 2369   // Alter locale table to add a primary key, drop an index. | 
| webmaster@1 | 2370   if (db_table_exists('locales_target')) { | 
| webmaster@1 | 2371     db_add_primary_key($ret, 'locales_target', array('language', 'lid', 'plural')); | 
| webmaster@1 | 2372   } | 
| webmaster@1 | 2373   // Alter a poll module table to add a primary key. | 
| webmaster@1 | 2374   if (db_table_exists('poll_votes')) { | 
| webmaster@1 | 2375     db_drop_index($ret, 'poll_votes', 'nid'); | 
| webmaster@1 | 2376     db_add_primary_key($ret, 'poll_votes', array('nid', 'uid', 'hostname')); | 
| webmaster@1 | 2377   } | 
| webmaster@1 | 2378   // Alter a profile module table to add a primary key. | 
| webmaster@1 | 2379   if (db_table_exists('profile_values')) { | 
| webmaster@1 | 2380     db_drop_index($ret, 'profile_values', 'uid'); | 
| webmaster@1 | 2381     db_drop_index($ret, 'profile_values', 'fid'); | 
| webmaster@1 | 2382     db_change_field($ret,'profile_values' ,'fid', 'fid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,), array('indexes' => array('fid' => array('fid'),))); | 
| webmaster@1 | 2383     db_change_field($ret,'profile_values' ,'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,)); | 
| webmaster@1 | 2384     db_add_primary_key($ret, 'profile_values', array('uid', 'fid')); | 
| webmaster@1 | 2385   } | 
| webmaster@1 | 2386   // Alter a statistics module table to add an index. | 
| webmaster@1 | 2387   if (db_table_exists('accesslog')) { | 
| webmaster@1 | 2388     db_add_index($ret, 'accesslog', 'uid', array('uid')); | 
| webmaster@1 | 2389   } | 
| webmaster@1 | 2390   // Alter taxonomy module's tables. | 
| webmaster@1 | 2391   if (db_table_exists('term_data')) { | 
| webmaster@1 | 2392     db_drop_index($ret, 'term_data', 'vid'); | 
| webmaster@1 | 2393     db_add_index($ret, 'term_data', 'vid_name', array('vid', 'name')); | 
| webmaster@1 | 2394     db_add_index($ret, 'term_data', 'taxonomy_tree', array('vid', 'weight', 'name')); | 
| webmaster@1 | 2395   } | 
| webmaster@1 | 2396   if (db_table_exists('term_node')) { | 
| webmaster@1 | 2397     db_drop_primary_key($ret, 'term_node'); | 
| webmaster@1 | 2398     db_drop_index($ret, 'term_node', 'tid'); | 
| webmaster@1 | 2399     db_add_primary_key($ret, 'term_node', array('tid', 'vid')); | 
| webmaster@1 | 2400   } | 
| webmaster@1 | 2401   if (db_table_exists('term_relation')) { | 
| webmaster@1 | 2402     db_drop_index($ret, 'term_relation', 'tid1'); | 
| webmaster@1 | 2403     db_add_unique_key($ret, 'term_relation', 'tid1_tid2', array('tid1', 'tid2')); | 
| webmaster@1 | 2404   } | 
| webmaster@1 | 2405   if (db_table_exists('term_synonym')) { | 
| webmaster@1 | 2406     db_drop_index($ret, 'term_synonym', 'name'); | 
| webmaster@1 | 2407     db_add_index($ret, 'term_synonym', 'name_tid', array('name', 'tid')); | 
| webmaster@1 | 2408   } | 
| webmaster@1 | 2409   if (db_table_exists('vocabulary')) { | 
| webmaster@1 | 2410     db_add_index($ret, 'vocabulary', 'list', array('weight', 'name')); | 
| webmaster@1 | 2411   } | 
| webmaster@1 | 2412   if (db_table_exists('vocabulary_node_types')) { | 
| webmaster@1 | 2413     db_drop_primary_key($ret, 'vocabulary_node_types'); | 
| webmaster@1 | 2414     db_add_primary_key($ret, 'vocabulary_node_types', array('type', 'vid')); | 
| webmaster@1 | 2415     db_add_index($ret, 'vocabulary_node_types', 'vid', array('vid')); | 
| webmaster@1 | 2416   } | 
| webmaster@1 | 2417   // If we updated in RC1 or before ensure we don't update twice. | 
| webmaster@1 | 2418   variable_set('system_update_6043_RC2', TRUE); | 
| webmaster@1 | 2419 | 
| webmaster@1 | 2420   return $ret; | 
| webmaster@1 | 2421 } | 
| webmaster@1 | 2422 | 
| webmaster@1 | 2423 /** | 
| webmaster@1 | 2424  * RC1 to RC2 index cleanup. | 
| webmaster@1 | 2425  */ | 
| webmaster@1 | 2426 function system_update_6044() { | 
| webmaster@1 | 2427   $ret = array(); | 
| webmaster@1 | 2428 | 
| webmaster@1 | 2429   // Delete invalid entries in {term_node} after system_update_6001. | 
| webmaster@1 | 2430   $ret[] = update_sql("DELETE FROM {term_node} WHERE vid = 0"); | 
| webmaster@1 | 2431 | 
| webmaster@1 | 2432   // Only execute the rest of this function if 6043 was run in RC1 or before. | 
| webmaster@1 | 2433   if (variable_get('system_update_6043_RC2', FALSE)) { | 
| webmaster@1 | 2434     variable_del('system_update_6043_RC2'); | 
| webmaster@1 | 2435     return $ret; | 
| webmaster@1 | 2436   } | 
| webmaster@1 | 2437 | 
| webmaster@1 | 2438   // User module indices. | 
| webmaster@1 | 2439   db_drop_unique_key($ret, 'users', 'mail'); | 
| webmaster@1 | 2440   db_add_index($ret, 'users', 'mail', array('mail')); | 
| webmaster@1 | 2441 | 
| webmaster@1 | 2442   // Optional modules - need to check if the tables exist. | 
| webmaster@1 | 2443   // Alter taxonomy module's tables. | 
| webmaster@1 | 2444   if (db_table_exists('term_data')) { | 
| webmaster@1 | 2445     db_drop_unique_key($ret, 'term_data', 'vid_name'); | 
| webmaster@1 | 2446     db_add_index($ret, 'term_data', 'vid_name', array('vid', 'name')); | 
| webmaster@1 | 2447   } | 
| webmaster@1 | 2448   if (db_table_exists('term_synonym')) { | 
| webmaster@1 | 2449     db_drop_unique_key($ret, 'term_synonym', 'name_tid', array('name', 'tid')); | 
| webmaster@1 | 2450     db_add_index($ret, 'term_synonym', 'name_tid', array('name', 'tid')); | 
| webmaster@1 | 2451   } | 
| webmaster@1 | 2452 | 
| webmaster@1 | 2453   return $ret; | 
| webmaster@1 | 2454 } | 
| webmaster@1 | 2455 | 
| webmaster@1 | 2456 /** | 
| webmaster@1 | 2457  * Update blog, book and locale module permissions. | 
| webmaster@1 | 2458  * | 
| webmaster@1 | 2459  * Blog module got "edit own blog" replaced with the more granular "create | 
| webmaster@1 | 2460  * blog entries", "edit own blog entries" and "delete own blog entries" | 
| webmaster@1 | 2461  * permissions. We grant create and edit to previously privileged users, but | 
| webmaster@1 | 2462  * delete is not granted to be in line with other permission changes in Drupal 6. | 
| webmaster@1 | 2463  * | 
| webmaster@1 | 2464  * Book module's "edit book pages" was upgraded to the bogus "edit book content" | 
| webmaster@1 | 2465  * in Drupal 6 RC1 instead of "edit any book content", which would be correct. | 
| webmaster@1 | 2466  * | 
| webmaster@1 | 2467  * Locale module introduced "administer languages" and "translate interface" | 
| webmaster@1 | 2468  * in place of "administer locales". | 
| webmaster@1 | 2469  * | 
| webmaster@1 | 2470  * Modeled after system_update_6039(). | 
| webmaster@1 | 2471  */ | 
| webmaster@1 | 2472 function system_update_6045() { | 
| webmaster@1 | 2473   $ret = array(); | 
| webmaster@1 | 2474   $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid"); | 
| webmaster@1 | 2475   while ($role = db_fetch_object($result)) { | 
| webmaster@1 | 2476     $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ blog(?=,|$)/', 'create blog entries, edit own blog entries', $role->perm); | 
| webmaster@1 | 2477     $renamed_permission = preg_replace('/(?<=^|,\ )edit\ book\ content(?=,|$)/', 'edit any book content', $renamed_permission); | 
| webmaster@1 | 2478     $renamed_permission = preg_replace('/(?<=^|,\ )administer\ locales(?=,|$)/', 'administer languages, translate interface', $renamed_permission); | 
| webmaster@1 | 2479     if ($renamed_permission != $role->perm) { | 
| webmaster@1 | 2480       $ret[] = update_sql("UPDATE {permission} SET perm = '$renamed_permission' WHERE rid = $role->rid"); | 
| webmaster@1 | 2481     } | 
| webmaster@1 | 2482   } | 
| webmaster@1 | 2483 | 
| webmaster@1 | 2484   // Notify user that delete permissions may have been changed. This was in | 
| webmaster@1 | 2485   // effect since system_update_6039(), but there was no user notice. | 
| webmaster@1 | 2486   drupal_set_message('Drupal now has separate edit and delete permissions. Previously, users who were able to edit content were automatically allowed to delete it. For added security, delete permissions for individual core content types have been <strong>removed</strong> from all roles on your site (only roles with the "administer nodes" permission can now delete these types of content). If you would like to reenable any individual delete permissions, you can do this at the <a href="'. url('admin/user/permissions', array('fragment' => 'module-node')) .'">permissions page</a>.'); | 
| webmaster@1 | 2487   return $ret; | 
| webmaster@1 | 2488 } | 
| webmaster@1 | 2489 | 
| webmaster@1 | 2490 /** | 
| webmaster@1 | 2491  * Ensure that the file_directory_path variable is set (using the old 5.x | 
| webmaster@1 | 2492  * default, if necessary), so that the changed 6.x default won't break | 
| webmaster@1 | 2493  * existing sites. | 
| webmaster@1 | 2494  */ | 
| webmaster@1 | 2495 function system_update_6046() { | 
| webmaster@1 | 2496   $ret = array(); | 
| webmaster@1 | 2497   if (!variable_get('file_directory_path', FALSE)) { | 
| webmaster@1 | 2498     variable_set('file_directory_path', 'files'); | 
| webmaster@1 | 2499     $ret[] = array('success' => TRUE, 'query' => "variable_set('file_directory_path')"); | 
| webmaster@1 | 2500   } | 
| webmaster@1 | 2501   return $ret; | 
| webmaster@1 | 2502 } | 
| webmaster@1 | 2503 | 
| webmaster@1 | 2504 /** | 
| webmaster@1 | 2505  * Fix cache mode for blocks inserted in system_install() in fresh installs of previous RC. | 
| webmaster@1 | 2506  */ | 
| webmaster@1 | 2507 function system_update_6047() { | 
| webmaster@1 | 2508   $ret = array(); | 
| webmaster@1 | 2509   $ret[] = update_sql("UPDATE {blocks} SET cache = -1 WHERE module = 'user' AND delta IN ('0', '1')"); | 
| webmaster@1 | 2510   $ret[] = update_sql("UPDATE {blocks} SET cache = -1 WHERE module = 'system' AND delta = '0'"); | 
| webmaster@1 | 2511   return $ret; | 
| webmaster@1 | 2512 } | 
| webmaster@1 | 2513 | 
| webmaster@1 | 2514 /** | 
| webmaster@1 | 2515  * @} End of "defgroup updates-5.x-to-6.x" | 
| webmaster@1 | 2516  * The next series of updates should start at 7000. | 
| webmaster@1 | 2517  */ |