Projet

Général

Profil

Paste
Télécharger (112 ko) Statistiques
| Branche: | Révision:

root / drupal7 / modules / system / system.install @ 6a4d64c4

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the system module.
6
 */
7

    
8
/**
9
 * Implements hook_requirements().
10
 */
11
function system_requirements($phase) {
12
  global $base_url;
13
  $requirements = array();
14
  // Ensure translations don't break during installation.
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
    // Display the currently active installation profile, if the site
27
    // is not running the default installation profile.
28
    $profile = drupal_get_profile();
29
    if ($profile != 'standard') {
30
      $info = system_get_info('module', $profile);
31
      $requirements['install_profile'] = array(
32
        'title' => $t('Install profile'),
33
        'value' => $t('%profile_name (%profile-%version)', array(
34
          '%profile_name' => $info['name'],
35
          '%profile' => $profile,
36
          '%version' => $info['version']
37
        )),
38
        'severity' => REQUIREMENT_INFO,
39
        'weight' => -9
40
      );
41
    }
42
  }
43

    
44
  // Web server information.
45
  $software = $_SERVER['SERVER_SOFTWARE'];
46
  $requirements['webserver'] = array(
47
    'title' => $t('Web server'),
48
    'value' => $software,
49
  );
50

    
51
  // Test PHP version and show link to phpinfo() if it's available
52
  $phpversion = phpversion();
53
  if (function_exists('phpinfo')) {
54
    $requirements['php'] = array(
55
      'title' => $t('PHP'),
56
      'value' => ($phase == 'runtime') ? $phpversion .' ('. l($t('more information'), 'admin/reports/status/php') .')' : $phpversion,
57
    );
58
  }
59
  else {
60
    $requirements['php'] = array(
61
      'title' => $t('PHP'),
62
      'value' => $phpversion,
63
      'description' => $t('The phpinfo() function has been disabled for security reasons. To see your server\'s phpinfo() information, change your PHP settings or contact your server administrator. For more information, <a href="@phpinfo">Enabling and disabling phpinfo()</a> handbook page.', array('@phpinfo' => 'http://drupal.org/node/243993')),
64
      'severity' => REQUIREMENT_INFO,
65
    );
66
  }
67

    
68
  if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) {
69
    $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP));
70
    $requirements['php']['severity'] = REQUIREMENT_ERROR;
71
    // If PHP is old, it's not safe to continue with the requirements check.
72
    return $requirements;
73
  }
74
  // Check that htmlspecialchars() is secure if the site is running any PHP
75
  // version older than 5.2.5. We don't simply require 5.2.5, because Ubuntu
76
  // 8.04 ships with PHP 5.2.4, but includes the necessary security patch.
77
  elseif (version_compare($phpversion, '5.2.5') < 0 && strlen(@htmlspecialchars(chr(0xC0) . chr(0xAF), ENT_QUOTES, 'UTF-8'))) {
78
    $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP 5.2.5, or PHP @version with the htmlspecialchars security patch backported.', array('@version' => DRUPAL_MINIMUM_PHP));
79
    $requirements['php']['severity'] = REQUIREMENT_ERROR;
80
    // If PHP is old, it's not safe to continue with the requirements check.
81
    return $requirements;
82
  }
83

    
84
  // Test PHP register_globals setting.
85
  $requirements['php_register_globals'] = array(
86
    'title' => $t('PHP register globals'),
87
  );
88
  $register_globals = trim(ini_get('register_globals'));
89
  // Unfortunately, ini_get() may return many different values, and we can't
90
  // be certain which values mean 'on', so we instead check for 'not off'
91
  // since we never want to tell the user that their site is secure
92
  // (register_globals off), when it is in fact on. We can only guarantee
93
  // register_globals is off if the value returned is 'off', '', or 0.
94
  if (!empty($register_globals) && strtolower($register_globals) != 'off') {
95
    $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>.');
96
    $requirements['php_register_globals']['severity'] = REQUIREMENT_ERROR;
97
    $requirements['php_register_globals']['value'] = $t("Enabled ('@value')", array('@value' => $register_globals));
98
  }
99
  else {
100
    $requirements['php_register_globals']['value'] = $t('Disabled');
101
  }
102

    
103
  // Test for PHP extensions.
104
  $requirements['php_extensions'] = array(
105
    'title' => $t('PHP extensions'),
106
  );
107

    
108
  $missing_extensions = array();
109
  $required_extensions = array(
110
    'date',
111
    'dom',
112
    'filter',
113
    'gd',
114
    'hash',
115
    'json',
116
    'pcre',
117
    'pdo',
118
    'session',
119
    'SimpleXML',
120
    'SPL',
121
    'xml',
122
  );
123
  foreach ($required_extensions as $extension) {
124
    if (!extension_loaded($extension)) {
125
      $missing_extensions[] = $extension;
126
    }
127
  }
128

    
129
  if (!empty($missing_extensions)) {
130
    $description = $t('Drupal requires you to enable the PHP extensions in the following list (see the <a href="@system_requirements">system requirements page</a> for more information):', array(
131
      '@system_requirements' => 'http://drupal.org/requirements',
132
    ));
133

    
134
    $description .= theme('item_list', array('items' => $missing_extensions));
135

    
136
    $requirements['php_extensions']['value'] = $t('Disabled');
137
    $requirements['php_extensions']['severity'] = REQUIREMENT_ERROR;
138
    $requirements['php_extensions']['description'] = $description;
139
  }
140
  else {
141
    $requirements['php_extensions']['value'] = $t('Enabled');
142
  }
143

    
144
  if ($phase == 'install' || $phase == 'update') {
145
    // Test for PDO (database).
146
    $requirements['database_extensions'] = array(
147
      'title' => $t('Database support'),
148
    );
149

    
150
    // Make sure PDO is available.
151
    $database_ok = extension_loaded('pdo');
152
    if (!$database_ok) {
153
      $pdo_message = $t('Your web server does not appear to support PDO (PHP Data Objects). Ask your hosting provider if they support the native PDO extension. See the <a href="@link">system requirements</a> page for more information.', array(
154
        '@link' => 'http://drupal.org/requirements/pdo',
155
      ));
156
    }
157
    else {
158
      // Make sure at least one supported database driver exists.
159
      $drivers = drupal_detect_database_types();
160
      if (empty($drivers)) {
161
        $database_ok = FALSE;
162
        $pdo_message = $t('Your web server does not appear to support any common PDO database extensions. Check with your hosting provider to see if they support PDO (PHP Data Objects) and offer any databases that <a href="@drupal-databases">Drupal supports</a>.', array(
163
          '@drupal-databases' => 'http://drupal.org/node/270#database',
164
        ));
165
      }
166
      // Make sure the native PDO extension is available, not the older PEAR
167
      // version. (See install_verify_pdo() for details.)
168
      if (!defined('PDO::ATTR_DEFAULT_FETCH_MODE')) {
169
        $database_ok = FALSE;
170
        $pdo_message = $t('Your web server seems to have the wrong version of PDO installed. Drupal 7 requires the PDO extension from PHP core. This system has the older PECL version. See the <a href="@link">system requirements</a> page for more information.', array(
171
          '@link' => 'http://drupal.org/requirements/pdo#pecl',
172
        ));
173
      }
174
    }
175

    
176
    if (!$database_ok) {
177
      $requirements['database_extensions']['value'] = $t('Disabled');
178
      $requirements['database_extensions']['severity'] = REQUIREMENT_ERROR;
179
      $requirements['database_extensions']['description'] = $pdo_message;
180
    }
181
    else {
182
      $requirements['database_extensions']['value'] = $t('Enabled');
183
    }
184
  }
185
  else {
186
    // Database information.
187
    $class = 'DatabaseTasks_' . Database::getConnection()->driver();
188
    $tasks = new $class();
189
    $requirements['database_system'] = array(
190
      'title' => $t('Database system'),
191
      'value' => $tasks->name(),
192
    );
193
    $requirements['database_system_version'] = array(
194
      'title' => $t('Database system version'),
195
      'value' => Database::getConnection()->version(),
196
    );
197
  }
198

    
199
  // Test PHP memory_limit
200
  $memory_limit = ini_get('memory_limit');
201
  $requirements['php_memory_limit'] = array(
202
    'title' => $t('PHP memory limit'),
203
    'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
204
  );
205

    
206
  if (!drupal_check_memory_limit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
207
    $description = '';
208
    if ($phase == 'install') {
209
      $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));
210
    }
211
    elseif ($phase == 'update') {
212
      $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));
213
    }
214
    elseif ($phase == 'runtime') {
215
      $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));
216
    }
217

    
218
    if (!empty($description)) {
219
      if ($php_ini_path = get_cfg_var('cfg_file_path')) {
220
        $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));
221
      }
222
      else {
223
        $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
224
      }
225

    
226
      $requirements['php_memory_limit']['description'] = $description . ' ' . $t('See the <a href="@url">Drupal requirements</a> for more information.', array('@url' => 'http://drupal.org/requirements'));
227
      $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
228
    }
229
  }
230

    
231
  // Test settings.php file writability
232
  if ($phase == 'runtime') {
233
    $conf_dir = drupal_verify_install_file(conf_path(), FILE_NOT_WRITABLE, 'dir');
234
    $conf_file = drupal_verify_install_file(conf_path() . '/settings.php', FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE);
235
    if (!$conf_dir || !$conf_file) {
236
      $requirements['settings.php'] = array(
237
        'value' => $t('Not protected'),
238
        'severity' => REQUIREMENT_ERROR,
239
        'description' => '',
240
      );
241
      if (!$conf_dir) {
242
        $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()));
243
      }
244
      if (!$conf_file) {
245
        $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'));
246
      }
247
    }
248
    else {
249
      $requirements['settings.php'] = array(
250
        'value' => $t('Protected'),
251
      );
252
    }
253
    $requirements['settings.php']['title'] = $t('Configuration file');
254
  }
255

    
256
  // Test the contents of the .htaccess files.
257
  if ($phase == 'runtime') {
258
    // Try to write the .htaccess files first, to prevent false alarms in case
259
    // (for example) the /tmp directory was wiped.
260
    file_ensure_htaccess();
261
    $htaccess_files['public://.htaccess'] = array(
262
      'title' => $t('Public files directory'),
263
      'directory' => variable_get('file_public_path', conf_path() . '/files'),
264
    );
265
    if ($private_files_directory = variable_get('file_private_path')) {
266
      $htaccess_files['private://.htaccess'] = array(
267
        'title' => $t('Private files directory'),
268
        'directory' => $private_files_directory,
269
      );
270
    }
271
    $htaccess_files['temporary://.htaccess'] = array(
272
      'title' => $t('Temporary files directory'),
273
      'directory' => variable_get('file_temporary_path', file_directory_temp()),
274
    );
275
    foreach ($htaccess_files as $htaccess_file => $info) {
276
      // Check for the string which was added to the recommended .htaccess file
277
      // in the latest security update.
278
      if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
279
        $requirements[$htaccess_file] = array(
280
          'title' => $info['title'],
281
          'value' => $t('Not fully protected'),
282
          'severity' => REQUIREMENT_ERROR,
283
          'description' => $t('See <a href="@url">@url</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', array('@url' => 'http://drupal.org/SA-CORE-2013-003', '%directory' => $info['directory'])),
284
        );
285
      }
286
    }
287
  }
288

    
289
  // Report cron status.
290
  if ($phase == 'runtime') {
291
    // Cron warning threshold defaults to two days.
292
    $threshold_warning = variable_get('cron_threshold_warning', 172800);
293
    // Cron error threshold defaults to two weeks.
294
    $threshold_error = variable_get('cron_threshold_error', 1209600);
295
    // Cron configuration help text.
296
    $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'));
297

    
298
    // Determine when cron last ran.
299
    $cron_last = variable_get('cron_last');
300
    if (!is_numeric($cron_last)) {
301
      $cron_last = variable_get('install_time', 0);
302
    }
303

    
304
    // Determine severity based on time since cron last ran.
305
    $severity = REQUIREMENT_OK;
306
    if (REQUEST_TIME - $cron_last > $threshold_error) {
307
      $severity = REQUIREMENT_ERROR;
308
    }
309
    elseif (REQUEST_TIME - $cron_last > $threshold_warning) {
310
      $severity = REQUIREMENT_WARNING;
311
    }
312

    
313
    // Set summary and description based on values determined above.
314
    $summary = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last)));
315
    $description = '';
316
    if ($severity != REQUIREMENT_OK) {
317
      $description = $t('Cron has not run recently.') . ' ' . $help;
318
    }
319

    
320
    $description .= ' ' . $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron')));
321
    $description .= '<br />' . $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => variable_get('cron_key', 'drupal'))))));
322

    
323
    $requirements['cron'] = array(
324
      'title' => $t('Cron maintenance tasks'),
325
      'severity' => $severity,
326
      'value' => $summary,
327
      'description' => $description
328
    );
329
  }
330

    
331
  // Test files directories.
332
  $directories = array(
333
    variable_get('file_public_path', conf_path() . '/files'),
334
    // By default no private files directory is configured. For private files
335
    // to be secure the admin needs to provide a path outside the webroot.
336
    variable_get('file_private_path', FALSE),
337
  );
338

    
339
  // Do not check for the temporary files directory during installation
340
  // unless it has been set in settings.php. In this case the user has
341
  // no alternative but to fix the directory if it is not writable.
342
  if ($phase == 'install') {
343
    $directories[] = variable_get('file_temporary_path', FALSE);
344
  }
345
  else {
346
    $directories[] = variable_get('file_temporary_path', file_directory_temp());
347
  }
348

    
349
  $requirements['file system'] = array(
350
    'title' => $t('File system'),
351
  );
352

    
353
  $error = '';
354
  // For installer, create the directories if possible.
355
  foreach ($directories as $directory) {
356
    if (!$directory) {
357
      continue;
358
    }
359
    if ($phase == 'install') {
360
      file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
361
    }
362
    $is_writable = is_writable($directory);
363
    $is_directory = is_dir($directory);
364
    if (!$is_writable || !$is_directory) {
365
      $description = '';
366
      $requirements['file system']['value'] = $t('Not writable');
367
      if (!$is_directory) {
368
        $error .= $t('The directory %directory does not exist.', array('%directory' => $directory)) . ' ';
369
      }
370
      else {
371
        $error .= $t('The directory %directory is not writable.', array('%directory' => $directory)) . ' ';
372
      }
373
      // The files directory requirement check is done only during install and runtime.
374
      if ($phase == 'runtime') {
375
        $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/config/media/file-system')));
376
      }
377
      elseif ($phase == 'install') {
378
        // For the installer UI, we need different wording. 'value' will
379
        // be treated as version, so provide none there.
380
        $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, see INSTALL.txt or the <a href="@handbook_url">online handbook</a>.', array('@handbook_url' => 'http://drupal.org/server-permissions'));
381
        $requirements['file system']['value'] = '';
382
      }
383
      if (!empty($description)) {
384
        $requirements['file system']['description'] = $description;
385
        $requirements['file system']['severity'] = REQUIREMENT_ERROR;
386
      }
387
    }
388
    else {
389
      if (file_default_scheme() == 'public') {
390
        $requirements['file system']['value'] = $t('Writable (<em>public</em> download method)');
391
      }
392
      else {
393
        $requirements['file system']['value'] = $t('Writable (<em>private</em> download method)');
394
      }
395
    }
396
  }
