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