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