397

    
398
  // See if updates are available in update.php.
399
  if ($phase == 'runtime') {
400
    $requirements['update'] = array(
401
      'title' => $t('Database updates'),
402
      'severity' => REQUIREMENT_OK,
403
      'value' => $t('Up to date'),
404
    );
405

    
406
    // Check installed modules.
407
    foreach (module_list() as $module) {
408
      $updates = drupal_get_schema_versions($module);
409
      if ($updates !== FALSE) {
410
        $default = drupal_get_installed_schema_version($module);
411
        if (max($updates) > $default) {
412
          $requirements['update']['severity'] = REQUIREMENT_ERROR;
413
          $requirements['update']['value'] = $t('Out of date');
414
          $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'));
415
          break;
416
        }
417
      }
418
    }
419
  }
420

    
421
  // Verify the update.php access setting
422
  if ($phase == 'runtime') {
423
    if (!empty($GLOBALS['update_free_access'])) {
424
      $requirements['update access'] = array(
425
        'value' => $t('Not protected'),
426
        'severity' => REQUIREMENT_ERROR,
427
        '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.'),
428
      );
429
    }
430
    else {
431
      $requirements['update access'] = array(
432
        'value' => $t('Protected'),
433
      );
434
    }
435
    $requirements['update access']['title'] = $t('Access to update.php');
436
  }
437

    
438
  // Display an error if a newly introduced dependency in a module is not resolved.
439
  if ($phase == 'update') {
440
    $profile = drupal_get_profile();
441
    $files = system_rebuild_module_data();
442
    foreach ($files as $module => $file) {
443
      // Ignore disabled modules and installation profiles.
444
      if (!$file->status || $module == $profile) {
445
        continue;
446
      }
447
      // Check the module's PHP version.
448
      $name = $file->info['name'];
449
      $php = $file->info['php'];
450
      if (version_compare($php, PHP_VERSION, '>')) {
451
        $requirements['php']['description'] .= $t('@name requires at least PHP @version.', array('@name' => $name, '@version' => $php));
452
        $requirements['php']['severity'] = REQUIREMENT_ERROR;
453
      }
454
      // Check the module's required modules.
455
      foreach ($file->requires as $requirement) {
456
        $required_module = $requirement['name'];
457
        // Check if the module exists.
458
        if (!isset($files[$required_module])) {
459
          $requirements["$module-$required_module"] = array(
460
            'title' => $t('Unresolved dependency'),
461
            'description' => $t('@name requires this module.', array('@name' => $name)),
462
            'value' => t('@required_name (Missing)', array('@required_name' => $required_module)),
463
            'severity' => REQUIREMENT_ERROR,
464
          );
465
          continue;
466
        }
467
        // Check for an incompatible version.
468
        $required_file = $files[$required_module];
469
        $required_name = $required_file->info['name'];
470
        $version = str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $required_file->info['version']);
471
        $compatibility = drupal_check_incompatibility($requirement, $version);
472
        if ($compatibility) {
473
          $compatibility = rtrim(substr($compatibility, 2), ')');
474
          $requirements["$module-$required_module"] = array(
475
            'title' => $t('Unresolved dependency'),
476
            'description' => $t('@name requires this module and version. Currently using @required_name version @version', array('@name' => $name, '@required_name' => $required_name, '@version' => $version)),
477
            'value' => t('@required_name (Version @compatibility required)', array('@required_name' => $required_name, '@compatibility' => $compatibility)),
478
            'severity' => REQUIREMENT_ERROR,
479
          );
480
          continue;
481
        }
482
      }
483
    }
484
  }
485

    
486
  // Test Unicode library
487
  include_once DRUPAL_ROOT . '/includes/unicode.inc';
488
  $requirements = array_merge($requirements, unicode_requirements());
489

    
490
  if ($phase == 'runtime') {
491
    // Check for update status module.
492
    if (!module_exists('update')) {
493
      $requirements['update status'] = array(
494
        'value' => $t('Not enabled'),
495
        'severity' => REQUIREMENT_WARNING,
496
        'description' => $t('Update notifications are not enabled. It is <strong>highly recommended</strong> that you enable the update manager module from the <a href="@module">module administration page</a> in order to stay up-to-date on new releases. For more information, <a href="@update">Update status handbook page</a>.', array('@update' => 'http://drupal.org/documentation/modules/update', '@module' => url('admin/modules'))),
497
      );
498
    }
499
    else {
500
      $requirements['update status'] = array(
501
        'value' => $t('Enabled'),
502
      );
503
    }
504
    $requirements['update status']['title'] = $t('Update notifications');
505

    
506
    // Check that Drupal can issue HTTP requests.
507
    if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) {
508
      $requirements['http requests'] = array(
509
        'title' => $t('HTTP request status'),
510
        'value' => $t('Fails'),
511
        'severity' => REQUIREMENT_ERROR,
512
        '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. If you are certain that Drupal can access web pages but you are still seeing this message, you may add <code>$conf[\'drupal_http_request_fails\'] = FALSE;</code> to the bottom of your settings.php file.'),
513
      );
514
    }
515
  }
516

    
517
  return $requirements;
518
}
519

    
520
/**
521
 * Implements hook_install().
522
 */
523
function system_install() {
524
  // Create tables.
525
  drupal_install_schema('system');
526
  $versions = drupal_get_schema_versions('system');
527
  $version = $versions ? max($versions) : SCHEMA_INSTALLED;
528
  drupal_set_installed_schema_version('system', $version);
529

    
530
  // Clear out module list and hook implementation statics before calling
531
  // system_rebuild_theme_data().
532
  module_list(TRUE);
533
  module_implements('', FALSE, TRUE);
534

    
535
  // Load system theme data appropriately.
536
  system_rebuild_theme_data();
537

    
538
  // Enable the default theme.
539
  variable_set('theme_default', 'bartik');
540
  db_update('system')
541
    ->fields(array('status' => 1))
542
    ->condition('type', 'theme')
543
    ->condition('name', 'bartik')
544
    ->execute();
545

    
546
  // Populate the cron key variable.
547
  $cron_key = drupal_random_key();
548
  variable_set('cron_key', $cron_key);
549
}
550

    
551
/**
552
 * Implements hook_schema().
553
 */
