Spike PHPCoverage Details: system.install

Line #FrequencySource Line
1 <?php
2 // $Id: system.install,v 1.244 2008/03/21 08:52:25 dries 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,
68   );
69 
70   if ($memory_limit && 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     $description .= ' '. $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron')));
174     $description .= '<br />'. $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron.php', array('absolute' => true, 'query' => 'cron_key='. variable_get('cron_key', 'drupal')))));
175 
176     $requirements['cron'] = array(
177       'title' => $t('Cron maintenance tasks'),
178       'severity' => $severity,
179       'value' => $summary,
180       'description' => $description
181     );
182   }
183 
184   // Test files directory
185   $directory = file_directory_path();
186   $requirements['file system'] = array(
187     'title' => $t('File system'),
188   );
189 
190   // For installer, create the directory if possible.
191   if ($phase == 'install' && !is_dir($directory) && @mkdir($directory)) {
192     @chmod($directory, 0775); // Necessary for non-webserver users.
193   }
194 
195   $is_writable = is_writable($directory);
196   $is_directory = is_dir($directory);
197   if (!$is_writable || !$is_directory) {
198     $description = '';
199     $requirements['file system']['value'] = $t('Not writable');
200     if (!$is_directory) {
201       $error = $t('The directory %directory does not exist.', array('%directory' => $directory));
202     }
203     else {
204       $error = $t('The directory %directory is not writable.', array('%directory' => $directory));
205     }
206     // The files directory requirement check is done only during install and runtime.
207     if ($phase == 'runtime') {
208       $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')));
209     }
210     elseif ($phase == 'install') {
211       // For the installer UI, we need different wording. 'value' will
212       // be treated as version, so provide none there.
213       $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'));
214       $requirements['file system']['value'] = '';
215     }
216     if (!empty($description)) {
217       $requirements['file system']['description'] = $description;
218       $requirements['file system']['severity'] = REQUIREMENT_ERROR;
219     }
220   }
221   else {
222     if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) {
223       $requirements['file system']['value'] = $t('Writable (<em>public</em> download method)');
224     }
225     else {
226       $requirements['file system']['value'] = $t('Writable (<em>private</em> download method)');
227     }
228   }
229 
230   // See if updates are available in update.php.
231   if ($phase == 'runtime') {
232     $requirements['update'] = array(
233       'title' => $t('Database updates'),
234       'severity' => REQUIREMENT_OK,
235       'value' => $t('Up to date'),
236     );
237 
238     // Check installed modules.
239     foreach (module_list() as $module) {
240       $updates = drupal_get_schema_versions($module);
241       if ($updates !== FALSE) {
242         $default = drupal_get_installed_schema_version($module);
243         if (max($updates) > $default) {
244           $requirements['update']['severity'] = REQUIREMENT_ERROR;
245           $requirements['update']['value'] = $t('Out of date');
246           $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'));
247           break;
248         }
249       }
250     }
251   }
252 
253   // Verify the update.php access setting
254   if ($phase == 'runtime') {
255     if (!empty($GLOBALS['update_free_access'])) {
256       $requirements['update access'] = array(
257         'value' => $t('Not protected'),
258         'severity' => REQUIREMENT_ERROR,
259         '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.'),
260       );
261     }
262     else {
263       $requirements['update access'] = array(
264         'value' => $t('Protected'),
265       );
266     }
267     $requirements['update access']['title'] = $t('Access to update.php');
268   }
269 
270   // Test Unicode library
271   include_once './includes/unicode.inc';
272   $requirements = array_merge($requirements, unicode_requirements());
273 
274   // Check for update status module.
275   if ($phase == 'runtime') {
276     if (!module_exists('update')) {
277       $requirements['update status'] = array(
278         'value' => $t('Not enabled'),
279         'severity' => REQUIREMENT_ERROR,
280         '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'))),
281       );
282     }
283     else {
284       $requirements['update status'] = array(
285         'value' => $t('Enabled'),
286       );
287       if (variable_get('drupal_http_request_fails', FALSE)) {
288         $requirements['http requests'] = array(
289           'title' => $t('HTTP request status'),
290           'value' => $t('Fails'),
291           'severity' => REQUIREMENT_ERROR,
292           '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.'),
293         );
294       }
295     }
296     $requirements['update status']['title'] = $t('Update notifications');
297   }
298 
299   return $requirements;
300 }
301 
302 /**
303  * Implementation of hook_install().
304  */
305 function system_install() {
3061  if ($GLOBALS['db_type'] == 'pgsql') {
307     // Create unsigned types.
308     db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)");
309     db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)");
310     db_query("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)");
311 
312     // Create functions.
313     db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS
314       \'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\'
315       LANGUAGE \'sql\''
316     );
317     db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS
318       \'SELECT greatest($1, greatest($2, $3));\'
319       LANGUAGE \'sql\''
320     );
321     if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'"))) {
322       db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
323         \'SELECT random();\'
324         LANGUAGE \'sql\''
325       );
326     }
327 
328     if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'"))) {
329       db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS
330         \'SELECT $1 || $2;\'
331         LANGUAGE \'sql\''
332       );
333     }
334     db_query('CREATE OR REPLACE FUNCTION "if"(boolean, text, text) RETURNS text AS
335       \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
336       LANGUAGE \'sql\''
337     );
338     db_query('CREATE OR REPLACE FUNCTION "if"(boolean, integer, integer) RETURNS integer AS
339       \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
340       LANGUAGE \'sql\''
341     );
342   }
343 
344   // Create tables.
345   $modules = array('system', 'filter', 'block', 'user', 'node', 'comment', 'taxonomy');
3461  foreach ($modules as $module) {
3471    drupal_install_schema($module);
348   }
349 
350   // Load system theme data appropriately.
3511  system_theme_data();
352 
353   // Inserting uid 0 here confuses MySQL -- the next user might be created as
354   // uid 2 which is not what we want. So we insert the first user here, the
355   // anonymous user. uid is 1 here for now, but very soon it will be changed
356   // to 0.
3571  db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', '');
358   // We need some placeholders here as name and mail are uniques and data is
359   // presumed to be a serialized array. Install will change uid 1 immediately
360   // anyways. So we insert the superuser here, the uid is 2 here for now, but
361   // very soon it will be changed to 1.
3621  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()));
363   // This sets the above two users uid 0 (anonymous). We avoid an explicit 0
364   // otherwise MySQL might insert the next auto_increment value.
3651  db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", '');
366   // This sets uid 1 (superuser). We skip uid 2 but that's not a big problem.
3671  db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1');
368 
3691  db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user');
3701  db_query("INSERT INTO {role} (name) VALUES ('%s')", 'authenticated user');
371 
3721  db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (%d, '%s', %d)", 1, 'access content', 0);
3731  db_query("INSERT INTO {permission} (rid, perm, tid) VALUES (%d, '%s', %d)", 2, 'access comments, access content, post comments, post comments without approval', 0);
374 
3751  db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'theme_default', 's:7:"garland";');
3761  db_query("UPDATE {system} SET status = %d WHERE type = '%s' AND name = '%s'", 1, 'theme', 'garland');
3771  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);
3781  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);
3791  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);
380 
3811  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);
382 
383   // Add input formats.
3841  db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('%s', '%s', %d)", 'Filtered HTML', ',1,2,', 1);
3851  db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('%s', '%s', %d)", 'Full HTML', '', 1);
386 
387   // Enable filters for each input format.
388 
389   // Filtered HTML:
390   // URL filter.
3911  db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 2, 0);
392   // HTML filter.
3931  db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 0, 1);
394   // Line break filter.
3951  db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 1, 2);
396   // HTML corrector filter.
3971  db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 3, 10);
398 
399   // Full HTML:
400   // URL filter.
4011  db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 2, 0);
402   // Line break filter.
4031  db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 1, 1);
404   // HTML corrector filter.
4051  db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 3, 10);
406 
4071  db_query("INSERT INTO {variable} (name, value) VALUES ('%s','%s')", 'filter_html_1', 'i:1;');
408 
4091  db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'node_options_forum', 'a:1:{i:0;s:6:"status";}');
410 
4111  $cron_key = serialize(md5(mt_rand()));
412 
4131  db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'cron_key', $cron_key);
414 }
415 
416 /**
417  * Implementation of hook_schema().
418  */
419 function system_schema() {
420   // NOTE: {variable} needs to be created before all other tables, as
421   // some database drivers, e.g. Oracle and DB2, will require variable_get()
422   // and variable_set() for overcoming some database specific limitations.
423   $schema['variable'] = array(
4241    'description' => t('Named variable/value pairs created by Drupal core or any other module or theme. All variables are cached in memory at the start of every Drupal request so developers should not be careless about what is stored here.'),
425     'fields' => array(
426       'name' => array(
427         'description' => t('The name of the variable.'),
428         'type' => 'varchar',
429         'length' => 128,
430         'not null' => TRUE,
431         'default' => '',
432       ),
433       'value' => array(
434         'description' => t('The value of the variable.'),
435         'type' => 'text',
436         'not null' => TRUE,
437         'size' => 'big',
438       ),
439     ),
440     'primary key' => array('name'),
441   );
442 
443   $schema['actions'] = array(
4441    'description' => t('Stores action information.'),
445     'fields' => array(
446       'aid' => array(
447         'description' => t('Primary Key: Unique actions ID.'),
448         'type' => 'varchar',
449         'length' => 255,
450         'not null' => TRUE,
451         'default' => '0',
452       ),
453       'type' => array(
454         'description' => t('The object that that action acts on (node, user, comment, system or custom types.)'),
455         'type' => 'varchar',
456         'length' => 32,
457         'not null' => TRUE,
458         'default' => '',
459       ),
460       'callback' => array(
461         'description' => t('The callback function that executes when the action runs.'),
462         'type' => 'varchar',
463         'length' => 255,
464         'not null' => TRUE,
465         'default' => '',
466       ),
467       'parameters' => array(
468         'description' => t('Parameters to be passed to the callback function.'),
469         'type' => 'text',
470         'not null' => TRUE,
471         'size' => 'big',
472       ),
473       'description' => array(
474         'description' => t('Description of the action.'),
475         'type' => 'varchar',
476         'length' => 255,
477         'not null' => TRUE,
478         'default' => '0',
479       ),
480     ),
481     'primary key' => array('aid'),
482   );
483 
484   $schema['actions_aid'] = array(
4851    'description' => t('Stores action IDs for non-default actions.'),
486     'fields' => array(
487       'aid' => array(
488         'description' => t('Primary Key: Unique actions ID.'),
489         'type' => 'serial',
490         'unsigned' => TRUE,
491         'not null' => TRUE,
492       ),
493     ),
494     'primary key' => array('aid'),
495   );
496 
497   $schema['batch'] = array(
4981    'description' => t('Stores details about batches (processes that run in multiple HTTP requests).'),
499     'fields' => array(
500       'bid' => array(
501         'description' => t('Primary Key: Unique batch ID.'),
502         'type' => 'serial',
503         'unsigned' => TRUE,
504         'not null' => TRUE,
505       ),
506       'token' => array(
507         'description' => t("A string token generated against the current user's session id and the batch id, used to ensure that only the user who submitted the batch can effectively access it."),
508         'type' => 'varchar',
509         'length' => 64,
510         'not null' => TRUE,
511       ),
512       'timestamp' => array(
513         'description' => t('A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.'),
514         'type' => 'int',
515         'not null' => TRUE,
516       ),
517       'batch' => array(
518         'description' => t('A serialized array containing the processing data for the batch.'),
519         'type' => 'text',
520         'not null' => FALSE,
521         'size' => 'big',
522       ),
523     ),
524     'primary key' => array('bid'),
525     'indexes' => array(
526       'token' => array('token'),
527     ),
528   );
529 
530   $schema['cache'] = array(
5311    'description' => t('Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.'),
532     'fields' => array(
533       'cid' => array(
534         'description' => t('Primary Key: Unique cache ID.'),
535         'type' => 'varchar',
536         'length' => 255,
537         'not null' => TRUE,
538         'default' => '',
539       ),
540       'data' => array(
541         'description' => t('A collection of data to cache.'),
542         'type' => 'blob',
543         'not null' => FALSE,
544         'size' => 'big',
545       ),
546       'expire' => array(
547         'description' => t('A Unix timestamp indicating when the cache entry should expire, or 0 for never.'),
548         'type' => 'int',
549         'not null' => TRUE,
550         'default' => 0,
551       ),
552       'created' => array(
553         'description' => t('A Unix timestamp indicating when the cache entry was created.'),
554         'type' => 'int',
555         'not null' => TRUE,
556         'default' => 0,
557       ),
558       'headers' => array(
559         'description' => t('Any custom HTTP headers to be added to cached data.'),
560         'type' => 'text',
561         'not null' => FALSE,
562       ),
563       'serialized' => array(
564         'description' => t('A flag to indicate whether content is serialized (1) or not (0).'),
565         'type' => 'int',
566         'size' => 'small',
567         'not null' => TRUE,
568         'default' => 0,
569       ),
570     ),
571     'indexes' => array(
572       'expire' => array('expire'),
573     ),
574     'primary key' => array('cid'),
575   );
576 
5771  $schema['cache_form'] = $schema['cache'];
5781  $schema['cache_form']['description'] = t('Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.');
5791  $schema['cache_page'] = $schema['cache'];
5801  $schema['cache_page']['description'] = t('Cache table used to store compressed pages for anonymous users, if page caching is enabled.');
5811  $schema['cache_menu'] = $schema['cache'];
5821  $schema['cache_menu']['description'] = t('Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.');
583 
584   $schema['files'] = array(
5851    'description' => t('Stores information for uploaded files.'),
586     'fields' => array(
587       'fid' => array(
588         'description' => t('Primary Key: Unique files ID.'),
589         'type' => 'serial',
590         'unsigned' => TRUE,
591         'not null' => TRUE,
592       ),
593       'uid' => array(
594         'description' => t('The {users}.uid of the user who is associated with the file.'),
595         'type' => 'int',
596         'unsigned' => TRUE,
597         'not null' => TRUE,
598         'default' => 0,
599       ),
600       'filename' => array(
601         'description' => t('Name of the file.'),
602         'type' => 'varchar',
603         'length' => 255,
604         'not null' => TRUE,
605         'default' => '',
606       ),
607       'filepath' => array(
608         'description' => t('Path of the file relative to Drupal root.'),
609         'type' => 'varchar',
610         'length' => 255,
611         'not null' => TRUE,
612         'default' => '',
613       ),
614       'filemime' => array(
615         'description' => t('The file MIME type.'),
616         'type' => 'varchar',
617         'length' => 255,
618         'not null' => TRUE,
619         'default' => '',
620       ),
621       'filesize' => array(
622         'description' => t('The size of the file in bytes.'),
623         'type' => 'int',
624         'unsigned' => TRUE,
625         'not null' => TRUE,
626         'default' => 0,
627       ),
628       'status' => array(
629         'description' => t('A flag indicating whether file is temporary (1) or permanent (0).'),
630         'type' => 'int',
631         'not null' => TRUE,
632         'default' => 0,
633       ),
634       'timestamp' => array(
635         'description' => t('UNIX timestamp for when the file was added.'),
636         'type' => 'int',
637         'unsigned' => TRUE,
638         'not null' => TRUE,
639         'default' => 0,
640       ),
641     ),
642     'indexes' => array(
643       'uid' => array('uid'),
644       'status' => array('status'),
645       'timestamp' => array('timestamp'),
646     ),
647     'primary key' => array('fid'),
648   );
649 
650   $schema['flood'] = array(
6511    'description' => t('Flood controls the threshold of events, such as the number of contact attempts.'),
652     'fields' => array(
653       'fid' => array(
654         'description' => t('Unique flood event ID.'),
655         'type' => 'serial',
656         'not null' => TRUE,
657       ),
658       'event' => array(
659         'description' => t('Name of event (e.g. contact).'),
660         'type' => 'varchar',
661         'length' => 64,
662         'not null' => TRUE,
663         'default' => '',
664       ),
665       'hostname' => array(
666         'description' => t('Hostname of the visitor.'),
667         'type' => 'varchar',
668         'length' => 128,
669         'not null' => TRUE,
670         'default' => '',
671       ),
672       'timestamp' => array(
673         'description' => t('Timestamp of the event.'),
674         'type' => 'int',
675         'not null' => TRUE,
676         'default' => 0,
677       ),
678     ),
679     'primary key' => array('fid'),
680     'indexes' => array(
681       'allow' => array('event', 'hostname', 'timestamp'),
682     ),
683   );
684 
685   $schema['history'] = array(
6861    'description' => t('A record of which {users} have read which {node}s.'),
687     'fields' => array(
688       'uid' => array(
689         'description' => t('The {users}.uid that read the {node} nid.'),
690         'type' => 'int',
691         'not null' => TRUE,
692         'default' => 0,
693       ),
694       'nid' => array(
695         'description' => t('The {node}.nid that was read.'),
696         'type' => 'int',
697         'not null' => TRUE,
698         'default' => 0,
699       ),
700       'timestamp' => array(
701         'description' => t('The Unix timestamp at which the read occurred.'),
702         'type' => 'int',
703         'not null' => TRUE,
704         'default' => 0,
705       ),
706     ),
707     'primary key' => array('uid', 'nid'),
708     'indexes' => array(
709       'nid' => array('nid'),
710     ),
711   );
712   $schema['menu_router'] = array(
7131    'description' => t('Maps paths to various callbacks (access, page and title)'),
714     'fields' => array(
715       'path' => array(
716         'description' => t('Primary Key: the Drupal path this entry describes'),
717         'type' => 'varchar',
718         'length' => 255,
719         'not null' => TRUE,
720         'default' => '',
721       ),
722       'load_functions' => array(
723         'description' => t('A serialized array of function names (like node_load) to be called to load an object corresponding to a part of the current path.'),
724         'type' => 'varchar',
725         'length' => 255,
726         'not null' => TRUE,
727         'default' => '',
728       ),
729       'to_arg_functions' => array(
730         'description' => t('A serialized array of function names (like user_current_to_arg) to be called to replace a part of the router path with another string.'),
731         'type' => 'varchar',
732         'length' => 255,
733         'not null' => TRUE,
734         'default' => '',
735       ),
736       'access_callback' => array(
737         'description' => t('The callback which determines the access to this router path. Defaults to user_access.'),
738         'type' => 'varchar',
739         'length' => 255,
740         'not null' => TRUE,
741         'default' => '',
742       ),
743       'access_arguments' => array(
744         'description' => t('A serialized array of arguments for the access callback.'),
745         'type' => 'text',
746         'not null' => FALSE,
747       ),
748       'page_callback' => array(
749         'description' => t('The name of the function that renders the page.'),
750         'type' => 'varchar',
751         'length' => 255,
752         'not null' => TRUE,
753         'default' => '',
754       ),
755       'page_arguments' => array(
756         'description' => t('A serialized array of arguments for the page callback.'),
757         'type' => 'text',
758         'not null' => FALSE,
759       ),
760       'fit' => array(
761         'description' => t('A numeric representation of how specific the path is.'),
762         'type' => 'int',
763         'not null' => TRUE,
764         'default' => 0,
765       ),
766       'number_parts' => array(
767         'description' => t('Number of parts in this router path.'),
768         'type' => 'int',
769         'not null' => TRUE,
770         'default' => 0,
771         'size' => 'small',
772       ),
773       'tab_parent' => array(
774         'description' => t('Only for local tasks (tabs) - the router path of the parent page (which may also be a local task).'),
775         'type' => 'varchar',
776         'length' => 255,
777         'not null' => TRUE,
778         'default' => '',
779       ),
780       'tab_root' => array(
781         'description' => t('Router path of the closest non-tab parent page. For pages that are not local tasks, this will be the same as the path.'),
782         'type' => 'varchar',
783         'length' => 255,
784         'not null' => TRUE,
785         'default' => '',
786       ),
787       'title' => array(
788         'description' => t('The title for the current page, or the title for the tab if this is a local task.'),
789         'type' => 'varchar',
790         'length' => 255,
791         'not null' => TRUE,
792         'default' => '',
793       ),
794       'title_callback' => array(
795         'description' => t('A function which will alter the title. Defaults to t()'),
796         'type' => 'varchar',
797         'length' => 255,
798         'not null' => TRUE,
799         'default' => '',
800       ),
801       'title_arguments' => array(
802         'description' => t('A serialized array of arguments for the title callback. If empty, the title will be used as the sole argument for the title callback.'),
803         'type' => 'varchar',
804         'length' => 255,
805         'not null' => TRUE,
806         'default' => '',
807       ),
808       'type' => array(
809         'description' => t('Numeric representation of the type of the menu item, like MENU_LOCAL_TASK.'),
810         'type' => 'int',
811         'not null' => TRUE,
812         'default' => 0,
813       ),
814       'block_callback' => array(
815         'description' => t('Name of a function used to render the block on the system administration page for this item.'),
816         'type' => 'varchar',
817         'length' => 255,
818         'not null' => TRUE,
819         'default' => '',
820       ),
821       'description' => array(
822         'description' => t('A description of this item.'),
823         'type' => 'text',
824         'not null' => TRUE,
825       ),
826       'position' => array(
827         'description' => t('The position of the block (left or right) on the system administration page for this item.'),
828         'type' => 'varchar',
829         'length' => 255,
830         'not null' => TRUE,
831         'default' => '',
832       ),
833       'weight' => array(
834         'description' => t('Weight of the element. Lighter weights are higher up, heavier weights go down.'),
835         'type' => 'int',
836         'not null' => TRUE,
837         'default' => 0,
838       ),
839       'file' => array(
840         'description' => t('The file to include for this element, usually the page callback function lives in this file.'),
841         'type' => 'text',
842         'size' => 'medium',
843       ),
844     ),
845     'indexes' => array(
846       'fit' => array('fit'),
847       'tab_parent' => array('tab_parent'),
848     ),
849     'primary key' => array('path'),
850   );
851 
852   $schema['menu_links'] = array(
8531    'description' => t('Contains the individual links within a menu.'),
854     'fields' => array(
855      'menu_name' => array(
856         'description' => t("The menu name. All links with the same menu name (such as 'navigation') are part of the same menu."),
857         'type' => 'varchar',
858         'length' => 32,
859         'not null' => TRUE,
860         'default' => '',
861       ),
862       'mlid' => array(
863         'description' => t('The menu link ID (mlid) is the integer primary key.'),
864         'type' => 'serial',
865         'unsigned' => TRUE,
866         'not null' => TRUE,
867       ),
868       'plid' => array(
869         'description' => t('The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.'),
870         'type' => 'int',
871         'unsigned' => TRUE,
872         'not null' => TRUE,
873         'default' => 0,
874       ),
875       'link_path' => array(
876         'description' => t('The Drupal path or external path this link points to.'),
877         'type' => 'varchar',
878         'length' => 255,
879         'not null' => TRUE,
880         'default' => '',
881       ),
882       'router_path' => array(
883         'description' => t('For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.'),
884         'type' => 'varchar',
885         'length' => 255,
886         'not null' => TRUE,
887         'default' => '',
888       ),
889       'link_title' => array(
890       'description' => t('The text displayed for the link, which may be modified by a title callback stored in {menu_router}.'),
891         'type' => 'varchar',
892         'length' => 255,
893         'not null' => TRUE,
894         'default' => '',
895       ),
896       'options' => array(
897         'description' => t('A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.'),
898         'type' => 'text',
899         'not null' => FALSE,
900       ),
901       'module' => array(
902         'description' => t('The name of the module that generated this link.'),
903         'type' => 'varchar',
904         'length' => 255,
905         'not null' => TRUE,
906         'default' => 'system',
907       ),
908       'hidden' => array(
909         'description' => t('A flag for whether the link should be rendered in menus. (1 = a disabled menu item that may be shown on admin screens, -1 = a menu callback, 0 = a normal, visible link)'),
910         'type' => 'int',
911         'not null' => TRUE,
912         'default' => 0,
913         'size' => 'small',
914       ),
915       'external' => array(
916         'description' => t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).'),
917         'type' => 'int',
918         'not null' => TRUE,
919         'default' => 0,
920         'size' => 'small',
921       ),
922       'has_children' => array(
923         'description' => t('Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).'),
924         'type' => 'int',
925         'not null' => TRUE,
926         'default' => 0,
927         'size' => 'small',
928       ),
929       'expanded' => array(
930         'description' => t('Flag for whether this link should be rendered as expanded in menus - expanded links always have their child links displayed, instead of only when the link is in the active trail (1 = expanded, 0 = not expanded)'),
931         'type' => 'int',
932         'not null' => TRUE,
933         'default' => 0,
934         'size' => 'small',
935       ),
936       'weight' => array(
937         'description' => t('Link weight among links in the same menu at the same depth.'),
938         'type' => 'int',
939         'not null' => TRUE,
940         'default' => 0,
941       ),
942       'depth' => array(
943         'description' => t('The depth relative to the top level. A link with plid == 0 will have depth == 1.'),
944         'type' => 'int',
945         'not null' => TRUE,
946         'default' => 0,
947         'size' => 'small',
948       ),
949       'customized' => array(
950         'description' => t('A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).'),
951         'type' => 'int',
952         'not null' => TRUE,
953         'default' => 0,
954         'size' => 'small',
955       ),
956       'p1' => array(
957         'description' => t('The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the plid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.'),
958         'type' => 'int',
959         'unsigned' => TRUE,
960         'not null' => TRUE,
961         'default' => 0,
962       ),
963       'p2' => array(
964         'description' => t('The second mlid in the materialized path. See p1.'),
965         'type' => 'int',
966         'unsigned' => TRUE,
967         'not null' => TRUE,
968         'default' => 0,
969       ),
970       'p3' => array(
971         'description' => t('The third mlid in the materialized path. See p1.'),
972         'type' => 'int',
973         'unsigned' => TRUE,
974         'not null' => TRUE,
975         'default' => 0,
976       ),
977       'p4' => array(
978         'description' => t('The fourth mlid in the materialized path. See p1.'),
979         'type' => 'int',
980         'unsigned' => TRUE,
981         'not null' => TRUE,
982         'default' => 0,
983       ),
984       'p5' => array(
985         'description' => t('The fifth mlid in the materialized path. See p1.'),
986         'type' => 'int',
987         'unsigned' => TRUE,
988         'not null' => TRUE,
989         'default' => 0,
990       ),
991       'p6' => array(
992         'description' => t('The sixth mlid in the materialized path. See p1.'),
993         'type' => 'int',
994         'unsigned' => TRUE,
995         'not null' => TRUE,
996         'default' => 0,
997       ),
998       'p7' => array(
999         'description' => t('The seventh mlid in the materialized path. See p1.'),
1000         'type' => 'int',
1001         'unsigned' => TRUE,
1002         'not null' => TRUE,
1003         'default' => 0,
1004       ),
1005       'p8' => array(
1006         'description' => t('The eighth mlid in the materialized path. See p1.'),
1007         'type' => 'int',
1008         'unsigned' => TRUE,
1009         'not null' => TRUE,
1010         'default' => 0,
1011       ),
1012       'p9' => array(
1013         'description' => t('The ninth mlid in the materialized path. See p1.'),
1014         'type' => 'int',
1015         'unsigned' => TRUE,
1016         'not null' => TRUE,
1017         'default' => 0,
1018       ),
1019       'updated' => array(
1020         'description' => t('Flag that indicates that this link was generated during the update from Drupal 5.'),
1021         'type' => 'int',
1022         'not null' => TRUE,
1023         'default' => 0,
1024         'size' => 'small',
1025       ),
1026     ),
1027     'indexes' => array(
1028       'path_menu' => array(array('link_path', 128), 'menu_name'),
1029       'menu_plid_expand_child' => array('menu_name', 'plid', 'expanded', 'has_children'),
1030       'menu_parents' => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'),
1031       'router_path' => array(array('router_path', 128)),
1032     ),
1033     'primary key' => array('mlid'),
1034   );
1035 
1036   $schema['sessions'] = array(
10371    'description' => t("Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated."),
1038     'fields' => array(
1039       'uid' => array(
1040         'description' => t('The {users}.uid corresponding to a session, or 0 for anonymous user.'),
1041         'type' => 'int',
1042         'unsigned' => TRUE,
1043         'not null' => TRUE,
1044       ),
1045       'sid' => array(
1046         'description' => t("Primary key: A session ID. The value is generated by PHP's Session API."),
1047         'type' => 'varchar',
1048         'length' => 64,
1049         'not null' => TRUE,
1050         'default' => '',
1051       ),
1052       'hostname' => array(
1053         'description' => t('The IP address that last used this session ID (sid).'),
1054         'type' => 'varchar',
1055         'length' => 128,
1056         'not null' => TRUE,
1057         'default' => '',
1058       ),
1059       'timestamp' => array(
1060         'description' => t('The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.'),
1061         'type' => 'int',
1062         'not null' => TRUE,
1063         'default' => 0,
1064       ),
1065       'cache' => array(
1066         'description' => t("The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get()."),
1067         'type' => 'int',
1068         'not null' => TRUE,
1069         'default' => 0,
1070       ),
1071       'session' => array(
1072         'description' => t('The serialized contents of $_SESSION, an array of name/value pairs that persists across page requests by this session ID. Drupal loads $_SESSION from here at the start of each request and saves it at the end.'),
1073         'type' => 'text',
1074         'not null' => FALSE,
1075         'size' => 'big',
1076       ),
1077     ),
1078     'primary key' => array('sid'),
1079     'indexes' => array(
1080       'timestamp' => array('timestamp'),
1081       'uid' => array('uid'),
1082     ),
1083   );
1084 
1085   $schema['system'] = array(
10861    'description' => t("A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system."),
1087     'fields' => array(
1088       'filename' => array(
1089         'description' => t('The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.'),
1090         'type' => 'varchar',
1091         'length' => 255,
1092         'not null' => TRUE,
1093         'default' => '',
1094       ),
1095       'name' => array(
1096         'description' => t('The name of the item; e.g. node.'),
1097         'type' => 'varchar',
1098         'length' => 255,
1099         'not null' => TRUE,
1100         'default' => '',
1101       ),
1102       'type' => array(
1103         'description' => t('The type of the item, either module, theme, or theme_engine.'),
1104         'type' => 'varchar',
1105         'length' => 255,
1106         'not null' => TRUE,
1107         'default' => '',
1108       ),
1109       'owner' => array(
1110         'description' => t("A theme's 'parent'. Can be either a theme or an engine."),
1111         'type' => 'varchar',
1112         'length' => 255,
1113         'not null' => TRUE,
1114         'default' => '',
1115       ),
1116       'status' => array(
1117         'description' => t('Boolean indicating whether or not this item is enabled.'),
1118         'type' => 'int',
1119         'not null' => TRUE,
1120         'default' => 0,
1121       ),
1122       'throttle' => array(
1123         'description' => t('Boolean indicating whether this item is disabled when the throttle.module disables throttleable items.'),
1124         'type' => 'int',
1125         'not null' => TRUE,
1126         'default' => 0,
1127         'size' => 'tiny',
1128       ),
1129       'bootstrap' => array(
1130         'description' => t("Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted)."),
1131         'type' => 'int',
1132         'not null' => TRUE,
1133         'default' => 0,
1134       ),
1135       'schema_version' => array(
1136         'description' => t("The module's database schema version number. -1 if the module is not installed (its tables do not exist); 0 or the largest N of the module's hook_update_N() function that has either been run or existed when the module was first installed."),
1137         'type' => 'int',
1138         'not null' => TRUE,
1139         'default' => -1,
1140         'size' => 'small',
1141       ),
1142       'weight' => array(
1143         'description' => t("The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name."),
1144         'type' => 'int',
1145         'not null' => TRUE,
1146         'default' => 0,
1147       ),
1148       'info' => array(
1149         'description' => t("A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, dependents, and php."),
1150         'type' => 'text',
1151         'not null' => FALSE,
1152       ),
1153     ),
1154     'primary key' => array('filename'),
1155     'indexes' => array(
1156       'modules' => array(array('type', 12), 'status', 'weight', 'filename'),
1157       'bootstrap' => array(array('type', 12), 'status', 'bootstrap', 'weight', 'filename'),
1158     ),
1159   );
1160 
1161   $schema['url_alias'] = array(
11621    'description' => t('A list of URL aliases for Drupal paths; a user may visit either the source or destination path.'),
1163     'fields' => array(
1164       'pid' => array(
1165         'description' => t('A unique path alias identifier.'),
1166         'type' => 'serial',
1167         'unsigned' => TRUE,
1168         'not null' => TRUE,
1169       ),
1170       'src' => array(
1171         'description' => t('The Drupal path this alias is for; e.g. node/12.'),
1172         'type' => 'varchar',
1173         'length' => 128,
1174         'not null' => TRUE,
1175         'default' => '',
1176       ),
1177       'dst' => array(
1178         'description' => t('The alias for this path; e.g. title-of-the-story.'),
1179         'type' => 'varchar',
1180         'length' => 128,
1181         'not null' => TRUE,
1182         'default' => '',
1183       ),
1184       'language' => array(
1185         'description' => t('The language this alias is for; if blank, the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.'),
1186         'type' => 'varchar',
1187         'length' => 12,
1188         'not null' => TRUE,
1189         'default' => '',
1190       ),
1191     ),
1192     'unique keys' => array(
1193       'dst_language' => array('dst', 'language'),
1194     ),
1195     'primary key' => array('pid'),
1196     'indexes' => array(
1197       'src' => array('src'),
1198     ),
1199   );
1200 
12011  return $schema;
1202 }
1203 
1204 // Updates for core.
1205 
1206 function system_update_last_removed() {
1207   return 1021;
1208 }
1209 
1210 /**
1211  * @defgroup updates-5.x-extra Extra system updates for 5.x
1212  * @{
1213  */
1214 
1215 /**
1216  * Add index on users created column.
1217  */
1218 function system_update_1022() {
1219   $ret = array();
1220   db_add_index($ret, 'users', 'created', array('created'));
1221   // Also appears as system_update_6004(). Ensure we don't update twice.
1222   variable_set('system_update_1022', TRUE);
1223   return $ret;
1224 }
1225 
1226 /**
1227  * @} End of "defgroup updates-5.x-extra"
1228  */
1229 
1230 /**
1231  * @defgroup updates-5.x-to-6.x System updates from 5.x to 6.x
1232  * @{
1233  */
1234 
1235 /**
1236  * Remove auto_increment from {boxes} to allow adding custom blocks with
1237  * visibility settings.
1238  */
1239 function system_update_6000() {
1240   $ret = array();
1241   switch ($GLOBALS['db_type']) {
1242     case 'mysql':
1243     case 'mysqli':
1244       $max = (int)db_result(db_query('SELECT MAX(bid) FROM {boxes}'));
1245       $ret[] = update_sql('ALTER TABLE {boxes} CHANGE COLUMN bid bid int NOT NULL');
1246       $ret[] = update_sql("REPLACE INTO {sequences} VALUES ('{boxes}_bid', $max)");
1247       break;
1248   }
1249   return $ret;
1250 }
1251 
1252 /**
1253  * Add version id column to {term_node} to allow taxonomy module to use revisions.
1254  */
1255 function system_update_6001() {
1256   $ret = array();
1257 
1258   // Add vid to term-node relation.  The schema says it is unsigned.
1259   db_add_field($ret, 'term_node', 'vid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
1260   db_drop_primary_key($ret, 'term_node');
1261   db_add_primary_key($ret, 'term_node', array('vid', 'tid', 'nid'));
1262   db_add_index($ret, 'term_node', 'vid', array('vid'));
1263 
1264   db_query('UPDATE {term_node} t SET vid = (SELECT vid FROM {node} n WHERE t.nid = n.nid)');
1265   return $ret;
1266 }
1267 
1268 /**
1269  * Increase the maximum length of variable names from 48 to 128.
1270  */
1271 function system_update_6002() {
1272   $ret = array();
1273   db_drop_primary_key($ret, 'variable');
1274   db_change_field($ret, 'variable', 'name', 'name', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
1275   db_add_primary_key($ret, 'variable', array('name'));
1276   return $ret;
1277 }
1278 
1279 /**
1280  * Add index on comments status column.
1281  */
1282 function system_update_6003() {
1283   $ret = array();
1284   db_add_index($ret, 'comments', 'status', array('status'));
1285   return $ret;
1286 }
1287 
1288 /**
1289  * This update used to add an index on users created column (#127941).
1290  * However, system_update_1022() does the same thing.  This update
1291  * tried to detect if 1022 had already run but failed to do so,
1292  * resulting in an "index already exists" error.
1293  *
1294  * Adding the index here is never necessary.  Sites installed before
1295  * 1022 will run 1022, getting the update.  Sites installed on/after 1022
1296  * got the index when the table was first created.  Therefore, this
1297  * function is now a no-op.
1298  */
1299 function system_update_6004() {
1300   return array();
1301 }
1302 
1303 /**
1304  * Add language to url_alias table and modify indexes.
1305  */
1306 function system_update_6005() {
1307   $ret = array();
1308   switch ($GLOBALS['db_type']) {
1309     case 'pgsql':
1310       db_add_column($ret, 'url_alias', 'language', 'varchar(12)', array('default' => "''", 'not null' => TRUE));
1311 
1312       // As of system.install:1.85 (before the new language
1313       // subsystem), new installs got a unique key named
1314       // url_alias_dst_key on url_alias.dst.  Unfortunately,
1315       // system_update_162 created a unique key inconsistently named
1316       // url_alias_dst_idx on url_alias.dst (keys should have the _key
1317       // suffix, indexes the _idx suffix).  Therefore, sites installed
1318       // before system_update_162 have a unique key with a different
1319       // name than sites installed after system_update_162().  Now, we
1320       // want to drop the unique key on dst which may have either one
1321       // of two names and create a new unique key on (dst, language).
1322       // There is no way to know which key name exists so we have to
1323       // drop both, causing an SQL error.  Thus, we just hide the
1324       // error and only report the update_sql results that work.
1325       $err = error_reporting(0);
1326       $ret1 = update_sql('DROP INDEX {url_alias}_dst_idx');
1327       if ($ret1['success']) {
1328   $ret[] = $ret1;
1329       }
1330       $ret1 = array();
1331       db_drop_unique_key($ret, 'url_alias', 'dst');
1332       foreach ($ret1 as $r) {
1333   if ($r['success']) {
1334     $ret[] = $r;
1335   }
1336       }
1337       error_reporting($err);
1338 
1339       $ret[] = update_sql('CREATE UNIQUE INDEX {url_alias}_dst_language_idx ON {url_alias}(dst, language)');
1340       break;
1341     case 'mysql':
1342     case 'mysqli':
1343       $ret[] = update_sql("ALTER TABLE {url_alias} ADD language varchar(12) NOT NULL default ''");
1344       $ret[] = update_sql("ALTER TABLE {url_alias} DROP INDEX dst");
1345       $ret[] = update_sql("ALTER TABLE {url_alias} ADD UNIQUE dst_language (dst, language)");
1346       break;
1347   }
1348   return $ret;
1349 }
1350 
1351 /**
1352  * Drop useless indices on node_counter table.
1353  */
1354 function system_update_6006() {
1355   $ret = array();
1356   switch ($GLOBALS['db_type']) {
1357     case 'pgsql':
1358       $ret[] = update_sql('DROP INDEX {node_counter}_daycount_idx');
1359       $ret[] = update_sql('DROP INDEX {node_counter}_totalcount_idx');
1360       $ret[] = update_sql('DROP INDEX {node_counter}_timestamp_idx');
1361       break;
1362     case 'mysql':
1363     case 'mysqli':
1364       $ret[] = update_sql("ALTER TABLE {node_counter} DROP INDEX daycount");
1365       $ret[] = update_sql("ALTER TABLE {node_counter} DROP INDEX totalcount");
1366       $ret[] = update_sql("ALTER TABLE {node_counter} DROP INDEX timestamp");
1367       break;
1368   }
1369   return $ret;
1370 }
1371 
1372 /**
1373  * Change the severity column in the watchdog table to the new values.
1374  */
1375 function system_update_6007() {
1376   $ret = array();
1377   $ret[] = update_sql("UPDATE {watchdog} SET severity = ". WATCHDOG_NOTICE ." WHERE severity = 0");
1378   $ret[] = update_sql("UPDATE {watchdog} SET severity = ". WATCHDOG_WARNING ." WHERE severity = 1");
1379   $ret[] = update_sql("UPDATE {watchdog} SET severity = ". WATCHDOG_ERROR ." WHERE severity = 2");
1380   return $ret;
1381 }
1382 
1383 /**
1384  * Add info files to themes.  The info and owner columns are added by
1385  * update_fix_d6_requirements() in update.php to avoid a large number
1386  * of error messages from update.php.  All we need to do here is copy
1387  * description to owner and then drop description.
1388  */
1389 function system_update_6008() {
1390   $ret = array();
1391   $ret[] = update_sql('UPDATE {system} SET owner = description');
1392   db_drop_field($ret, 'system', 'description');
1393 
1394   // Rebuild system table contents.
1395   module_rebuild_cache();
1396   system_theme_data();
1397 
1398   return $ret;
1399 }
1400 
1401 /**
1402  * The PHP filter is now a separate module.
1403  */
1404 function system_update_6009() {
1405   $ret = array();
1406 
1407   // If any input format used the Drupal 5 PHP filter.
1408   if (db_result(db_query("SELECT COUNT(format) FROM {filters} WHERE module = 'filter' AND delta = 1"))) {
1409     // Enable the PHP filter module.
1410     $ret[] = update_sql("UPDATE {system} SET status = 1 WHERE name = 'php' AND type = 'module'");
1411     // Update the input filters.
1412     $ret[] = update_sql("UPDATE {filters} SET delta = 0, module = 'php' WHERE module = 'filter' AND delta = 1");
1413   }
1414 
1415   // With the removal of the PHP evaluator filter, the deltas of the line break
1416   // and URL filter have changed.
1417   $ret[] = update_sql("UPDATE {filters} SET delta = 1 WHERE module = 'filter' AND delta = 2");
1418   $ret[] = update_sql("UPDATE {filters} SET delta = 2 WHERE module = 'filter' AND delta = 3");
1419 
1420   return $ret;
1421 }
1422 
1423 /**
1424  * Add variable replacement for watchdog messages.
1425  *
1426  * The variables field is NOT NULL and does not have a default value.
1427  * Existing log messages should not be translated in the new system,
1428  * so we insert 'N;' (serialize(NULL)) as the temporary default but
1429  * then remove the default value to match the schema.
1430  */
1431 function system_update_6010() {
1432   $ret = array();
1433   db_add_field($ret, 'watchdog', 'variables', array('type' => 'text', 'size' => 'big', 'not null' => TRUE, 'initial' => 'N;'));
1434   return $ret;
1435 }
1436 
1437 /**
1438  * Add language support to nodes
1439  */
1440 function system_update_6011() {
1441   $ret = array();
1442   switch ($GLOBALS['db_type']) {
1443     case 'pgsql':
1444       db_add_column($ret, 'node', 'language', 'varchar(12)', array('default' => "''", 'not null' => TRUE));
1445       break;
1446     case 'mysql':
1447     case 'mysqli':
1448       $ret[] = update_sql("ALTER TABLE {node} ADD language varchar(12) NOT NULL default ''");
1449       break;
1450   }
1451   return $ret;
1452 }
1453 
1454 /**
1455  * Add serialized field to cache tables.  This is now handled directly
1456  * by update.php, so this function is a no-op.
1457  */
1458 function system_update_6012() {
1459   return array();
1460 }
1461 
1462 /**
1463  * Rebuild cache data for theme system changes
1464  */
1465 function system_update_6013() {
1466   // Rebuild system table contents.
1467   module_rebuild_cache();
1468   system_theme_data();
1469 
1470   return array(array('success' => TRUE, 'query' => 'Cache rebuilt.'));
1471 }
1472 
1473 /**
1474  * Record that the installer is done, so it is not
1475  * possible to run the installer on upgraded sites.
1476  */
1477 function system_update_6014() {
1478   variable_set('install_task', 'done');
1479 
1480   return array(array('success' => TRUE, 'query' => "variable_set('install_task')"));
1481 }
1482 
1483 /**
1484  * Add the form cache table.
1485  */
1486 function system_update_6015() {
1487   $ret = array();
1488 
1489   switch ($GLOBALS['db_type']) {
1490     case 'pgsql':
1491       $ret[] = update_sql("CREATE TABLE {cache_form} (
1492         cid varchar(255) NOT NULL default '',
1493         data bytea,
1494         expire int NOT NULL default '0',
1495         created int NOT NULL default '0',
1496         headers text,
1497         serialized smallint NOT NULL default '0',
1498         PRIMARY KEY (cid)
1499     )");
1500       $ret[] = update_sql("CREATE INDEX {cache_form}_expire_idx ON {cache_form} (expire)");
1501       break;
1502     case 'mysql':
1503     case 'mysqli':
1504       $ret[] = update_sql("CREATE TABLE {cache_form} (
1505         cid varchar(255) NOT NULL default '',
1506         data longblob,
1507         expire int NOT NULL default '0',
1508         created int NOT NULL default '0',
1509         headers text,
1510         serialized int(1) NOT NULL default '0',
1511         PRIMARY KEY (cid),
1512         INDEX expire (expire)
1513       ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
1514       break;
1515   }
1516 
1517   return $ret;
1518 }
1519 
1520 /**
1521  * Make {node}'s primary key be nid, change nid,vid to a unique key.
1522  * Add primary keys to block, filters, flood, permission, and term_relation.
1523  */
1524 function system_update_6016() {
1525   $ret = array();
1526 
1527   switch ($GLOBALS['db_type']) {
1528     case 'pgsql':
1529       $ret[] = update_sql("ALTER TABLE {node} ADD CONSTRAINT {node}_nid_vid_key UNIQUE (nid, vid)");
1530       db_add_column($ret, 'blocks', 'bid', 'serial');
1531       $ret[] = update_sql("ALTER TABLE {blocks} ADD PRIMARY KEY (bid)");
1532       db_add_column($ret, 'filters', 'fid', 'serial');
1533       $ret[] = update_sql("ALTER TABLE {filters} ADD PRIMARY KEY (fid)");
1534       db_add_column($ret, 'flood', 'fid', 'serial');
1535       $ret[] = update_sql("ALTER TABLE {flood} ADD PRIMARY KEY (fid)");
1536       db_add_column($ret, 'permission', 'pid', 'serial');
1537       $ret[] = update_sql("ALTER TABLE {permission} ADD PRIMARY KEY (pid)");
1538       db_add_column($ret, 'term_relation', 'trid', 'serial');
1539       $ret[] = update_sql("ALTER TABLE {term_relation} ADD PRIMARY KEY (trid)");
1540       db_add_column($ret, 'term_synonym', 'tsid', 'serial');
1541       $ret[] = update_sql("ALTER TABLE {term_synonym} ADD PRIMARY KEY (tsid)");
1542       break;
1543     case 'mysql':
1544     case 'mysqli':
1545       $ret[] = update_sql('ALTER TABLE {node} ADD UNIQUE KEY nid_vid (nid, vid)');
1546       $ret[] = update_sql("ALTER TABLE {blocks} ADD bid int NOT NULL AUTO_INCREMENT PRIMARY KEY");
1547       $ret[] = update_sql("ALTER TABLE {filters} ADD fid int NOT NULL AUTO_INCREMENT PRIMARY KEY");
1548       $ret[] = update_sql("ALTER TABLE {flood} ADD fid int NOT NULL AUTO_INCREMENT PRIMARY KEY");
1549       $ret[] = update_sql("ALTER TABLE {permission} ADD pid int NOT NULL AUTO_INCREMENT PRIMARY KEY");
1550       $ret[] = update_sql("ALTER TABLE {term_relation} ADD trid int NOT NULL AUTO_INCREMENT PRIMARY KEY");
1551       $ret[] = update_sql("ALTER TABLE {term_synonym} ADD tsid int NOT NULL AUTO_INCREMENT PRIMARY KEY");
1552       break;
1553   }
1554 
1555   return $ret;
1556 }
1557 
1558 /**
1559  * Rename settings related to user.module email notifications.
1560  */
1561 function system_update_6017() {
1562   $ret = array();
1563   // Maps old names to new ones.
1564   $var_names = array(
1565     'admin'    => 'register_admin_created',
1566     'approval' => 'register_pending_approval',
1567     'welcome'  => 'register_no_approval_required',
1568     'pass'     => 'password_reset',
1569   );
1570   foreach ($var_names as $old => $new) {
1571     foreach (array('_subject', '_body') as $suffix) {
1572       $old_name = 'user_mail_'. $old . $suffix;
1573       $new_name = 'user_mail_'. $new . $suffix;
1574       if ($old_val = variable_get($old_name, FALSE)) {
1575         variable_set($new_name, $old_val);
1576         variable_del($old_name);
1577         $ret[] = array('success' => TRUE, 'query' => "variable_set($new_name)");
1578         $ret[] = array('success' => TRUE, 'query' => "variable_del($old_name)");
1579         if ($old_name == 'user_mail_approval_body') {
1580           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.');
1581         }
1582       }
1583     }
1584   }
1585   return $ret;
1586 }
1587 
1588 /**
1589  * Add HTML corrector to HTML formats or replace the old module if it was in use.
1590  */
1591 function system_update_6018() {
1592   $ret = array();
1593 
1594   // Disable htmlcorrector.module, if it exists and replace its filter.
1595   if (module_exists('htmlcorrector')) {
1596     module_disable(array('htmlcorrector'));
1597     $ret[] = update_sql("UPDATE {filter_formats} SET module = 'filter', delta = 3 WHERE module = 'htmlcorrector'");
1598     $ret[] = array('success' => TRUE, 'query' => 'HTML Corrector module was disabled; this functionality has now been added to core.');
1599     return $ret;
1600   }
1601 
1602   // Otherwise, find any format with 'HTML' in its name and add the filter at the end.
1603   $result = db_query("SELECT format, name FROM {filter_formats} WHERE name LIKE '%HTML%'");
1604   while ($format = db_fetch_object($result)) {
1605     $weight = db_result(db_query("SELECT MAX(weight) FROM {filters} WHERE format = %d", $format->format));
1606     db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", $format->format, 'filter', 3, max(10, $weight + 1));
1607     $ret[] = array('success' => TRUE, 'query' => "HTML corrector filter added to the '". $format->name ."' input format.");
1608   }
1609 
1610   return $ret;
1611 }
1612 
1613 /**
1614  * Reconcile small differences in the previous, manually created mysql
1615  * and pgsql schemas so they are the same and can be represented by a
1616  * single schema structure.
1617  *
1618  * Note that the mysql and pgsql cases make different changes.  This
1619  * is because each schema needs to be tweaked in different ways to
1620  * conform to the new schema structure.  Also, since they operate on
1621  * tables defined by many optional core modules which may not ever
1622  * have been installed, they must test each table for existence.  If
1623  * the modules are first installed after this update exists the tables
1624  * will be created from the schema structure and will start out
1625  * correct.
1626  */
1627 function system_update_6019() {
1628   $ret = array();
1629 
1630   switch ($GLOBALS['db_type']) {
1631     case 'pgsql':
1632       // Remove default ''.
1633       if (db_table_exists('aggregator_feed')) {
1634         db_field_set_no_default($ret, 'aggregator_feed', 'description');
1635         db_field_set_no_default($ret, 'aggregator_feed', 'image');
1636       }
1637       db_field_set_no_default($ret, 'blocks', 'pages');
1638       if (db_table_exists('contact')) {
1639         db_field_set_no_default($ret, 'contact', 'recipients');
1640         db_field_set_no_default($ret, 'contact', 'reply');
1641       }
1642       db_field_set_no_default($ret, 'watchdog', 'location');
1643       db_field_set_no_default($ret, 'node_revisions', 'body');
1644       db_field_set_no_default($ret, 'node_revisions', 'teaser');
1645       db_field_set_no_default($ret, 'node_revisions', 'log');
1646 
1647       // Update from pgsql 'float' (which means 'double precision') to
1648       // schema 'float' (which in pgsql means 'real').
1649       if (db_table_exists('search_index')) {
1650         db_change_field($ret, 'search_index', 'score', 'score', array('type' => 'float'));
1651       }
1652       if (db_table_exists('search_total')) {
1653         db_change_field($ret, 'search_total', 'count', 'count', array('type' => 'float'));
1654       }
1655 
1656       // Replace unique index dst_language with a unique constraint.  The
1657       // result is the same but the unique key fits our current schema
1658       // structure.  Also, the postgres documentation implies that
1659       // unique constraints are preferable to unique indexes.  See
1660       // http://www.postgresql.org/docs/8.2/interactive/indexes-unique.html.
1661       if (db_table_exists('url_alias')) {
1662         db_drop_index($ret, 'url_alias', 'dst_language');
1663         db_add_unique_key($ret, 'url_alias', 'dst_language',
1664           array('dst', 'language'));
1665       }
1666 
1667       // Fix term_node pkey: mysql and pgsql code had different orders.
1668       if (db_table_exists('term_node')) {
1669         db_drop_primary_key($ret, 'term_node');
1670         db_add_primary_key($ret, 'term_node', array('vid', 'tid', 'nid'));
1671       }
1672 
1673       // Make boxes.bid unsigned.
1674       db_drop_primary_key($ret, 'boxes');
1675       db_change_field($ret, 'boxes', 'bid', 'bid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('bid')));
1676 
1677       // Fix primary key
1678       db_drop_primary_key($ret, 'node');
1679       db_add_primary_key($ret, 'node', array('nid'));
1680 
1681       break;
1682 
1683     case 'mysql':
1684     case 'mysqli':
1685       // Rename key 'link' to 'url'.
1686       if (db_table_exists('aggregator_feed')) {
1687         db_drop_unique_key($ret, 'aggregator_feed', 'link');
1688         db_add_unique_key($ret, 'aggregator_feed', 'url', array('url'));
1689       }
1690 
1691       // Change to size => small.
1692       if (db_table_exists('boxes')) {
1693         db_change_field($ret, 'boxes', 'format', 'format', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
1694       }
1695 
1696       // Change to size => small.
1697       // Rename index 'lid' to 'nid'.
1698       if (db_table_exists('comments')) {
1699         db_change_field($ret, 'comments', 'format', 'format', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
1700         db_drop_index($ret, 'comments', 'lid');
1701         db_add_index($ret, 'comments', 'nid', array('nid'));
1702       }
1703 
1704       // Change to size => small.
1705       db_change_field($ret, 'cache', 'serialized', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
1706       db_change_field($ret, 'cache_filter', 'serialized', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
1707       db_change_field($ret, 'cache_page', 'serialized', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
1708       db_change_field($ret, 'cache_form', 'serialized', 'serialized', array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0));
1709 
1710       // Remove default => 0, set auto increment.
1711       $new_uid = 1 + db_result(db_query('SELECT MAX(uid) FROM {users}'));
1712       $ret[] = update_sql('UPDATE {users} SET uid = '. $new_uid .' WHERE uid = 0');
1713       db_drop_primary_key($ret, 'users');
1714       db_change_field($ret, 'users', 'uid', 'uid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('uid')));
1715       $ret[] = update_sql('UPDATE {users} SET uid = 0 WHERE uid = '. $new_uid);
1716 
1717       // Special field names.
1718       $map = array('node_revisions' => 'vid');
1719       // Make sure these tables have proper auto_increment fields.
1720       foreach (array('boxes', 'files', 'node', 'node_revisions') as $table) {
1721         $field = isset($map[$table]) ? $map[$table] : $table[0] .'id';
1722         db_drop_primary_key($ret, $table);
1723         db_change_field($ret, $table, $field, $field, array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array($field)));
1724       }
1725 
1726       break;
1727   }
1728 
1729   return $ret;
1730 }
1731 
1732 /**
1733  * Create the tables for the new menu system.
1734  */
1735 function system_update_6020() {
1736   $ret = array();
1737 
1738   $schema['menu_router'] = array(
1739     'fields' => array(
1740       'path'             => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1741       'load_functions'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1742       'to_arg_functions' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1743       'access_callback'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1744       'access_arguments' => array('type' => 'text', 'not null' => FALSE),
1745       'page_callback'    => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1746       'page_arguments'   => array('type' => 'text', 'not null' => FALSE),
1747       'fit'              => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
1748       'number_parts'     => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'),
1749       'tab_parent'       => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1750       'tab_root'         => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1751       'title'            => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1752       'title_callback'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1753       'title_arguments'  => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
1754       'type'             => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
1755       'block_callback'   => array('type' => 'varchar', 'length' =>&nb