annotate modules/system/system.install @ 11:589fb7c02327 6.5

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