554
function system_schema() {
555
  // NOTE: {variable} needs to be created before all other tables, as
556
  // some database drivers, e.g. Oracle and DB2, will require variable_get()
557
  // and variable_set() for overcoming some database specific limitations.
558
  $schema['variable'] = array(
559
    '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.',
560
    'fields' => array(
561
      'name' => array(
562
        'description' => 'The name of the variable.',
563
        'type' => 'varchar',
564
        'length' => 128,
565
        'not null' => TRUE,
566
        'default' => '',
567
      ),
568
      'value' => array(
569
        'description' => 'The value of the variable.',
570
        'type' => 'blob',
571
        'not null' => TRUE,
572
        'size' => 'big',
573
        'translatable' => TRUE,
574
      ),
575
    ),
576
    'primary key' => array('name'),
577
  );
578

    
579
  $schema['actions'] = array(
580
    'description' => 'Stores action information.',
581
    'fields' => array(
582
      'aid' => array(
583
        'description' => 'Primary Key: Unique actions ID.',
584
        'type' => 'varchar',
585
        'length' => 255,
586
        'not null' => TRUE,
587
        'default' => '0',
588
      ),
589
      'type' => array(
590
        'description' => 'The object that that action acts on (node, user, comment, system or custom types.)',
591
        'type' => 'varchar',
592
        'length' => 32,
593
        'not null' => TRUE,
594
        'default' => '',
595
      ),
596
      'callback' => array(
597
        'description' => 'The callback function that executes when the action runs.',
598
        'type' => 'varchar',
599
        'length' => 255,
600
        'not null' => TRUE,
601
        'default' => '',
602
      ),
603
      'parameters' => array(
604
        'description' => 'Parameters to be passed to the callback function.',
605
        'type' => 'blob',
606
        'not null' => TRUE,
607
        'size' => 'big',
608
      ),
609
      'label' => array(
610
        'description' => 'Label of the action.',
611
        'type' => 'varchar',
612
        'length' => 255,
613
        'not null' => TRUE,
614
        'default' => '0',
615
      ),
616
    ),
617
    'primary key' => array('aid'),
618
  );
619

    
620
  $schema['batch'] = array(
621
    'description' => 'Stores details about batches (processes that run in multiple HTTP requests).',
622
    'fields' => array(
623
      'bid' => array(
624
        'description' => 'Primary Key: Unique batch ID.',
625
        // This is not a serial column, to allow both progressive and
626
        // non-progressive batches. See batch_process().
627
        'type' => 'int',
628
        'unsigned' => TRUE,
629
        'not null' => TRUE,
630
      ),
631
      'token' => array(
632
        '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.",
633
        'type' => 'varchar',
634
        'length' => 64,
635
        'not null' => TRUE,
636
      ),
637
      'timestamp' => array(
638
        'description' => 'A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.',
639
        'type' => 'int',
640
        'not null' => TRUE,
641
      ),
642
      'batch' => array(
643
        'description' => 'A serialized array containing the processing data for the batch.',
644
        'type' => 'blob',
645
        'not null' => FALSE,
646
        'size' => 'big',
647
      ),
648
    ),
649
    'primary key' => array('bid'),
650
    'indexes' => array(
651
      'token' => array('token'),
652
    ),
653
  );
654

    
655
  $schema['blocked_ips'] = array(
656
    'description' => 'Stores blocked IP addresses.',
657
    'fields' => array(
658
       'iid' => array(
659
        'description' => 'Primary Key: unique ID for IP addresses.',
660
        'type' => 'serial',
661
        'unsigned' => TRUE,
662
        'not null' => TRUE,
663
      ),
664
      'ip' => array(
665
        'description' => 'IP address',
666
        'type' => 'varchar',
667
        'length' => 40,
668
        'not null' => TRUE,
669
        'default' => '',
670
      ),
671
    ),
672
    'indexes' => array(
673
      'blocked_ip' => array('ip'),
674
    ),
675
    'primary key' => array('iid'),
676
  );
677

    
678
  $schema['cache'] = array(
679
    'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
680
    'fields' => array(
681
      'cid' => array(
682
        'description' => 'Primary Key: Unique cache ID.',
683
        'type' => 'varchar',
684
        'length' => 255,
685
        'not null' => TRUE,
686
        'default' => '',
687
      ),
688
      'data' => array(
689
        'description' => 'A collection of data to cache.',
690
        'type' => 'blob',
691
        'not null' => FALSE,
692
        'size' => 'big',
693
      ),
694
      'expire' => array(
695
        'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
696
        'type' => 'int',
697
        'not null' => TRUE,
698
        'default' => 0,
699
      ),
700
      'created' => array(
701
        'description' => 'A Unix timestamp indicating when the cache entry was created.',
702
        'type' => 'int',
703
        'not null' => TRUE,
704
        'default' => 0,
705
      ),
706
      'serialized' => array(
707
        'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
708
        'type' => 'int',
709
        'size' => 'small',
710
        'not null' => TRUE,
711
        'default' => 0,
712
      ),
713
    ),
714
    'indexes' => array(
715
      'expire' => array('expire'),
716
    ),
717
    'primary key' => array('cid'),
718
  );
719
  $schema['cache_bootstrap'] = $schema['cache'];
720
  $schema['cache_bootstrap']['description'] = 'Cache table for data required to bootstrap Drupal, may be routed to a shared memory cache.';
721
  $schema['cache_form'] = $schema['cache'];
722
  $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.';
723
  $schema['cache_page'] = $schema['cache'];
724
  $schema['cache_page']['description'] = 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.';
725
  $schema['cache_menu'] = $schema['cache'];
726
  $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.';
727
  $schema['cache_path'] = $schema['cache'];
728
  $schema['cache_path']['description'] = 'Cache table for path alias lookup.';
729

    
730
  $schema['date_format_type'] = array(
731
    'description' => 'Stores configured date format types.',
732
    'fields' => array(
733
      'type' => array(
734
        'description' => 'The date format type, e.g. medium.',
735
        'type' => 'varchar',
736
        'length' => 64,
737
        'not null' => TRUE,
738
      ),
739
      'title' => array(
740
        'description' => 'The human readable name of the format type.',
741
        'type' => 'varchar',
742
        'length' => 255,
743
        'not null' => TRUE,
744
      ),
745
      'locked' => array(
746
        'description' => 'Whether or not this is a system provided format.',
747
        'type' => 'int',
748
        'size' => 'tiny',
749
        'default' => 0,
750
        'not null' => TRUE,
751
      ),
752
    ),
753
    'primary key' => array('type'),
754
    'indexes' => array(
755
      'title' => array('title'),
756
    ),
757
  );
758

    
759
  // This table's name is plural as some versions of MySQL can't create a
760
  // table named 'date_format'.
761
  $schema['date_formats'] = array(
762
    'description' => 'Stores configured date formats.',
763
    'fields' => array(
764
      'dfid' => array(
765
        'description' => 'The date format identifier.',
766
        'type' => 'serial',
767
        'not null' => TRUE,
768
        'unsigned' => TRUE,
769
      ),
770
      'format' => array(
771
        'description' => 'The date format string.',
772
        'type' => 'varchar',
773
        'length' => 100,
774
        'not null' => TRUE,
775
        'binary' => TRUE,
776
      ),
777
      'type' => array(
778
        'description' => 'The date format type, e.g. medium.',
779
        'type' => 'varchar',
780
        'length' => 64,
781
        'not null' => TRUE,
782
      ),
783
      'locked' => array(
784
        'description' => 'Whether or not this format can be modified.',
785
        'type' => 'int',
786
        'size' => 'tiny',
787
        'default' => 0,
788
        'not null' => TRUE,
789
      ),
790
    ),
791
    'primary key' => array('dfid'),
792
    'unique keys' => array('formats' => array('format', 'type')),
793
  );
794

    
795
  $schema['date_format_locale'] = array(
796
    'description' => 'Stores configured date formats for each locale.',
797
    'fields' => array(
798
      'format' => array(
799
        'description' => 'The date format string.',
800
        'type' => 'varchar',
801
        'length' => 100,
802
        'not null' => TRUE,
803
      ),
804
      'type' => array(
805
        'description' => 'The date format type, e.g. medium.',
806
        'type' => 'varchar',
807
        'length' => 64,
808
        'not null' => TRUE,
809
      ),
810
      'language' => array(
811
        'description' => 'A {languages}.language for this format to be used with.',
812
        'type' => 'varchar',
813
        'length' => 12,
814
        'not null' => TRUE,
815
      ),
816
    ),
817
    'primary key' => array('type', 'language'),
818
  );
819

    
820
  $schema['file_managed'] = array(
821
    'description' => 'Stores information for uploaded files.',
822
    'fields' => array(
823
      'fid' => array(
824
        'description' => 'File ID.',
825
        'type' => 'serial',
826
        'unsigned' => TRUE,
827
        'not null' => TRUE,
828
      ),
829
      'uid' => array(
830
        'description' => 'The {users}.uid of the user who is associated with the file.',
831
        'type' => 'int',
832
        'unsigned' => TRUE,
833
        'not null' => TRUE,
834
        'default' => 0,
835
      ),
836
      'filename' => array(
837
        'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',
838
        'type' => 'varchar',
839
        'length' => 255,
840
        'not null' => TRUE,
841
        'default' => '',
842
      ),
843
      'uri' => array(
844
        'description' => 'The URI to access the file (either local or remote).',
845
        'type' => 'varchar',
846
        'length' => 255,
847
        'not null' => TRUE,
848
        'default' => '',
849
        'binary' => TRUE,
850
      ),
851
      'filemime' => array(
852
        'description' => "The file's MIME type.",
853
        'type' => 'varchar',
854
        'length' => 255,
855
        'not null' => TRUE,
856
        'default' => '',
857
      ),
858
      'filesize' => array(
859
        'description' => 'The size of the file in bytes.',
860
        'type' => 'int',
861
        'size' => 'big',
862
        'unsigned' => TRUE,
863
        'not null' => TRUE,
864
        'default' => 0,
865
      ),
866
      'status' => array(
867
        'description' => 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.',
868
        'type' => 'int',
869
        'not null' => TRUE,
870
        'default' => 0,
871
        'size' => 'tiny',
872
      ),
873
      'timestamp' => array(
874
        'description' => 'UNIX timestamp for when the file was added.',
875
        'type' => 'int',
876
        'unsigned' => TRUE,
877
        'not null' => TRUE,
878
        'default' => 0,
879
      ),
880
    ),
881
    'indexes' => array(
882
      'uid' => array('uid'),
883
      'status' => array('status'),
884
      'timestamp' => array('timestamp'),
885
    ),
886
    'unique keys' => array(
887
      'uri' => array('uri'),
888
    ),
889
    'primary key' => array('fid'),
890
    'foreign keys' => array(
891
      'file_owner' => array(
892
        'table' => 'users',
893
        'columns' => array('uid' => 'uid'),
894
      ),
895
    ),
896
  );
897

    
898
  $schema['file_usage'] = array(
899
    'description' => 'Track where a file is used.',
900
    'fields' => array(
901
      'fid' => array(
902
        'description' => 'File ID.',
903
        'type' => 'int',
904
        'unsigned' => TRUE,
905
        'not null' => TRUE,
906
      ),
907
      'module' => array(
908
        'description' => 'The name of the module that is using the file.',
909
        'type' => 'varchar',
910
        'length' => 255,
911
        'not null' => TRUE,
912
        'default' => '',
913
      ),
914
      'type' => array(
915
        'description' => 'The name of the object type in which the file is used.',
916
        'type' => 'varchar',
917
        'length' => 64,
918
        'not null' => TRUE,
919
        'default' => '',
920
      ),
921
      'id' => array(
922
        'description' => 'The primary key of the object using the file.',
923
        'type' => 'int',
924
        'unsigned' => TRUE,
925
        'not null' => TRUE,
926
        'default' => 0,
927
      ),
928
      'count' => array(
929
        'description' => 'The number of times this file is used by this object.',
930
        'type' => 'int',
931
        'unsigned' => TRUE,
932
        'not null' => TRUE,
933
        'default' => 0,
934
      ),
935
    ),
936
    'primary key' => array('fid', 'type', 'id', 'module'),
937
    'indexes' => array(
938
      'type_id' => array('type', 'id'),
939
      'fid_count' => array('fid', 'count'),
940
      'fid_module' => array('fid', 'module'),
941
    ),
942
  );
943

    
944
  $schema['flood'] = array(
945
    'description' => 'Flood controls the threshold of events, such as the number of contact attempts.',
946
    'fields' => array(
947
      'fid' => array(
948
        'description' => 'Unique flood event ID.',
949
        'type' => 'serial',
950
        'not null' => TRUE,
951
      ),
952
      'event' => array(
953
        'description' => 'Name of event (e.g. contact).',
954
        'type' => 'varchar',
955
        'length' => 64,
956
        'not null' => TRUE,
957
        'default' => '',
958
      ),
959
      'identifier' => array(
960
        'description' => 'Identifier of the visitor, such as an IP address or hostname.',
961
        'type' => 'varchar',
962
        'length' => 128,
963
        'not null' => TRUE,
964
        'default' => '',
965
      ),
966
      'timestamp' => array(
967
        'description' => 'Timestamp of the event.',
968
        'type' => 'int',
969
        'not null' => TRUE,
970
        'default' => 0,
971
      ),
972
      'expiration' => array(
973
        'description' => 'Expiration timestamp. Expired events are purged on cron run.',
974
        'type' => 'int',
975
        'not null' => TRUE,
976
        'default' => 0,
977
      ),
978
    ),
979
    'primary key' => array('fid'),
980
    'indexes' => array(
981
      'allow' => array('event', 'identifier', 'timestamp'),
982
      'purge' => array('expiration'),
983
    ),
984
  );
985

    
986
  $schema['menu_router'] = array(
987
    'description' => 'Maps paths to various callbacks (access, page and title)',
988
    'fields' => array(
989
      'path' => array(
990
        'description' => 'Primary Key: the Drupal path this entry describes',
991
        'type' => 'varchar',
992
        'length' => 255,
993
        'not null' => TRUE,
994
        'default' => '',
995
      ),
996
      'load_functions' => array(
997
        '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.',
998
        'type' => 'blob',
999
        'not null' => TRUE,
1000
      ),
1001
      'to_arg_functions' => array(
1002
        '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.',
1003
        'type' => 'blob',
1004
        'not null' => TRUE,
1005
      ),
1006
      'access_callback' => array(
1007
        'description' => 'The callback which determines the access to this router path. Defaults to user_access.',
1008
        'type' => 'varchar',
1009
        'length' => 255,
1010
        'not null' => TRUE,
1011
        'default' => '',
1012
      ),
1013
      'access_arguments' => array(
1014
        'description' => 'A serialized array of arguments for the access callback.',
1015
        'type' => 'blob',
1016
        'not null' => FALSE,
1017
      ),
1018
      'page_callback' => array(
1019
        'description' => 'The name of the function that renders the page.',
1020
        'type' => 'varchar',
1021
        'length' => 255,
1022
        'not null' => TRUE,
1023
        'default' => '',
1024
      ),
1025
      'page_arguments' => array(
1026
        'description' => 'A serialized array of arguments for the page callback.',
1027
        'type' => 'blob',
1028
        'not null' => FALSE,
1029
      ),
1030
      'delivery_callback' => array(
1031
        'description' => 'The name of the function that sends the result of the page_callback function to the browser.',
1032
        'type' => 'varchar',
1033
        'length' => 255,
1034
        'not null' => TRUE,
1035
        'default' => '',
1036
      ),
1037
      'fit' => array(
1038
        'description' => 'A numeric representation of how specific the path is.',
1039
        'type' => 'int',
1040
        'not null' => TRUE,
1041
        'default' => 0,
1042
      ),
1043
      'number_parts' => array(
1044
        'description' => 'Number of parts in this router path.',
1045
        'type' => 'int',
1046
        'not null' => TRUE,
1047
        'default' => 0,
1048
        'size' => 'small',
1049
      ),
1050
      'context' => array(
1051
        'description' => 'Only for local tasks (tabs) - the context of a local task to control its placement.',
1052
        'type' => 'int',
1053
        'not null' => TRUE,
1054
        'default' => 0,
1055
      ),
1056
      'tab_parent' => array(
1057
        'description' => 'Only for local tasks (tabs) - the router path of the parent page (which may also be a local task).',
1058
        'type' => 'varchar',
1059
        'length' => 255,
1060
        'not null' => TRUE,
1061
        'default' => '',
1062
      ),
1063
      'tab_root' => array(
1064
        '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.',
1065
        'type' => 'varchar',
1066
        'length' => 255,
1067
        'not null' => TRUE,
1068
        'default' => '',
1069
      ),
1070
      'title' => array(
1071
        'description' => 'The title for the current page, or the title for the tab if this is a local task.',
1072
        'type' => 'varchar',
1073
        'length' => 255,
1074
        'not null' => TRUE,
1075
        'default' => '',
1076
      ),
1077
      'title_callback' => array(
1078
        'description' => 'A function which will alter the title. Defaults to t()',
1079
        'type' => 'varchar',
1080
        'length' => 255,
1081
        'not null' => TRUE,
1082
        'default' => '',
1083
      ),
1084
      'title_arguments' => array(
1085
        '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.',
1086
        'type' => 'varchar',
1087
        'length' => 255,
1088
        'not null' => TRUE,
1089
        'default' => '',
1090
      ),
1091
      'theme_callback' => array(
1092
        'description' => 'A function which returns the name of the theme that will be used to render this page. If left empty, the default theme will be used.',
1093
        'type' => 'varchar',
1094
        'length' => 255,
1095
        'not null' => TRUE,
1096
        'default' => '',
1097
      ),
1098
      'theme_arguments' => array(
1099
        'description' => 'A serialized array of arguments for the theme callback.',
1100
        'type' => 'varchar',
1101
        'length' => 255,
1102
        'not null' => TRUE,
1103
        'default' => '',
1104
      ),
1105
      'type' => array(
1106
        'description' => 'Numeric representation of the type of the menu item, like MENU_LOCAL_TASK.',
1107
        'type' => 'int',
1108
        'not null' => TRUE,
1109
        'default' => 0,
1110
      ),
1111
      'description' => array(
1112
        'description' => 'A description of this item.',
1113
        'type' => 'text',
1114
        'not null' => TRUE,
1115
      ),
1116
      'position' => array(
1117
        'description' => 'The position of the block (left or right) on the system administration page for this item.',
1118
        'type' => 'varchar',
1119
        'length' => 255,
1120
        'not null' => TRUE,
1121
        'default' => '',
1122
      ),
1123
      'weight' => array(
1124
        'description' => 'Weight of the element. Lighter weights are higher up, heavier weights go down.',
1125
        'type' => 'int',
1126
        'not null' => TRUE,
1127
        'default' => 0,
1128
      ),
1129
      'include_file' => array(
1130
        'description' => 'The file to include for this element, usually the page callback function lives in this file.',
1131
        'type' => 'text',
1132
        'size' => 'medium',
1133
      ),
1134
    ),
1135
    'indexes' => array(
1136
      'fit' => array('fit'),
1137
      'tab_parent' => array(array('tab_parent', 64), 'weight', 'title'),
1138
      'tab_root_weight_title' => array(array('tab_root', 64), 'weight', 'title'),
1139
    ),
1140
    'primary key' => array('path'),
1141
  );
1142

    
1143
  $schema['menu_links'] = array(
1144
    'description' => 'Contains the individual links within a menu.',
1145
    'fields' => array(
1146
     'menu_name' => array(
1147
        'description' => "The menu name. All links with the same menu name (such as 'navigation') are part of the same menu.",
1148
        'type' => 'varchar',
1149
        'length' => 32,
1150
        'not null' => TRUE,
1151
        'default' => '',
1152
      ),
1153
      'mlid' => array(
1154
        'description' => 'The menu link ID (mlid) is the integer primary key.',
1155
        'type' => 'serial',
1156
        'unsigned' => TRUE,
1157
        'not null' => TRUE,
1158
      ),
1159
      'plid' => array(
1160
        '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.',
1161
        'type' => 'int',
1162
        'unsigned' => TRUE,
1163
        'not null' => TRUE,
1164
        'default' => 0,
1165
      ),
1166
      'link_path' => array(
1167
        'description' => 'The Drupal path or external path this link points to.',
1168
        'type' => 'varchar',
1169
        'length' => 255,
1170
        'not null' => TRUE,
1171
        'default' => '',
1172
      ),
1173
      'router_path' => array(
1174
        'description' => 'For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.',
1175
        'type' => 'varchar',
1176
        'length' => 255,
1177
        'not null' => TRUE,
1178
        'default' => '',
1179
      ),
1180
      'link_title' => array(
1181
      'description' => 'The text displayed for the link, which may be modified by a title callback stored in {menu_router}.',
1182
        'type' => 'varchar',
1183
        'length' => 255,
1184
        'not null' => TRUE,
1185
        'default' => '',
1186
        'translatable' => TRUE,
1187
      ),
1188
      'options' => array(
1189
        'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.',
1190
        'type' => 'blob',
1191
        'not null' => FALSE,
1192
        'translatable' => TRUE,
1193
      ),
1194
      'module' => array(
1195
        'description' => 'The name of the module that generated this link.',
1196
        'type' => 'varchar',
1197
        'length' => 255,
1198
        'not null' => TRUE,
1199
        'default' => 'system',
1200
      ),
1201
      'hidden' => array(
1202
        '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)',
1203
        'type' => 'int',
1204
        'not null' => TRUE,
1205
        'default' => 0,
1206
        'size' => 'small',
1207
      ),
1208
      'external' => array(
1209
        'description' => 'A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).',
1210
        'type' => 'int',
1211
        'not null' => TRUE,
1212
        'default' => 0,
1213
        'size' => 'small',
1214
      ),
1215
      'has_children' => array(
1216
        'description' => 'Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).',
1217
        'type' => 'int',
1218
        'not null' => TRUE,
1219
        'default' => 0,
1220
        'size' => 'small',
1221
      ),
1222
      'expanded' => array(
1223
        '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)',
1224
        'type' => 'int',
1225
        'not null' => TRUE,
1226
        'default' => 0,
1227
        'size' => 'small',
1228
      ),
1229
      'weight' => array(
1230
        'description' => 'Link weight among links in the same menu at the same depth.',
1231
        'type' => 'int',
1232
        'not null' => TRUE,
1233
        'default' => 0,
1234
      ),
1235
      'depth' => array(
1236
        'description' => 'The depth relative to the top level. A link with plid == 0 will have depth == 1.',
1237
        'type' => 'int',
1238
        'not null' => TRUE,
1239
        'default' => 0,
1240
        'size' => 'small',
1241
      ),
1242
      'customized' => array(
1243
        'description' => 'A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).',
1244
        'type' => 'int',
1245
        'not null' => TRUE,
1246
        'default' => 0,
1247
        'size' => 'small',
1248
      ),
1249
      'p1' => array(
1250
        '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.',
1251
        'type' => 'int',
1252
        'unsigned' => TRUE,
1253
        'not null' => TRUE,
1254
        'default' => 0,
1255
      ),
1256
      'p2' => array(
1257
        'description' => 'The second mlid in the materialized path. See p1.',
1258
        'type' => 'int',
1259
        'unsigned' => TRUE,
1260
        'not null' => TRUE,
1261
        'default' => 0,
1262
      ),
1263
      'p3' => array(
1264
        'description' => 'The third mlid in the materialized path. See p1.',
1265
        'type' => 'int',
1266
        'unsigned' => TRUE,
1267
        'not null' => TRUE,
1268
        'default' => 0,
1269
      ),
1270
      'p4' => array(
1271
        'description' => 'The fourth mlid in the materialized path. See p1.',
1272
        'type' => 'int',
1273
        'unsigned' => TRUE,
1274
        'not null' => TRUE,
1275
        'default' => 0,
1276
      ),
1277
      'p5' => array(
1278
        'description' => 'The fifth mlid in the materialized path. See p1.',
1279
        'type' => 'int',
1280
        'unsigned' => TRUE,
1281
        'not null' => TRUE,
1282
        'default' => 0,
1283
      ),
1284
      'p6' => array(
1285
        'description' => 'The sixth mlid in the materialized path. See p1.',
1286
        'type' => 'int',
1287
        'unsigned' => TRUE,
1288
        'not null' => TRUE,
1289
        'default' => 0,
1290
      ),
1291
      'p7' => array(
1292
        'description' => 'The seventh mlid in the materialized path. See p1.',
1293
        'type' => 'int',
1294
        'unsigned' => TRUE,
1295
        'not null' => TRUE,
1296
        'default' => 0,
1297
      ),
1298
      'p8' => array(
1299
        'description' => 'The eighth mlid in the materialized path. See p1.',
1300
        'type' => 'int',
1301
        'unsigned' => TRUE,
1302
        'not null' => TRUE,
1303
        'default' => 0,
1304
      ),
1305
      'p9' => array(
1306
        'description' => 'The ninth mlid in the materialized path. See p1.',
1307
        'type' => 'int',
1308
        'unsigned' => TRUE,
1309
        'not null' => TRUE,
1310
        'default' => 0,
1311
      ),
1312
      'updated' => array(
1313
        'description' => 'Flag that indicates that this link was generated during the update from Drupal 5.',
1314
        'type' => 'int',
1315
        'not null' => TRUE,
1316
        'default' => 0,
1317
        'size' => 'small',
1318
      ),
1319
    ),
1320
    'indexes' => array(
1321
      'path_menu' => array(array('link_path', 128), 'menu_name'),
1322
      'menu_plid_expand_child' => array('menu_name', 'plid', 'expanded', 'has_children'),
1323
      'menu_parents' => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'),
1324
      'router_path' => array(array('router_path', 128)),
1325
    ),
1326
    'primary key' => array('mlid'),
1327
  );
1328

    
1329
  $schema['queue'] = array(
1330
    'description' => 'Stores items in queues.',
1331
    'fields' => array(
1332
      'item_id' => array(
1333
        'type' => 'serial',
1334
        'unsigned' => TRUE,
1335
        'not null' => TRUE,
1336
        'description' => 'Primary Key: Unique item ID.',
1337
      ),
1338
      'name' => array(
1339
        'type' => 'varchar',
1340
        'length' => 255,
1341
        'not null' => TRUE,
1342
        'default' => '',
1343
        'description' => 'The queue name.',
1344
      ),
1345
      'data' => array(
1346
        'type' => 'blob',
1347
        'not null' => FALSE,
1348
        'size' => 'big',
1349
        'serialize' => TRUE,
1350
        'description' => 'The arbitrary data for the item.',
1351
      ),
1352
      'expire' => array(
1353
        'type' => 'int',
1354
        'not null' => TRUE,
1355
        'default' => 0,
1356
        'description' => 'Timestamp when the claim lease expires on the item.',
1357
      ),
1358
      'created' => array(
1359
        'type' => 'int',
1360
        'not null' => TRUE,
1361
        'default' => 0,
1362
        'description' => 'Timestamp when the item was created.',
1363
      ),
1364
    ),
1365
    'primary key' => array('item_id'),
1366
    'indexes' => array(
1367
      'name_created' => array('name', 'created'),
1368
      'expire' => array('expire'),
1369
    ),
1370
  );
1371

    
1372
  $schema['registry'] = array(
1373
    'description' => "Each record is a function, class, or interface name and the file it is in.",
1374
    'fields' => array(
1375
      'name'   => array(
1376
        'description' => 'The name of the function, class, or interface.',
1377
        'type' => 'varchar',
1378
        'length' => 255,
1379
        'not null' => TRUE,
1380
        'default' => '',
1381
      ),
1382
      'type'   => array(
1383
        'description' => 'Either function or class or interface.',
1384
        'type' => 'varchar',
1385
        'length' => 9,
1386
        'not null' => TRUE,
1387
        'default' => '',
1388
      ),
1389
      'filename'   => array(
1390
        'description' => 'Name of the file.',
1391
        'type' => 'varchar',
1392
        'length' => 255,
1393
        'not null' => TRUE,
1394
      ),
1395
      'module' => array(
1396
        'description' => 'Name of the module the file belongs to.',
1397
        'type' => 'varchar',
1398
        'length' => 255,
1399
        'not null' => TRUE,
1400
        'default' => ''
1401
      ),
1402
      'weight' => array(
1403
        'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
1404
        'type' => 'int',
1405
        'not null' => TRUE,
1406
        'default' => 0,
1407
      ),
1408
    ),
1409
    'primary key' => array('name', 'type'),
1410
    'indexes' => array(
1411
      'hook' => array('type', 'weight', 'module'),
1412
    ),
1413
  );
1414

    
1415
  $schema['registry_file'] = array(
1416
    'description' => "Files parsed to build the registry.",
1417
    'fields' => array(
1418
      'filename'   => array(
1419
        'description' => 'Path to the file.',
1420
        'type' => 'varchar',
1421
        'length' => 255,
1422
        'not null' => TRUE,
1423
      ),
1424
      'hash'  => array(
1425
        'description' => "sha-256 hash of the file's contents when last parsed.",
1426
        'type' => 'varchar',
1427
        'length' => 64,
1428
        'not null' => TRUE,
1429
      ),
1430
    ),
1431
    'primary key' => array('filename'),
1432
  );
1433

    
1434
  $schema['semaphore'] = array(
1435
    'description' => 'Table for holding semaphores, locks, flags, etc. that cannot be stored as Drupal variables since they must not be cached.',
1436
    'fields' => array(
1437
      'name' => array(
1438
        'description' => 'Primary Key: Unique name.',
1439
        'type' => 'varchar',
1440
        'length' => 255,
1441
        'not null' => TRUE,
1442
        'default' => ''
1443
      ),
1444
      'value' => array(
1445
        'description' => 'A value for the semaphore.',
1446
        'type' => 'varchar',
1447
        'length' => 255,
1448
        'not null' => TRUE,
1449
        'default' => ''
1450
      ),
1451
      'expire' => array(
1452
        'description' => 'A Unix timestamp with microseconds indicating when the semaphore should expire.',
1453
        'type' => 'float',
1454
        'size' => 'big',
1455
        'not null' => TRUE
1456
      ),
1457
    ),
1458
    'indexes' => array(
1459
      'value' => array('value'),
1460
      'expire' => array('expire'),
1461
    ),
1462
    'primary key' => array('name'),
1463
  );
1464

    
1465
  $schema['sequences'] = array(
1466
    'description' => 'Stores IDs.',
1467
    'fields' => array(
1468
      'value' => array(
1469
        'description' => 'The value of the sequence.',
1470
        'type' => 'serial',
1471
        'unsigned' => TRUE,
1472
        'not null' => TRUE,
1473
      ),
1474
     ),
1475
    'primary key' => array('value'),
1476
  );
1477

    
1478
  $schema['sessions'] = array(
1479
    'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",
1480
    'fields' => array(
1481
      'uid' => array(
1482
        'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.',
1483
        'type' => 'int',
1484
        'unsigned' => TRUE,
1485
        'not null' => TRUE,
1486
      ),
1487
      'sid' => array(
1488
        'description' => "A session ID. The value is generated by Drupal's session handlers.",
1489
        'type' => 'varchar',
1490
        'length' => 128,
1491
        'not null' => TRUE,
1492
      ),
1493
      'ssid' => array(
1494
        'description' => "Secure session ID. The value is generated by Drupal's session handlers.",
1495
        'type' => 'varchar',
1496
        'length' => 128,
1497
        'not null' => TRUE,
1498
        'default' => '',
1499
      ),
1500
      'hostname' => array(
1501
        'description' => 'The IP address that last used this session ID (sid).',
1502
        'type' => 'varchar',
1503
        'length' => 128,
1504
        'not null' => TRUE,
1505
        'default' => '',
1506
      ),
1507
      'timestamp' => array(
1508
        'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.',
1509
        'type' => 'int',
1510
        'not null' => TRUE,
1511
        'default' => 0,
1512
      ),
1513
      'cache' => array(
1514
        'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get().",
1515
        'type' => 'int',
1516
        'not null' => TRUE,
1517
        'default' => 0,
1518
      ),
1519
      'session' => array(
1520
        '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.',
1521
        'type' => 'blob',
1522
        'not null' => FALSE,
1523
        'size' => 'big',
1524
      ),
1525
    ),
1526
    'primary key' => array(
1527
      'sid',
1528
      'ssid',
1529
    ),
1530
    'indexes' => array(
1531
      'timestamp' => array('timestamp'),
1532
      'uid' => array('uid'),
1533
      'ssid' => array('ssid'),
1534
    ),
1535
    'foreign keys' => array(
1536
      'session_user' => array(
1537
        'table' => 'users',
1538
        'columns' => array('uid' => 'uid'),
1539
      ),
1540
    ),
1541
  );
1542

    
1543
  $schema['system'] = array(
1544
    'description' => "A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system.",
1545
    'fields' => array(
1546
      'filename' => array(
1547
        'description' => 'The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.',
1548
        'type' => 'varchar',
1549
        'length' => 255,
1550
        'not null' => TRUE,
1551
        'default' => '',
1552
      ),
1553
      'name' => array(
1554
        'description' => 'The name of the item; e.g. node.',
1555
        'type' => 'varchar',
1556
        'length' => 255,
1557
        'not null' => TRUE,
1558
        'default' => '',
1559
      ),
1560
      'type' => array(
1561
        'description' => 'The type of the item, either module, theme, or theme_engine.',
1562
        'type' => 'varchar',
1563
        'length' => 12,
1564
        'not null' => TRUE,
1565
        'default' => '',
1566
      ),
1567
      'owner' => array(
1568
        'description' => "A theme's 'parent' . Can be either a theme or an engine.",
1569
        'type' => 'varchar',
1570
        'length' => 255,
1571
        'not null' => TRUE,
1572
        'default' => '',
1573
      ),
1574
      'status' => array(
1575
        'description' => 'Boolean indicating whether or not this item is enabled.',
1576
        'type' => 'int',
1577
        'not null' => TRUE,
1578
        'default' => 0,
1579
      ),
1580
      'bootstrap' => array(
1581
        'description' => "Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted).",
1582
        'type' => 'int',
1583
        'not null' => TRUE,
1584
        'default' => 0,
1585
      ),
1586
      'schema_version' => array(
1587
        '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.",
1588
        'type' => 'int',
1589
        'not null' => TRUE,
1590
        'default' => -1,
1591
        'size' => 'small',
1592
      ),
1593
      'weight' => array(
1594
        'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
1595
        'type' => 'int',
1596
        'not null' => TRUE,
1597
        'default' => 0,
1598
      ),
1599
      'info' => array(
1600
        'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.",
1601
        'type' => 'blob',
1602
        'not null' => FALSE,
1603
      ),
1604
    ),
1605
    'primary key' => array('filename'),
1606
    'indexes' => array(
1607
      'system_list' => array('status', 'bootstrap', 'type', 'weight', 'name'),
1608
      'type_name' => array('type', 'name'),
1609
    ),
1610
  );
1611

    
1612
  $schema['url_alias'] = array(
1613
    'description' => 'A list of URL aliases for Drupal paths; a user may visit either the source or destination path.',
1614
    'fields' => array(
1615
      'pid' => array(
1616
        'description' => 'A unique path alias identifier.',
1617
        'type' => 'serial',
1618
        'unsigned' => TRUE,
1619
        'not null' => TRUE,
1620
      ),
1621
      'source' => array(
1622
        'description' => 'The Drupal path this alias is for; e.g. node/12.',
1623
        'type' => 'varchar',
1624
        'length' => 255,
1625
        'not null' => TRUE,
1626
        'default' => '',
1627
      ),
1628
      'alias' => array(
1629
        'description' => 'The alias for this path; e.g. title-of-the-story.',
1630
        'type' => 'varchar',
1631
        'length' => 255,
1632
        'not null' => TRUE,
1633
        'default' => '',
1634
      ),
1635
      'language' => array(
1636
        'description' => "The language this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
1637
        'type' => 'varchar',
1638
        'length' => 12,
1639
        'not null' => TRUE,
1640
        'default' => '',
1641
      ),
1642
    ),
1643
    'primary key' => array('pid'),
1644
    'indexes' => array(
1645
      'alias_language_pid' => array('alias', 'language', 'pid'),
1646
      'source_language_pid' => array('source', 'language', 'pid'),
1647
    ),
1648
  );
1649

    
1650
  return $schema;
1651
}
1652

    
1653
/**
1654
 * The cache schema corresponding to system_update_7054.
1655
 *
1656
 * Drupal 7 adds several new cache tables. Since they all have identical schema
1657
 * this helper function allows them to re-use the same definition, without
1658
 * relying on system_schema(), which may change with future updates.
1659
 */
1660
function system_schema_cache_7054() {
1661
  return array(
1662
    'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
1663
    'fields' => array(
1664
      'cid' => array(
1665
        'description' => 'Primary Key: Unique cache ID.',
1666
        'type' => 'varchar',
1667
        'length' => 255,
1668
        'not null' => TRUE,
1669
        'default' => '',
1670
      ),
1671
      'data' => array(
1672
        'description' => 'A collection of data to cache.',
1673
        'type' => 'blob',
1674
        'not null' => FALSE,
1675
        'size' => 'big',
1676
      ),
1677
      'expire' => array(
1678
        'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
1679
        'type' => 'int',
1680
        'not null' => TRUE,
1681
        'default' => 0,
1682
      ),
1683
      'created' => array(
1684
        'description' => 'A Unix timestamp indicating when the cache entry was created.',
1685
        'type' => 'int',
1686
        'not null' => TRUE,
1687
        'default' => 0,
1688
      ),
1689
      'serialized' => array(
1690
        'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
1691
        'type' => 'int',
1692
        'size' => 'small',
1693
        'not null' => TRUE,
1694
        'default' => 0,
1695
      ),
1696
    ),
1697
    'indexes' => array(
1698
      'expire' => array('expire'),
1699
    ),
1700
    'primary key' => array('cid'),
1701
  );
1702
}
1703

    
1704

    
1705
// Updates for core.
1706

    
1707
function system_update_last_removed() {
1708
  return 6055;
1709
}
1710

    
1711
/**
1712
 * Implements hook_update_dependencies().
1713
 */
1714
function system_update_dependencies() {
1715
  // system_update_7053() queries the {block} table, so it must run after
1716
  // block_update_7002(), which creates that table.
1717
  $dependencies['system'][7053] = array(
1718
    'block' => 7002,
1719
  );
1720

    
1721
  // system_update_7061() queries the {node_revision} table, so it must run
1722
  // after node_update_7001(), which renames the {node_revisions} table.
1723
  $dependencies['system'][7061] = array(
1724
    'node' => 7001,
1725
  );
1726

    
1727
  // system_update_7067() migrates role permissions and therefore must run
1728
  // after the {role} and {role_permission} tables are properly set up, which
1729
  // happens in user_update_7007().
1730
  $dependencies['system'][7067] = array(
1731
    'user' => 7007,
1732
  );
1733

    
1734
  return $dependencies;
1735
}
1736

    
1737
/**
1738
 * @defgroup updates-6.x-to-7.x Updates from 6.x to 7.x
1739
 * @{
1740
 * Update functions from 6.x to 7.x.
1741
 */
1742

    
1743
/**
1744
 * Rename blog and forum permissions to be consistent with other content types.
1745
 */
1746
function system_update_7000() {
1747
  $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
1748
  foreach ($result as $role) {
1749
    $renamed_permission = $role->perm;
1750
    $renamed_permission = preg_replace('/(?<=^|,\ )create\ blog\ entries(?=,|$)/', 'create blog content', $renamed_permission);
1751
    $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ blog\ entries(?=,|$)/', 'edit own blog content', $renamed_permission);
1752
    $renamed_permission = preg_replace('/(?<=^|,\ )edit\ any\ blog\ entry(?=,|$)/', 'edit any blog content', $renamed_permission);
1753
    $renamed_permission = preg_replace('/(?<=^|,\ )delete\ own\ blog\ entries(?=,|$)/', 'delete own blog content', $renamed_permission);
1754
    $renamed_permission = preg_replace('/(?<=^|,\ )delete\ any\ blog\ entry(?=,|$)/', 'delete any blog content', $renamed_permission);
1755

    
1756
    $renamed_permission = preg_replace('/(?<=^|,\ )create\ forum\ topics(?=,|$)/', 'create forum content', $renamed_permission);
1757
    $renamed_permission = preg_replace('/(?<=^|,\ )delete\ any\ forum\ topic(?=,|$)/', 'delete any forum content', $renamed_permission);
1758
    $renamed_permission = preg_replace('/(?<=^|,\ )delete\ own\ forum\ topics(?=,|$)/', 'delete own forum content', $renamed_permission);
1759
    $renamed_permission = preg_replace('/(?<=^|,\ )edit\ any\ forum\ topic(?=,|$)/', 'edit any forum content', $renamed_permission);
1760
    $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ forum\ topics(?=,|$)/', 'edit own forum content', $renamed_permission);
1761

    
1762
    if ($renamed_permission != $role->perm) {
1763
      db_update('permission')
1764
        ->fields(array('perm' => $renamed_permission))
1765
        ->condition('rid', $role->rid)
1766
        ->execute();
1767
    }
1768
  }
1769
}
1770

    
1771
/**
1772
 * Generate a cron key and save it in the variables table.
1773
 */
1774
function system_update_7001() {
1775
  variable_set('cron_key', drupal_random_key());
1776
}
1777

    
1778
/**
1779
 * Add a table to store blocked IP addresses.
1780
 */
1781
function system_update_7002() {
1782
  $schema['blocked_ips'] = array(
1783
    'description' => 'Stores blocked IP addresses.',
1784
    'fields' => array(
1785
      'iid' => array(
1786
        'description' => 'Primary Key: unique ID for IP addresses.',
1787
        'type' => 'serial',
1788
        'unsigned' => TRUE,
1789
        'not null' => TRUE,
1790
      ),
1791
      'ip' => array(
1792
        'description' => 'IP address',
1793
        'type' => 'varchar',
1794
        'length' => 32,
1795
        'not null' => TRUE,
1796
        'default' => '',
1797
      ),
1798
    ),
1799
    'indexes' => array(
1800
      'blocked_ip' => array('ip'),
1801
    ),
1802
    'primary key' => array('iid'),
1803
  );
1804

    
1805
  db_create_table('blocked_ips', $schema['blocked_ips']);
1806
}
1807

    
1808
/**
1809
 * Update {blocked_ips} with valid IP addresses from {access}.
1810
 */
1811
function system_update_7003() {
1812
  $messages = array();
1813
  $type = 'host';
1814
  $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
1815
    ':status' => 0,
1816
    ':type' => $type,
1817
  ));
1818
  foreach ($result as $blocked) {
1819
    if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) !== FALSE) {
1820
      db_insert('blocked_ips')
1821
        ->fields(array('ip' => $blocked->mask))
1822
        ->execute();
1823
    }
1824
    else {
1825
      $invalid_host = check_plain($blocked->mask);
1826
      $messages[] = t('The host !host is no longer blocked because it is not a valid IP address.', array('!host' => $invalid_host ));
1827
    }
1828
  }
1829
  if (isset($invalid_host)) {
1830
    drupal_set_message('Drupal no longer supports wildcard IP address blocking. Visitors whose IP addresses match ranges you have previously set using <em>access rules</em> will no longer be blocked from your site when you put the site online. See the <a href="http://drupal.org/node/24302">IP address and referrer blocking Handbook page</a> for alternative methods.', 'warning');
1831
  }
1832
  // Make sure not to block any IP addresses that were specifically allowed by access rules.
1833
  if (!empty($result)) {
1834
    $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
1835
      ':status' => 1,
1836
      ':type' => $type,
1837
    ));
1838
    $or = db_condition('or');
1839
    foreach ($result as $allowed) {
1840
      $or->condition('ip', $allowed->mask, 'LIKE');
1841
    }
1842
    if (count($or)) {
1843
      db_delete('blocked_ips')
1844
        ->condition($or)
1845
        ->execute();
1846
    }
1847
  }
1848
}
1849

    
1850
/**
1851
 * Remove hardcoded numeric deltas from all blocks in core.
1852
 */
1853
function system_update_7004(&$sandbox) {
1854
  // Get an array of the renamed block deltas, organized by module.
1855
  $renamed_deltas = array(
1856
    'blog' => array('0' => 'recent'),
1857
    'book' => array('0' => 'navigation'),
1858
    'comment' => array('0' => 'recent'),
1859
    'forum' => array(
1860
      '0' => 'active',
1861
      '1' => 'new',
1862
    ),
1863
    'locale' => array('0' => LANGUAGE_TYPE_INTERFACE),
1864
    'node' => array('0' => 'syndicate'),
1865
    'poll' => array('0' => 'recent'),
1866
    'profile' => array('0' => 'author-information'),
1867
    'search' => array('0' => 'form'),
1868
    'statistics' => array('0' => 'popular'),
1869
    'system' => array('0' => 'powered-by'),
1870
    'user' => array(
1871
      '0' => 'login',
1872
      '1' => 'navigation',
1873
      '2' => 'new',
1874
      '3' => 'online',
1875
    ),
1876
  );
1877

    
1878
  $moved_deltas = array(
1879
    'user' => array('navigation' => 'system'),
1880
  );
1881

    
1882
  // Only run this the first time through the batch update.
1883
  if (!isset($sandbox['progress'])) {
1884
    // Rename forum module's block variables.
1885
    $forum_block_num_0 = variable_get('forum_block_num_0');
1886
    if (isset($forum_block_num_0)) {
1887
      variable_set('forum_block_num_active', $forum_block_num_0);
1888
      variable_del('forum_block_num_0');
1889
    }
1890
    $forum_block_num_1 = variable_get('forum_block_num_1');
1891
    if (isset($forum_block_num_1)) {
1892
      variable_set('forum_block_num_new', $forum_block_num_1);
1893
      variable_del('forum_block_num_1');
1894
    }
1895
  }
1896

    
1897
  update_fix_d7_block_deltas($sandbox, $renamed_deltas, $moved_deltas);
1898

    
1899
}
1900

    
1901
/**
1902
 * Remove throttle columns and variables.
1903
 */
1904
function system_update_7005() {
1905
  db_drop_field('blocks', 'throttle');
1906
  db_drop_field('system', 'throttle');
1907
  variable_del('throttle_user');
1908
  variable_del('throttle_anonymous');
1909
  variable_del('throttle_level');
1910
  variable_del('throttle_probability_limiter');
1911
}
1912

    
1913
/**
1914
 * Convert to new method of storing permissions.
1915
 */
1916
function system_update_7007() {
1917
  // Copy the permissions from the old {permission} table to the new {role_permission} table.
1918
  $messages = array();
1919
  $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
1920
  $query = db_insert('role_permission')->fields(array('rid', 'permission'));
1921
  foreach ($result as $role) {
1922
    foreach (array_unique(explode(', ', $role->perm)) as $perm) {
1923
      $query->values(array(
1924
        'rid' => $role->rid,
1925
        'permission' => $perm,
1926
      ));
1927
    }
1928
    $messages[] = t('Inserted into {role_permission} the permissions for role ID !id', array('!id' => $role->rid));
1929
  }
1930
  $query->execute();
1931
  db_drop_table('permission');
1932

    
1933
  return implode(', ', $messages);
1934
}
1935

    
1936
/**
1937
 * Rename the variable for primary links.
1938
 */
1939
function system_update_7009() {
1940
  $current_primary = variable_get('menu_primary_links_source');
1941
  if (isset($current_primary)) {
1942
    variable_set('menu_main_links_source', $current_primary);
1943
    variable_del('menu_primary_links_source');
1944
  }
1945
}
1946

    
1947
/**
1948
 * Split the 'bypass node access' permission from 'administer nodes'.
1949
 */
1950
function system_update_7011() {
1951
  // Get existing roles that can 'administer nodes'.
1952
  $rids = array();
1953
  $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer nodes'))->fetchCol();
1954
  // None found.
1955
  if (empty($rids)) {
1956
    return;
1957
  }
1958
  $insert = db_insert('role_permission')->fields(array('rid', 'permission'));
1959
  foreach ($rids as $rid) {
1960
    $insert->values(array(
1961
    'rid' => $rid,
1962
    'permission' => 'bypass node access',
1963
    ));
1964
  }
1965
  $insert->execute();
1966
}
1967

    
1968
/**
1969
 * Convert default time zone offset to default time zone name.
1970
 */
1971
function system_update_7013() {
1972
  $timezone = NULL;
1973
  $timezones = system_time_zones();
1974
  // If the contributed Date module set a default time zone name, use this
1975
  // setting as the default time zone.
1976
  if (($timezone_name = variable_get('date_default_timezone_name')) && isset($timezones[$timezone_name])) {
1977
    $timezone = $timezone_name;
1978
  }
1979
  // If the contributed Event module has set a default site time zone, look up
1980
  // the time zone name and use it as the default time zone.
1981
  if (!$timezone && ($timezone_id = variable_get('date_default_timezone_id', 0))) {
1982
    try {
1983
      $timezone_name = db_query('SELECT name FROM {event_timezones} WHERE timezone = :timezone_id', array(':timezone_id' => $timezone_id))->fetchField();
1984
      if (($timezone_name = str_replace(' ', '_', $timezone_name)) && isset($timezones[$timezone_name])) {
1985
        $timezone = $timezone_name;
1986
      }
1987
    }
1988
    catch (PDOException $e) {
1989
      // Ignore error if event_timezones table does not exist or unexpected
1990
      // schema found.
1991
    }
1992
  }
1993

    
1994
  // Check to see if timezone was overriden in update_prepare_d7_bootstrap().
1995
  $offset = variable_get('date_temporary_timezone');
1996
  // If not, use the default.
1997
  if (!isset($offset)) {
1998
    $offset = variable_get('date_default_timezone', 0);
1999
  }
2000

    
2001
  // If the previous default time zone was a non-zero offset, guess the site's
2002
  // intended time zone based on that offset and the server's daylight saving
2003
  // time status.
2004
  if (!$timezone && $offset) {
2005
    $timezone_name = timezone_name_from_abbr('', intval($offset), date('I'));
2006
    if ($timezone_name && isset($timezones[$timezone_name])) {
2007
      $timezone = $timezone_name;
2008
    }
2009
  }
2010
  // Otherwise, the default time zone offset was zero, which is UTC.
2011
  if (!$timezone) {
2012
    $timezone = 'UTC';
2013
  }
2014
  variable_set('date_default_timezone', $timezone);
2015
  drupal_set_message(format_string('The default time zone has been set to %timezone. Check the <a href="@config-url">date and time configuration page</a> to configure it correctly.', array('%timezone' => $timezone, '@config-url' => url('admin/config/regional/settings'))), 'warning');
2016
  // Remove temporary override.
2017
  variable_del('date_temporary_timezone');
2018
}
2019

    
2020
/**
2021
 * Change the user logout path.
2022
 */
2023
function system_update_7015() {
2024
  db_update('menu_links')
2025
    ->fields(array('link_path' => 'user/logout'))
2026
    ->condition('link_path', 'logout')
2027
    ->execute();
2028
  db_update('menu_links')
2029
    ->fields(array('router_path' => 'user/logout'))
2030
    ->condition('router_path', 'logout')
2031
    ->execute();
2032

    
2033
  db_update('menu_links')
2034
    ->fields(array(
2035
      'menu_name' => 'user-menu',
2036
      'plid' => 0,
2037
    ))
2038
    ->condition(db_or()
2039
      ->condition('link_path', 'user/logout')
2040
      ->condition('router_path', 'user/logout')
2041
    )
2042
    ->condition('module', 'system')
2043
    ->condition('customized', 0)
2044
    ->execute();
2045
}
2046

    
2047
/**
2048
 * Remove custom datatype *_unsigned in PostgreSQL.
2049
 */
2050
function system_update_7016() {
2051
  // Only run these queries if the driver used is pgsql.
2052
  if (db_driver() == 'pgsql') {
2053
    $result = db_query("SELECT c.relname AS table, a.attname AS field,
2054
                        pg_catalog.format_type(a.atttypid, a.atttypmod) AS type
2055
                        FROM pg_catalog.pg_attribute a
2056
                        LEFT JOIN pg_class c ON (c.oid =  a.attrelid)
2057
                        WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relkind = 'r'
2058
                        AND pg_catalog.format_type(a.atttypid, a.atttypmod) LIKE '%unsigned%'");
2059
    foreach ($result as $row) {
2060
      switch ($row->type) {
2061
        case 'smallint_unsigned':
2062
          $datatype = 'int';
2063
          break;
2064
        case 'int_unsigned':
2065
        case 'bigint_unsigned':
2066
        default:
2067
          $datatype = 'bigint';
2068
          break;
2069
      }
2070
      db_query('ALTER TABLE ' . $row->table . ' ALTER COLUMN "' . $row->field . '" TYPE ' . $datatype);
2071
      db_query('ALTER TABLE ' . $row->table . ' ADD CHECK ("' . $row->field . '" >= 0)');
2072
    }
2073
    db_query('DROP DOMAIN IF EXISTS smallint_unsigned');
2074
    db_query('DROP DOMAIN IF EXISTS int_unsigned');
2075
    db_query('DROP DOMAIN IF EXISTS bigint_unsigned');
2076
  }
2077
}
2078

    
2079
/**
2080
 * Change the theme setting 'toggle_node_info' into a per content type variable.
2081
 */
2082
function system_update_7017() {
2083
  // Get the global theme settings.
2084
  $settings = variable_get('theme_settings', array());
2085
  // Get the settings of the default theme.
2086
  $settings = array_merge($settings, variable_get('theme_' . variable_get('theme_default', 'garland') . '_settings', array()));
2087

    
2088
  $types = _update_7000_node_get_types();
2089
  foreach ($types as $type) {
2090
    if (isset($settings['toggle_node_info_' . $type->type])) {
2091
      variable_set('node_submitted_' . $type->type, $settings['toggle_node_info_' . $type->type]);
2092
    }
2093
  }
2094

    
2095
  // Unset deprecated 'toggle_node_info' theme settings.
2096
  $theme_settings = variable_get('theme_settings', array());
2097
  foreach ($theme_settings as $setting => $value) {
2098
    if (substr($setting, 0, 16) == 'toggle_node_info') {
2099
      unset($theme_settings[$setting]);
2100
    }
2101
  }
2102
  variable_set('theme_settings', $theme_settings);
2103
}
2104

    
2105
/**
2106
 * Shorten the {system}.type column and modify indexes.
2107
 */
2108
function system_update_7018() {
2109
  db_drop_index('system', 'modules');
2110
  db_drop_index('system', 'type_name');
2111
  db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
2112
  db_add_index('system', 'type_name', array('type', 'name'));
2113
}
2114

    
2115
/**
2116
 * Enable field and field_ui modules.
2117
 */
2118
function system_update_7020() {
2119
  $module_list = array('field_sql_storage', 'field', 'field_ui');
2120
  module_enable($module_list, FALSE);
2121
}
2122

    
2123
/**
2124
 * Change the PHP for settings permission.
2125
 */
2126
function system_update_7021() {
2127
  db_update('role_permission')
2128
    ->fields(array('permission' => 'use PHP for settings'))
2129
    ->condition('permission', 'use PHP for block visibility')
2130
    ->execute();
2131
}
2132

    
2133
/**
2134
 * Enable field type modules.
2135
 */
2136
function system_update_7027() {
2137
  $module_list = array('text', 'number', 'list', 'options');
2138
  module_enable($module_list, FALSE);
2139
}
2140

    
2141
/**
2142
 * Add new 'view own unpublished content' permission for authenticated users.
2143
 * Preserves legacy behavior from Drupal 6.x.
2144
 */
2145
function system_update_7029() {
2146
  db_insert('role_permission')
2147
    ->fields(array(
2148
      'rid' => DRUPAL_AUTHENTICATED_RID,
2149
      'permission' => 'view own unpublished content',
2150
    ))
2151
    ->execute();
2152
}
2153

    
2154
/**
2155
* Alter field hostname to identifier in the {flood} table.
2156
 */
2157
function system_update_7032() {
2158
  db_drop_index('flood', 'allow');
2159
  db_change_field('flood', 'hostname', 'identifier', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
2160
  db_add_index('flood', 'allow', array('event', 'identifier', 'timestamp'));
2161
}
2162

    
2163
/**
2164
 * Move CACHE_AGGRESSIVE to CACHE_NORMAL.
2165
 */
2166
function system_update_7033() {
2167
  if (variable_get('cache') == 2) {
2168
    variable_set('cache', 1);
2169
    return t('Aggressive caching was disabled and replaced with normal caching. Read the page caching section in default.settings.php for more information on how to enable similar functionality.');
2170
  }
2171
}
2172

    
2173
/**
2174
 * Migrate the file path settings and create the new {file_managed} table.
2175
 */
2176
function system_update_7034() {
2177
  $files_directory = variable_get('file_directory_path', NULL);
2178
  if (variable_get('file_downloads', 1) == 1) {
2179
    // Our default is public, so we don't need to set anything.
2180
    if (!empty($files_directory)) {
2181
      variable_set('file_public_path', $files_directory);
2182
    }
2183
  }
2184
  elseif (variable_get('file_downloads', 1) == 2) {
2185
    variable_set('file_default_scheme', 'private');
2186
    if (!empty($files_directory)) {
2187
      variable_set('file_private_path', $files_directory);
2188
    }
2189
  }
2190
  variable_del('file_downloads');
2191

    
2192
  $schema['file_managed'] = array(
2193
    'description' => 'Stores information for uploaded files.',
2194
    'fields' => array(
2195
      'fid' => array(
2196
        'description' => 'File ID.',
2197
        'type' => 'serial',
2198
        'unsigned' => TRUE,
2199
        'not null' => TRUE,
2200
      ),
2201
      'uid' => array(
2202
        'description' => 'The {user}.uid of the user who is associated with the file.',
2203
        'type' => 'int',
2204
        'unsigned' => TRUE,
2205
        'not null' => TRUE,
2206
        'default' => 0,
2207
      ),
2208
      'filename' => array(
2209
        'description' => 'Name of the file with no path components. This may differ from the basename of the filepath if the file is renamed to avoid overwriting an existing file.',
2210
        'type' => 'varchar',
2211
        'length' => 255,
2212
        'not null' => TRUE,
2213
        'default' => '',
2214
        'binary' => TRUE,
2215
      ),
2216
      'uri' => array(
2217
        'description' => 'URI of file.',
2218
        'type' => 'varchar',
2219
        'length' => 255,
2220
        'not null' => TRUE,
2221
        'default' => '',
2222
        'binary' => TRUE,
2223
      ),
2224
      'filemime' => array(
2225
        'description' => "The file's MIME type.",
2226
        'type' => 'varchar',
2227
        'length' => 255,
2228
        'not null' => TRUE,
2229
        'default' => '',
2230
      ),
2231
      'filesize' => array(
2232
        'description' => 'The size of the file in bytes.',
2233
        'type' => 'int',
2234
        'unsigned' => TRUE,
2235
        'not null' => TRUE,
2236
        'default' => 0,
2237
      ),
2238
      'status' => array(
2239
        'description' => 'A field indicating the status of the file. Two status are defined in core: temporary (0) and permanent (1). Temporary files older than DRUPAL_MAXIMUM_TEMP_FILE_AGE will be removed during a cron run.',
2240
        'type' => 'int',
2241
        'not null' => TRUE,
2242
        'default' => 0,
2243
        'size' => 'tiny',
2244
      ),
2245
      'timestamp' => array(
2246
        'description' => 'UNIX timestamp for when the file was added.',
2247
        'type' => 'int',
2248
        'unsigned' => TRUE,
2249
        'not null' => TRUE,
2250
        'default' => 0,
2251
      ),
2252
    ),
2253
    'indexes' => array(
2254
      'uid' => array('uid'),
2255
      'status' => array('status'),
2256
      'timestamp' => array('timestamp'),
2257
    ),
2258
    'unique keys' => array(
2259
      'uri' => array('uri'),
2260
    ),
2261
    'primary key' => array('fid'),
2262
  );
2263

    
2264
  db_create_table('file_managed', $schema['file_managed']);
2265
}
2266

    
2267
/**
2268
 * Split the 'access site in maintenance mode' permission from 'administer site configuration'.
2269
 */
2270
function system_update_7036() {
2271
  // Get existing roles that can 'administer site configuration'.
2272
  $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer site configuration'))->fetchCol();
2273
  // None found.
2274
  if (empty($rids)) {
2275
    return;
2276
  }
2277
  $insert = db_insert('role_permission')->fields(array('rid', 'permission'));
2278
  foreach ($rids as $rid) {
2279
    $insert->values(array(
2280
      'rid' => $rid,
2281
      'permission' => 'access site in maintenance mode',
2282
    ));
2283
  }
2284
  $insert->execute();
2285
}
2286

    
2287
/**
2288
 * Upgrade the {url_alias} table and create a cache bin for path aliases.
2289
 */
2290
function system_update_7042() {
2291
  // update_fix_d7_requirements() adds 'fake' source and alias columns to
2292
  // allow bootstrap to run without fatal errors. Remove those columns now
2293
  // so that we can rename properly.
2294
  db_drop_field('url_alias', 'source');
2295
  db_drop_field('url_alias', 'alias');
2296

    
2297
  // Drop indexes.
2298
  db_drop_index('url_alias', 'src_language_pid');
2299
  db_drop_unique_key('url_alias', 'dst_language_pid');
2300
  // Rename the fields, and increase their length to 255 characters.
2301
  db_change_field('url_alias', 'src', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
2302
  db_change_field('url_alias', 'dst', 'alias', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
2303
  // Add indexes back. We replace the unique key with an index since it never
2304
  // provided any meaningful unique constraint ('pid' is a primary key).
2305
  db_add_index('url_alias', 'source_language_pid', array('source', 'language', 'pid'));
2306
  db_add_index('url_alias', 'alias_language_pid', array('alias', 'language', 'pid'));
2307

    
2308
  // Now that the URL aliases are correct, we can rebuild the whitelist.
2309
  drupal_path_alias_whitelist_rebuild();
2310
}
2311

    
2312
/**
2313
 * Drop the actions_aid table.
2314
 */
2315
function system_update_7044() {
2316
  // The current value of the increment has been taken into account when
2317
  // creating the sequences table in update_fix_d7_requirements().
2318
  db_drop_table('actions_aid');
2319
}
2320

    
2321
/**
2322
 * Add expiration field to the {flood} table.
2323
 */
2324
function system_update_7045() {
2325
  db_add_field('flood', 'expiration', array('description' => 'Expiration timestamp. Expired events are purged on cron run.', 'type' => 'int', 'not null' => TRUE, 'default' => 0));
2326
  db_add_index('flood', 'purge', array('expiration'));
2327
}
2328

    
2329
/**
2330
 * Switch from the Minnelli theme if it is the default or admin theme.
2331
 */
2332
function system_update_7046() {
2333
  if (variable_get('theme_default') == 'minnelli' || variable_get('admin_theme') == 'minnelli') {
2334
    // Make sure Garland is enabled.
2335
    db_update('system')
2336
      ->fields(array('status' => 1))
2337
      ->condition('type', 'theme')
2338
      ->condition('name', 'garland')
2339
      ->execute();
2340
    if (variable_get('theme_default') != 'garland') {
2341
      // If the default theme isn't Garland, transfer all of Minnelli's old
2342
      // settings to Garland.
2343
      $settings = variable_get('theme_minnelli_settings', array());
2344
      // Set the theme setting width to "fixed" to match Minnelli's old layout.
2345
      $settings['garland_width'] = 'fixed';
2346
      variable_set('theme_garland_settings', $settings);
2347
      // Remove Garland's color files since they won't match Minnelli's.
2348
      foreach (variable_get('color_garland_files', array()) as $file) {
2349
        @drupal_unlink($file);
2350
      }
2351
      if (isset($file) && $file = dirname($file)) {
2352
        @drupal_rmdir($file);
2353
      }
2354
      variable_del('color_garland_palette');
2355
      variable_del('color_garland_stylesheets');
2356
      variable_del('color_garland_logo');
2357
      variable_del('color_garland_files');
2358
      variable_del('color_garland_screenshot');
2359
    }
2360
    if (variable_get('theme_default') == 'minnelli') {
2361
      variable_set('theme_default', 'garland');
2362
    }
2363
    if (variable_get('admin_theme') == 'minnelli') {
2364
      variable_set('admin_theme', 'garland');
2365
    }
2366
  }
2367
}
2368

    
2369
/**
2370
 * Normalize the front page path variable.
2371
 */
2372
function system_update_7047() {
2373
  variable_set('site_frontpage', drupal_get_normal_path(variable_get('site_frontpage', 'node')));
2374
}
2375

    
2376
/**
2377
 * Convert path languages from the empty string to LANGUAGE_NONE.
2378
 */
2379
function system_update_7048() {
2380
  db_update('url_alias')
2381
    ->fields(array('language' => LANGUAGE_NONE))
2382
    ->condition('language', '')
2383
    ->execute();
2384
}
2385

    
2386
/**
2387
 * Rename 'Default' profile to 'Standard.'
2388
 */
2389
function system_update_7049() {
2390
  if (variable_get('install_profile', 'standard') == 'default') {
2391
    variable_set('install_profile', 'standard');
2392
  }
2393
}
2394

    
2395
/**
2396
 * Change {batch}.id column from serial to regular int.
2397
 */
2398
function system_update_7050() {
2399
  db_change_field('batch', 'bid', 'bid', array('description' => 'Primary Key: Unique batch ID.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
2400
}
2401

    
2402
/**
2403
 * make the IP field IPv6 compatible
2404
 */
2405
function system_update_7051() {
2406
  db_change_field('blocked_ips', 'ip', 'ip', array('description' => 'IP address', 'type' => 'varchar', 'length' => 40, 'not null' => TRUE, 'default' => ''));
2407
}
2408

    
2409
/**
2410
 * Rename file to include_file in {menu_router} table.
2411
 */
2412
function system_update_7052() {
2413
  db_change_field('menu_router', 'file', 'include_file', array('type' => 'text', 'size' => 'medium'));
2414
}
2415

    
2416
/**
2417
 * Upgrade standard blocks and menus.
2418
 */
2419
function system_update_7053() {
2420
  if (db_table_exists('menu_custom')) {
2421
    // Create the same menus as in menu_install().
2422
    db_insert('menu_custom')
2423
      ->fields(array('menu_name' => 'user-menu', 'title' => 'User Menu', 'description' => "The <em>User</em> menu contains links related to the user's account, as well as the 'Log out' link."))
2424
      ->execute();
2425

    
2426
    db_insert('menu_custom')
2427
      ->fields(array('menu_name' => 'management', 'title' => 'Management', 'description' => "The <em>Management</em> menu contains links for administrative tasks."))
2428
      ->execute();
2429
  }
2430

    
2431
  block_flush_caches();
2432

    
2433
  // Show the new menu blocks along the navigation block.
2434
  $blocks = db_query("SELECT theme, status, region, weight, visibility, pages FROM {block} WHERE module = 'system' AND delta = 'navigation'");
2435
  $deltas = db_or()
2436
    ->condition('delta', 'user-menu')
2437
    ->condition('delta', 'management');
2438

    
2439
  foreach ($blocks as $block) {
2440
    db_update('block')
2441
      ->fields(array(
2442
        'status' => $block->status,
2443
        'region' => $block->region,
2444
        'weight' => $block->weight,
2445
        'visibility' => $block->visibility,
2446
        'pages' => $block->pages,
2447
      ))
2448
      ->condition('theme', $block->theme)
2449
      ->condition('module', 'system')
2450
      ->condition($deltas)
2451
      ->execute();
2452
  }
2453
}
2454

    
2455
/**
2456
 * Remove {cache_*}.headers columns.
2457
 */
2458
function system_update_7054() {
2459
  // Update: update_fix_d7_requirements() installs this version for cache_path
2460
  // already, so we don't include it in this particular update. It should be
2461
  // included in later updates though.
2462
  $cache_tables = array(
2463
    'cache' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
2464
    'cache_form' => 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.',
2465
    'cache_page' => 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.',
2466
    'cache_menu' => 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.',
2467
  );
2468
  $schema = system_schema_cache_7054();
2469
  foreach ($cache_tables as $table => $description) {
2470
    $schema['description'] = $description;
2471
    db_drop_table($table);
2472
    db_create_table($table, $schema);
2473
  }
2474
}
2475

    
2476
/**
2477
 * Converts fields that store serialized variables from text to blob.
2478
 */
2479
function system_update_7055() {
2480
  $spec = array(
2481
    'description' => 'The value of the variable.',
2482
    'type' => 'blob',
2483
    'not null' => TRUE,
2484
    'size' => 'big',
2485
    'translatable' => TRUE,
2486
  );
2487
  db_change_field('variable', 'value', 'value', $spec);
2488

    
2489
  $spec = array(
2490
    'description' => 'Parameters to be passed to the callback function.',
2491
    'type' => 'blob',
2492
    'not null' => TRUE,
2493
    'size' => 'big',
2494
  );
2495
  db_change_field('actions', 'parameters', 'parameters', $spec);
2496

    
2497
  $spec = array(
2498
    'description' => 'A serialized array containing the processing data for the batch.',
2499
    'type' => 'blob',
2500
    'not null' => FALSE,
2501
    'size' => 'big',
2502
  );
2503
  db_change_field('batch', 'batch', 'batch', $spec);
2504

    
2505
  $spec = array(
2506
    '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.',
2507
    'type' => 'blob',
2508
    'not null' => TRUE,
2509
  );
2510
  db_change_field('menu_router', 'load_functions', 'load_functions', $spec);
2511

    
2512
  $spec = array(
2513
    '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.',
2514
    'type' => 'blob',
2515
    'not null' => TRUE,
2516
  );
2517
  db_change_field('menu_router', 'to_arg_functions', 'to_arg_functions', $spec);
2518

    
2519
  $spec = array(
2520
    'description' => 'A serialized array of arguments for the access callback.',
2521
    'type' => 'blob',
2522
    'not null' => FALSE,
2523
  );
2524
  db_change_field('menu_router', 'access_arguments', 'access_arguments', $spec);
2525

    
2526
  $spec = array(
2527
    'description' => 'A serialized array of arguments for the page callback.',
2528
    'type' => 'blob',
2529
    'not null' => FALSE,
2530
  );
2531
  db_change_field('menu_router', 'page_arguments', 'page_arguments', $spec);
2532

    
2533
  $spec = array(
2534
    'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.',
2535
    'type' => 'blob',
2536
    'not null' => FALSE,
2537
    'translatable' => TRUE,
2538
  );
2539
  db_change_field('menu_links', 'options', 'options', $spec);
2540

    
2541
  $spec = array(
2542
    '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.',
2543
    'type' => 'blob',
2544
    'not null' => FALSE,
2545
    'size' => 'big',
2546
  );
2547
  db_change_field('sessions', 'session', 'session', $spec);
2548

    
2549
  $spec = array(
2550
    'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.",
2551
    'type' => 'blob',
2552
    'not null' => FALSE,
2553
  );
2554
  db_change_field('system', 'info', 'info', $spec);
2555
}
2556

    
2557
/**
2558
 * Increase the size of session-ids.
2559
 */
2560
function system_update_7057() {
2561
  $spec = array(
2562
    'description' => "A session ID. The value is generated by PHP's Session API.",
2563
    'type' => 'varchar',
2564
    'length' => 128,
2565
    'not null' => TRUE,
2566
    'default' => '',
2567
  );
2568
  db_change_field('sessions', 'sid', 'sid', $spec);
2569
}
2570

    
2571
/**
2572
 * Remove cron semaphore variable.
2573
 */
2574
function system_update_7058() {
2575
  variable_del('cron_semaphore');
2576
}
2577

    
2578
/**
2579
 * Create the {file_usage} table.
2580
 */
2581
function system_update_7059() {
2582
  $spec = array(
2583
    'description' => 'Track where a file is used.',
2584
    'fields' => array(
2585
      'fid' => array(
2586
        'description' => 'File ID.',
2587
        'type' => 'int',
2588
        'unsigned' => TRUE,
2589
        'not null' => TRUE,
2590
      ),
2591
      'module' => array(
2592
        'description' => 'The name of the module that is using the file.',
2593
        'type' => 'varchar',
2594
        'length' => 255,
2595
        'not null' => TRUE,
2596
        'default' => '',
2597
      ),
2598
      'type' => array(
2599
        'description' => 'The name of the object type in which the file is used.',
2600
        'type' => 'varchar',
2601
        'length' => 64,
2602
        'not null' => TRUE,
2603
        'default' => '',
2604
      ),
2605
      'id' => array(
2606
        'description' => 'The primary key of the object using the file.',
2607
        'type' => 'int',
2608
        'unsigned' => TRUE,
2609
        'not null' => TRUE,
2610
        'default' => 0,
2611
      ),
2612
      'count' => array(
2613
        'description' => 'The number of times this file is used by this object.',
2614
        'type' => 'int',
2615
        'unsigned' => TRUE,
2616
        'not null' => TRUE,
2617
        'default' => 0,
2618
      ),
2619
    ),
2620
    'primary key' => array('fid', 'type', 'id', 'module'),
2621
    'indexes' => array(
2622
      'type_id' => array('type', 'id'),
2623
      'fid_count' => array('fid', 'count'),
2624
      'fid_module' => array('fid', 'module'),
2625
    ),
2626
  );
2627
  db_create_table('file_usage', $spec);
2628
}
2629

    
2630
/**
2631
 * Create fields in preparation for migrating upload.module to file.module.
2632
 */
2633
function system_update_7060() {
2634
  if (!db_table_exists('upload')) {
2635
    return;
2636
  }
2637

    
2638
  if (!db_query_range('SELECT 1 FROM {upload}', 0, 1)->fetchField()) {
2639
    // There is nothing to migrate. Delete variables and the empty table. There
2640
    // is no need to create fields that are not going to be used.
2641
    foreach (_update_7000_node_get_types() as $node_type) {
2642
      variable_del('upload_' . $node_type->type);
2643
    }
2644
    db_drop_table('upload');
2645
    return;
2646
  }
2647

    
2648
  // Check which node types have upload.module attachments enabled.
2649
  $context['types'] = array();
2650
  foreach (_update_7000_node_get_types() as $node_type) {
2651
    if (variable_get('upload_' . $node_type->type, 0)) {
2652
      $context['types'][$node_type->type] = $node_type->type;
2653
    }
2654
  }
2655

    
2656
  // The {upload} table will be deleted when this update is complete so we
2657
  // want to be careful to migrate all the data, even for node types that
2658
  // may have had attachments disabled after files were uploaded. Look for
2659
  // any other node types referenced by the upload records and add those to
2660
  // the list. The admin can always remove the field later.
2661
  $results = db_query('SELECT DISTINCT type FROM {node} n INNER JOIN {node_revision} nr ON n.nid = nr.nid INNER JOIN {upload} u ON nr.vid = u.vid');
2662
  foreach ($results as $row) {
2663
    if (!isset($context['types'][$row->type])) {
2664
      drupal_set_message(t('The content type %rowtype had uploads disabled but contained uploaded file data. Uploads have been re-enabled to migrate the existing data. You may delete the "File attachments" field in the %rowtype type if this data is not necessary.', array('%rowtype' => $row->type)));
2665
      $context['types'][$row->type] = $row->type;
2666
    }
2667
  }
2668

    
2669
  // Create a single "upload" field on all the content types that have uploads
2670
  // enabled, then add an instance to each enabled type.
2671
  if (count($context['types']) > 0) {
2672
    module_enable(array('file'));
2673
    $field = array(
2674
      'field_name' => 'upload',
2675
      'type' => 'file',
2676
      'module' => 'file',
2677
      'locked' => FALSE,
2678
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
2679
      'translatable' => FALSE,
2680
      'settings' => array(
2681
        'display_field' => 1,
2682
        'display_default' => variable_get('upload_list_default', 1),
2683
        'uri_scheme' => file_default_scheme(),
2684
        'default_file' => 0,
2685
      ),
2686
    );
2687

    
2688
    $upload_size = variable_get('upload_uploadsize_default', 1);
2689
    $instance = array(
2690
      'field_name' => 'upload',
2691
      'entity_type' => 'node',
2692
      'bundle' => NULL,
2693
      'label' => 'File attachments',
2694
      'required' => 0,
2695
      'description' => '',
2696
      'widget' => array(
2697
        'weight' => '1',
2698
        'settings' => array(
2699
          'progress_indicator' => 'throbber',
2700
        ),
2701
        'type' => 'file_generic',
2702
      ),
2703
      'settings' => array(
2704
        'max_filesize' => $upload_size ? ($upload_size . ' MB') : '',
2705
        'file_extensions' => variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'),
2706
        'file_directory' => '',
2707
        'description_field' => 1,
2708
      ),
2709
      'display' => array(
2710
        'default' => array(
2711
          'label' => 'hidden',
2712
          'type' => 'file_table',
2713
          'settings' => array(),
2714
          'weight' => 0,
2715
          'module' => 'file',
2716
        ),
2717
        'full' => array(
2718
          'label' => 'hidden',
2719
          'type' => 'file_table',
2720
          'settings' => array(),
2721
          'weight' => 0,
2722
          'module' => 'file',
2723
        ),
2724
        'teaser' => array(
2725
          'label' => 'hidden',
2726
          'type' => 'hidden',
2727
          'settings' => array(),
2728
          'weight' => 0,
2729
          'module' => NULL,
2730
        ),
2731
        'rss' => array(
2732
          'label' => 'hidden',
2733
          'type' => 'file_table',
2734
          'settings' => array(),
2735
          'weight' => 0,
2736
          'module' => 'file',
2737
        ),
2738
      ),
2739
    );
2740

    
2741
    // Create the field.
2742
    _update_7000_field_create_field($field);
2743

    
2744
    // Create the instances.
2745
    foreach ($context['types'] as $bundle) {
2746
      $instance['bundle'] = $bundle;
2747
      _update_7000_field_create_instance($field, $instance);
2748
      // Now that the instance is created, we can safely delete any legacy
2749
      // node type information.
2750
      variable_del('upload_' . $bundle);
2751
    }
2752
  }
2753
  else {
2754
    // No uploads or content types with uploads enabled.
2755
    db_drop_table('upload');
2756
  }
2757
}
2758

    
2759
/**
2760
 * Migrate upload.module data to the newly created file field.
2761
 */
2762
function system_update_7061(&$sandbox) {
2763
  if (!db_table_exists('upload')) {
2764
    return;
2765
  }
2766

    
2767
  if (!isset($sandbox['progress'])) {
2768
    // Delete stale rows from {upload} where the fid is not in the {files} table.
2769
    db_delete('upload')
2770
      ->notExists(
2771
        db_select('files', 'f')
2772
        ->fields('f', array('fid'))
2773
        ->where('f.fid = {upload}.fid')
2774
      )
2775
      ->execute();
2776

    
2777
    // Delete stale rows from {upload} where the vid is not in the
2778
    // {node_revision} table. The table has already been renamed in
2779
    // node_update_7001().
2780
    db_delete('upload')
2781
      ->notExists(
2782
        db_select('node_revision', 'nr')
2783
        ->fields('nr', array('vid'))
2784
        ->where('nr.vid = {upload}.vid')
2785
      )
2786
      ->execute();
2787

    
2788
    // Retrieve a list of node revisions that have uploaded files attached.
2789
    // DISTINCT queries are expensive, especially when paged, so we store the
2790
    // data in its own table for the duration of the update.
2791
    if (!db_table_exists('system_update_7061')) {
2792
      $table = array(
2793
        'description' => t('Stores temporary data for system_update_7061.'),
2794
        'fields' => array('vid' => array('type' => 'int')),
2795
        'primary key' => array('vid'),
2796
      );
2797
      db_create_table('system_update_7061', $table);
2798
    }
2799
    $query = db_select('upload', 'u');
2800
    $query->distinct();
2801
    $query->addField('u','vid');
2802
    db_insert('system_update_7061')
2803
      ->from($query)
2804
      ->execute();
2805

    
2806
    // Initialize batch update information.
2807
    $sandbox['progress'] = 0;
2808
    $sandbox['last_vid_processed'] = -1;
2809
    $sandbox['max'] = db_query("SELECT COUNT(*) FROM {system_update_7061}")->fetchField();
2810
  }
2811

    
2812
  // Determine vids for this batch.
2813
  // Process all files attached to a given revision during the same batch.
2814
  $limit = variable_get('upload_update_batch_size', 100);
2815
  $vids = db_query_range('SELECT vid FROM {system_update_7061} WHERE vid > :lastvid ORDER BY vid', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed']))
2816
    ->fetchCol();
2817

    
2818
  // Retrieve information on all the files attached to these revisions.
2819
  if (!empty($vids)) {
2820
    $node_revisions = array();
2821
    $result = db_query('SELECT u.fid, u.vid, u.list, u.description, n.nid, n.type, u.weight FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid IN (:vids) ORDER BY u.vid, u.weight, u.fid', array(':vids' => $vids));
2822
    foreach ($result as $record) {
2823
      // For each uploaded file, retrieve the corresponding data from the old
2824
      // files table (since upload doesn't know about the new entry in the
2825
      // file_managed table).
2826
      $file = db_select('files', 'f')
2827
        ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp'))
2828
        ->condition('f.fid', $record->fid)
2829
        ->execute()
2830
        ->fetchAssoc();
2831
      if (!$file) {
2832
        continue;
2833
      }
2834

    
2835
      // Add in the file information from the upload table.
2836
      $file['description'] = $record->description;
2837
      $file['display'] = $record->list;
2838

    
2839
      // Create one record for each revision that contains all the uploaded
2840
      // files.
2841
      $node_revisions[$record->vid]['nid'] = $record->nid;
2842
      $node_revisions[$record->vid]['vid'] = $record->vid;
2843
      $node_revisions[$record->vid]['type'] = $record->type;
2844
      $node_revisions[$record->vid]['file'][LANGUAGE_NONE][] = $file;
2845
    }
2846

    
2847
    // Now that we know which files belong to which revisions, update the
2848
    // files'// database entries, and save a reference to each file in the
2849
    // upload field on their node revisions.
2850
    $basename = variable_get('file_directory_path', conf_path() . '/files');
2851
    $scheme = file_default_scheme() . '://';
2852
    foreach ($node_revisions as $vid => $revision) {
2853
      foreach ($revision['file'][LANGUAGE_NONE] as $delta => $file) {
2854
        // We will convert filepaths to URI using the default scheme
2855
        // and stripping off the existing file directory path.
2856
        $file['uri'] = $scheme . preg_replace('!^' . preg_quote($basename) . '!', '', $file['filepath']);
2857
        $file['uri'] = file_stream_wrapper_uri_normalize($file['uri']);
2858
        unset($file['filepath']);
2859
        // Insert into the file_managed table.
2860
        // Each fid should only be stored once in file_managed.
2861
        db_merge('file_managed')
2862
          ->key(array(
2863
            'fid' => $file['fid'],
2864
          ))
2865
          ->fields(array(
2866
            'uid' => $file['uid'],
2867
            'filename' => $file['filename'],
2868
            'uri' => $file['uri'],
2869
            'filemime' => $file['filemime'],
2870
            'filesize' => $file['filesize'],
2871
            'status' => $file['status'],
2872
            'timestamp' => $file['timestamp'],
2873
          ))
2874
          ->execute();
2875

    
2876
        // Add the usage entry for the file.
2877
        $file = (object) $file;
2878
        file_usage_add($file, 'file', 'node', $revision['nid']);
2879

    
2880
        // Update the node revision's upload file field with the file data.
2881
        $revision['file'][LANGUAGE_NONE][$delta] = array('fid' => $file->fid, 'display' => $file->display, 'description' => $file->description);
2882
      }
2883

    
2884
      // Write the revision's upload field data into the field_upload tables.
2885
      $node = (object) $revision;
2886
      _update_7000_field_sql_storage_write('node', $node->type, $node->nid, $node->vid, 'upload', $node->file);
2887

    
2888
      // Update our progress information for the batch update.
2889
      $sandbox['progress']++;
2890
      $sandbox['last_vid_processed'] = $vid;
2891
    }
2892
  }
2893

    
2894
  // If less than limit node revisions were processed, the update process is
2895
  // finished.
2896
  if (count($vids) < $limit) {
2897
    $finished = TRUE;
2898
  }
2899

    
2900
  // If there's no max value then there's nothing to update and we're finished.
2901
  if (empty($sandbox['max']) || isset($finished)) {
2902
    db_drop_table('upload');
2903
    db_drop_table('system_update_7061');
2904
    return t('Upload module has been migrated to File module.');
2905
  }
2906
  else {
2907
    // Indicate our current progress to the batch update system.
2908
    $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
2909
  }
2910
}
2911

    
2912
/**
2913
 * Replace 'system_list' index with 'bootstrap' index on {system}.
2914
 */
2915
function system_update_7062() {
2916
  db_drop_index('system', 'bootstrap');
2917
  db_drop_index('system', 'system_list');
2918
  db_add_index('system', 'system_list', array('status', 'bootstrap', 'type', 'weight', 'name'));
2919
}
2920

    
2921
/**
2922
 * Delete {menu_links} records for 'type' => MENU_CALLBACK which would not appear in a fresh install.
2923
 */
2924
function system_update_7063() {
2925
  // For router items where 'type' => MENU_CALLBACK, {menu_router}.type is
2926
  // stored as 4 in Drupal 6, and 0 in Drupal 7. Fortunately Drupal 7 doesn't
2927
  // store any types as 4, so delete both.
2928
  $result = db_query('SELECT ml.mlid FROM {menu_links} ml INNER JOIN {menu_router} mr ON ml.router_path = mr.path WHERE ml.module = :system AND ml.customized = 0 AND mr.type IN(:callbacks)', array(':callbacks' => array(0, 4), ':system' => 'system'));
2929
  foreach ($result as $record) {
2930
    db_delete('menu_links')->condition('mlid', $record->mlid)->execute();
2931
  }
2932
}
2933

    
2934
/**
2935
 * Remove block_callback field from {menu_router}.
2936
 */
2937
function system_update_7064() {
2938
  db_drop_field('menu_router', 'block_callback');
2939
}
2940

    
2941
/**
2942
 * Remove the default value for sid.
2943
 */
2944
function system_update_7065() {
2945
  $spec = array(
2946
    'description' => "A session ID. The value is generated by Drupal's session handlers.",
2947
    'type' => 'varchar',
2948
    'length' => 128,
2949
    'not null' => TRUE,
2950
  );
2951
  db_drop_primary_key('sessions');
2952
  db_change_field('sessions', 'sid', 'sid', $spec, array('primary key' => array('sid', 'ssid')));
2953
  // Delete any sessions with empty session ID.
2954
  db_delete('sessions')->condition('sid', '')->execute();
2955
}
2956

    
2957
/**
2958
 * Migrate the 'file_directory_temp' variable.
2959
 */
2960
function system_update_7066() {
2961
  $d6_file_directory_temp = variable_get('file_directory_temp', file_directory_temp());
2962
  variable_set('file_temporary_path', $d6_file_directory_temp);
2963
  variable_del('file_directory_temp');
2964
}
2965

    
2966
/**
2967
 * Grant administrators permission to view the administration theme.
2968
 */
2969
function system_update_7067() {
2970
  // Users with access to administration pages already see the administration
2971
  // theme in some places (if one is enabled on the site), so we want them to
2972
  // continue seeing it.
2973
  $admin_roles = user_roles(FALSE, 'access administration pages');
2974
  foreach (array_keys($admin_roles) as $rid) {
2975
    _update_7000_user_role_grant_permissions($rid, array('view the administration theme'), 'system');
2976
  }
2977
  // The above check is not guaranteed to reach all administrative users of the
2978
  // site, so if the site is currently using an administration theme, display a
2979
  // message also.
2980
  if (variable_get('admin_theme')) {
2981
    if (empty($admin_roles)) {
2982
      drupal_set_message('The new "View the administration theme" permission is required in order to view your site\'s administration theme. You can grant this permission to your site\'s administrators on the <a href="' . url('admin/people/permissions', array('fragment' => 'module-system')) . '">permissions page</a>.');
2983
    }
2984
    else {
2985
      drupal_set_message('The new "View the administration theme" permission is required in order to view your site\'s administration theme. This permission has been automatically granted to the following roles: <em>' . check_plain(implode(', ', $admin_roles)) . '</em>. You can grant this permission to other roles on the <a href="' . url('admin/people/permissions', array('fragment' => 'module-system')) . '">permissions page</a>.');
2986
    }
2987
  }
2988
}
2989

    
2990
/**
2991
 * Update {url_alias}.language description.
2992
 */
2993
function system_update_7068() {
2994
  $spec = array(
2995
    'description' => "The language this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
2996
    'type' => 'varchar',
2997
    'length' => 12,
2998
    'not null' => TRUE,
2999
    'default' => '',
3000
  );
3001
  db_change_field('url_alias', 'language', 'language', $spec);
3002
}
3003

    
3004
/**
3005
 * Remove the obsolete 'site_offline' variable.
3006
 *
3007
 * @see update_fix_d7_requirements()
3008
 */
3009
function system_update_7069() {
3010
  variable_del('site_offline');
3011
}
3012

    
3013
/**
3014
 * @} End of "defgroup updates-6.x-to-7.x".
3015
 * The next series of updates should start at 8000.
3016
 */
3017

    
3018
/**
3019
 * @defgroup updates-7.x-extra Extra updates for 7.x
3020
 * @{
3021
 * Update functions between 7.x versions.
3022
 */
3023

    
3024
/**
3025
 * Remove the obsolete 'drupal_badge_color' and 'drupal_badge_size' variables.
3026
 */
3027
function system_update_7070() {
3028
  variable_del('drupal_badge_color');
3029
  variable_del('drupal_badge_size');
3030
}
3031

    
3032
/**
3033
 * Add index missed during upgrade, and fix field default.
3034
 */
3035
function system_update_7071() {
3036
  db_drop_index('date_format_type', 'title');
3037
  db_add_index('date_format_type', 'title', array('title'));
3038
  db_change_field('registry', 'filename', 'filename', array(
3039
    'type' => 'varchar',
3040
    'length' => 255,
3041
    'not null' => TRUE,
3042
  ));
3043
}
3044

    
3045
/**
3046
 * Remove the obsolete 'site_offline_message' variable.
3047
 *
3048
 * @see update_fix_d7_requirements()
3049
 */
3050
function system_update_7072() {
3051
  variable_del('site_offline_message');
3052
}
3053

    
3054
/**
3055
 * Add binary to {file_managed}, in case system_update_7034() was run without
3056
 * it.
3057
 */
3058
function system_update_7073() {
3059
  db_change_field('file_managed', 'filename', 'filename', array(
3060
    'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',
3061
    'type' => 'varchar',
3062
    'length' => 255,
3063
    'not null' => TRUE,
3064
    'default' => '',
3065
    'binary' => TRUE,
3066
  ));
3067
  db_drop_unique_key('file_managed', 'uri');
3068
  db_change_field('file_managed', 'uri', 'uri', array(
3069
    'description' => 'The URI to access the file (either local or remote).',
3070
    'type' => 'varchar',
3071
    'length' => 255,
3072
    'not null' => TRUE,
3073
    'default' => '',
3074
    'binary' => TRUE,
3075
  ));
3076
  db_add_unique_key('file_managed', 'uri', array('uri'));
3077
}
3078

    
3079
/**
3080
 * This update has been removed and will not run.
3081
 */
3082
function system_update_7074() {
3083
  // This update function previously converted menu_links query strings to
3084
  // arrays. It has been removed for now due to incompatibility with
3085
  // PostgreSQL.
3086
}
3087

    
3088
/**
3089
 * Convert menu_links query strings into arrays.
3090
 */
3091
function system_update_7076() {
3092
  $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC))
3093
    ->fields('ml', array('mlid', 'options'));
3094
  foreach ($query->execute() as $menu_link) {
3095
    if (strpos($menu_link['options'], 'query') !== FALSE) {
3096
      $menu_link['options'] = unserialize($menu_link['options']);
3097
      if (isset($menu_link['options']['query']) && is_string($menu_link['options']['query'])) {
3098
        $menu_link['options']['query'] = drupal_get_query_array($menu_link['options']['query']);
3099
        db_update('menu_links')
3100
          ->fields(array(
3101
            'options' => serialize($menu_link['options']),
3102
          ))
3103
          ->condition('mlid', $menu_link['mlid'], '=')
3104
          ->execute();
3105
      }
3106
    }
3107
  }
3108
}
3109

    
3110
/**
3111
 * Revert {file_managed}.filename changed to a binary column.
3112
 */
3113
function system_update_7077() {
3114
  db_change_field('file_managed', 'filename', 'filename', array(
3115
    'description' => 'Name of the file with no path components. This may differ from the basename of the URI if the file is renamed to avoid overwriting an existing file.',
3116
    'type' => 'varchar',
3117
    'length' => 255,
3118
    'not null' => TRUE,
3119
    'default' => '',
3120
  ));
3121
}
3122

    
3123

    
3124
/**
3125
 * Add binary to {date_formats}.format.
3126
 */
3127
function system_update_7078() {
3128
  db_drop_unique_key('date_formats', 'formats');
3129
  db_change_field('date_formats', 'format', 'format', array(
3130
    'description' => 'The date format string.',
3131
    'type' => 'varchar',
3132
    'length' => 100,
3133
    'not null' => TRUE,
3134
    'binary' => TRUE,
3135
  ), array('unique keys' => array('formats' => array('format', 'type'))));
3136
}
3137

    
3138
/**
3139
 * Convert the 'filesize' column in {file_managed} to a bigint.
3140
 */
3141
function system_update_7079() {
3142
  $spec = array(
3143
    'description' => 'The size of the file in bytes.',
3144
    'type' => 'int',
3145
    'size' => 'big',
3146
    'unsigned' => TRUE,
3147
    'not null' => TRUE,
3148
    'default' => 0,
3149
  );
3150
  db_change_field('file_managed', 'filesize', 'filesize', $spec);
3151
}
3152

    
3153
/**
3154
 * @} End of "defgroup updates-7.x-extra".
3155
 * The next series of updates should start at 8000.
3156
 */