Projet

Général

Profil

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

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

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' => 'https://www.drupal.org/requirements/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 database-specific multi-byte UTF-8 related requirements.
200
  $charset_requirements = _system_check_db_utf8mb4_requirements($phase);
201
  if (!empty($charset_requirements)) {
202
    $requirements['database_charset'] = $charset_requirements;
203
  }
204

    
205
  // Test PHP memory_limit
206
  $memory_limit = ini_get('memory_limit');
207
  $requirements['php_memory_limit'] = array(
208
    'title' => $t('PHP memory limit'),
209
    'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
210
  );
211

    
212
  if (!drupal_check_memory_limit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) {
213
    $description = '';
214
    if ($phase == 'install') {
215
      $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));
216
    }
217
    elseif ($phase == 'update') {
218
      $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));
219
    }
220
    elseif ($phase == 'runtime') {
221
      $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));
222
    }
223

    
224
    if (!empty($description)) {
225
      if ($php_ini_path = get_cfg_var('cfg_file_path')) {
226
        $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));
227
      }
228
      else {
229
        $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
230
      }
231

    
232
      $requirements['php_memory_limit']['description'] = $description . ' ' . $t('See the <a href="@url">Drupal requirements</a> for more information.', array('@url' => 'http://drupal.org/requirements'));
233
      $requirements['php_memory_limit']['severity'] = REQUIREMENT_WARNING;
234
    }
235
  }
236

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

    
262
  // Test the contents of the .htaccess files.
263
  if ($phase == 'runtime') {
264
    // Try to write the .htaccess files first, to prevent false alarms in case
265
    // (for example) the /tmp directory was wiped.
266
    file_ensure_htaccess();
267
    $htaccess_files['public://.htaccess'] = array(
268
      'title' => $t('Public files directory'),
269
      'directory' => variable_get('file_public_path', conf_path() . '/files'),
270
    );
271
    if ($private_files_directory = variable_get('file_private_path')) {
272
      $htaccess_files['private://.htaccess'] = array(
273
        'title' => $t('Private files directory'),
274
        'directory' => $private_files_directory,
275
      );
276
    }
277
    $htaccess_files['temporary://.htaccess'] = array(
278
      'title' => $t('Temporary files directory'),
279
      'directory' => variable_get('file_temporary_path', file_directory_temp()),
280
    );
281
    foreach ($htaccess_files as $htaccess_file => $info) {
282
      // Check for the string which was added to the recommended .htaccess file
283
      // in the latest security update.
284
      if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
285
        $requirements[$htaccess_file] = array(
286
          'title' => $info['title'],
287
          'value' => $t('Not fully protected'),
288
          'severity' => REQUIREMENT_ERROR,
289
          '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'])),
290
        );
291
      }
292
    }
293
  }
294

    
295
  // Report cron status.
296
  if ($phase == 'runtime') {
297
    // Cron warning threshold defaults to two days.
298
    $threshold_warning = variable_get('cron_threshold_warning', 172800);
299
    // Cron error threshold defaults to two weeks.
300
    $threshold_error = variable_get('cron_threshold_error', 1209600);
301
    // Cron configuration help text.
302
    $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'));
303

    
304
    // Determine when cron last ran.
305
    $cron_last = variable_get('cron_last');
306
    if (!is_numeric($cron_last)) {
307
      $cron_last = variable_get('install_time', 0);
308
    }
309

    
310
    // Determine severity based on time since cron last ran.
311
    $severity = REQUIREMENT_OK;
312
    if (REQUEST_TIME - $cron_last > $threshold_error) {
313
      $severity = REQUIREMENT_ERROR;
314
    }
315
    elseif (REQUEST_TIME - $cron_last > $threshold_warning) {
316
      $severity = REQUIREMENT_WARNING;
317
    }
318

    
319
    // Set summary and description based on values determined above.
320
    $summary = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last)));
321
    $description = '';
322
    if ($severity != REQUIREMENT_OK) {
323
      $description = $t('Cron has not run recently.') . ' ' . $help;
324
    }
325

    
326
    $description .= ' ' . $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron')));
327
    $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'))))));
328

    
329
    $requirements['cron'] = array(
330
      'title' => $t('Cron maintenance tasks'),
331
      'severity' => $severity,
332
      'value' => $summary,
333
      'description' => $description
334
    );
335
  }
336

    
337
  // Test files directories.
338
  $directories = array(
339
    variable_get('file_public_path', conf_path() . '/files'),
340
    // By default no private files directory is configured. For private files
341
    // to be secure the admin needs to provide a path outside the webroot.
342
    variable_get('file_private_path', FALSE),
343
  );
344

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

    
355
  $requirements['file system'] = array(
356
    'title' => $t('File system'),
357
  );
358

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

    
404
  // See if updates are available in update.php.
405
  if ($phase == 'runtime') {
406
    $requirements['update'] = array(
407
      'title' => $t('Database updates'),
408
      'severity' => REQUIREMENT_OK,
409
      'value' => $t('Up to date'),
410
    );
411

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

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

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

    
492
  // Test Unicode library
493
  include_once DRUPAL_ROOT . '/includes/unicode.inc';
494
  $requirements = array_merge($requirements, unicode_requirements());
495

    
496
  if ($phase == 'runtime') {
497
    // Check for update status module.
498
    if (!module_exists('update')) {
499
      $requirements['update status'] = array(
500
        'value' => $t('Not enabled'),
501
        'severity' => REQUIREMENT_WARNING,
502
        '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'))),
503
      );
504
    }
505
    else {
506
      $requirements['update status'] = array(
507
        'value' => $t('Enabled'),
508
      );
509
    }
510
    $requirements['update status']['title'] = $t('Update notifications');
511

    
512
    // Check that Drupal can issue HTTP requests.
513
    if (variable_get('drupal_http_request_fails', TRUE) && !system_check_http_request()) {
514
      $requirements['http requests'] = array(
515
        'title' => $t('HTTP request status'),
516
        'value' => $t('Fails'),
517
        'severity' => REQUIREMENT_ERROR,
518
        '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.'),
519
      );
520
    }
521
  }
522

    
523
  return $requirements;
524
}
525

    
526
/**
527
 * Checks whether the requirements for multi-byte UTF-8 support are met.
528
 *
529
 * @param string $phase
530
 *   The hook_requirements() stage.
531
 *
532
 * @return array
533
 *   A requirements array with the result of the charset check.
534
 */
535
function _system_check_db_utf8mb4_requirements($phase) {
536
  global $install_state;
537
  // In the requirements check of the installer, skip the utf8mb4 check unless
538
  // the database connection info has been preconfigured by hand with valid
539
  // information before running the installer, as otherwise we cannot get a
540
  // valid database connection object.
541
  if (isset($install_state['settings_verified']) && !$install_state['settings_verified']) {
542
    return array();
543
  }
544

    
545
  $connection = Database::getConnection();
546
  $t = get_t();
547
  $requirements['title'] = $t('Database 4 byte UTF-8 support');
548

    
549
  $utf8mb4_configurable = $connection->utf8mb4IsConfigurable();
550
  $utf8mb4_active = $connection->utf8mb4IsActive();
551
  $utf8mb4_supported = $connection->utf8mb4IsSupported();
552
  $driver = $connection->driver();
553
  $documentation_url = 'https://www.drupal.org/node/2754539';
554

    
555
  if ($utf8mb4_active) {
556
    if ($utf8mb4_supported) {
557
      if ($phase != 'install' && $utf8mb4_configurable && !variable_get('drupal_all_databases_are_utf8mb4', FALSE)) {
558
        // Supported, active, and configurable, but not all database tables
559
        // have been converted yet.
560
        $requirements['value'] = $t('Enabled, but database tables need conversion');
561
        $requirements['description'] = $t('Please convert all database tables to utf8mb4 prior to enabling it in settings.php. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@url' => $documentation_url));
562
        $requirements['severity'] = REQUIREMENT_ERROR;
563
      }
564
      else {
565
        // Supported, active.
566
        $requirements['value'] = $t('Enabled');
567
        $requirements['description'] = $t('4 byte UTF-8 for @driver is enabled.', array('@driver' => $driver));
568
        $requirements['severity'] = REQUIREMENT_OK;
569
      }
570
    }
571
    else {
572
      // Not supported, active.
573
      $requirements['value'] = $t('Not supported');
574
      $requirements['description'] = $t('4 byte UTF-8 for @driver is activated, but not supported on your system. Please turn this off in settings.php, or ensure that all database-related requirements are met. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@driver' => $driver, '@url' => $documentation_url));
575
      $requirements['severity'] = REQUIREMENT_ERROR;
576
    }
577
  }
578
  else {
579
    if ($utf8mb4_supported) {
580
      // Supported, not active.
581
      $requirements['value'] = $t('Not enabled');
582
      $requirements['description'] = $t('4 byte UTF-8 for @driver is not activated, but it is supported on your system. It is recommended that you enable this to allow 4-byte UTF-8 input such as emojis, Asian symbols and mathematical symbols to be stored correctly. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@driver' => $driver, '@url' => $documentation_url));
583
      $requirements['severity'] = REQUIREMENT_INFO;
584
    }
585
    else {
586
      // Not supported, not active.
587
      $requirements['value'] = $t('Disabled');
588
      $requirements['description'] = $t('4 byte UTF-8 for @driver is disabled. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@driver' => $driver, '@url' => $documentation_url));
589
      $requirements['severity'] = REQUIREMENT_INFO;
590
    }
591
  }
592
  return $requirements;
593
}
594

    
595
/**
596
 * Implements hook_install().
597
 */
598
function system_install() {
599
  // Create tables.
600
  drupal_install_schema('system');
601
  $versions = drupal_get_schema_versions('system');
602
  $version = $versions ? max($versions) : SCHEMA_INSTALLED;
603
  drupal_set_installed_schema_version('system', $version);
604

    
605
  // Clear out module list and hook implementation statics before calling
606
  // system_rebuild_theme_data().
607
  module_list(TRUE);
608
  module_implements('', FALSE, TRUE);
609

    
610
  // Ensure the schema versions are not based on a previous module list.
611
  drupal_static_reset('drupal_get_schema_versions');
612

    
613
  // Load system theme data appropriately.
614
  system_rebuild_theme_data();
615

    
616
  // Enable the default theme.
617
  variable_set('theme_default', 'bartik');
618
  db_update('system')
619
    ->fields(array('status' => 1))
620
    ->condition('type', 'theme')
621
    ->condition('name', 'bartik')
622
    ->execute();
623

    
624
  // Populate the cron key variable.
625
  $cron_key = drupal_random_key();
626
  variable_set('cron_key', $cron_key);
627
}
628

    
629
/**
630
 * Implements hook_schema().
631
 */
632
function system_schema() {
633
  // NOTE: {variable} needs to be created before all other tables, as
634
  // some database drivers, e.g. Oracle and DB2, will require variable_get()
635
  // and variable_set() for overcoming some database specific limitations.
636
  $schema['variable'] = array(
637
    '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.',
638
    'fields' => array(
639
      'name' => array(
640
        'description' => 'The name of the variable.',
641
        'type' => 'varchar',
642
        'length' => 128,
643
        'not null' => TRUE,
644
        'default' => '',
645
      ),
646
      'value' => array(
647
        'description' => 'The value of the variable.',
648
        'type' => 'blob',
649
        'not null' => TRUE,
650
        'size' => 'big',
651
        'translatable' => TRUE,
652
      ),
653
    ),
654
    'primary key' => array('name'),
655
  );
656

    
657
  $schema['actions'] = array(
658
    'description' => 'Stores action information.',
659
    'fields' => array(
660
      'aid' => array(
661
        'description' => 'Primary Key: Unique actions ID.',
662
        'type' => 'varchar',
663
        'length' => 255,
664
        'not null' => TRUE,
665
        'default' => '0',
666
      ),
667
      'type' => array(
668
        'description' => 'The object that that action acts on (node, user, comment, system or custom types.)',
669
        'type' => 'varchar',
670
        'length' => 32,
671
        'not null' => TRUE,
672
        'default' => '',
673
      ),
674
      'callback' => array(
675
        'description' => 'The callback function that executes when the action runs.',
676
        'type' => 'varchar',
677
        'length' => 255,
678
        'not null' => TRUE,
679
        'default' => '',
680
      ),
681
      'parameters' => array(
682
        'description' => 'Parameters to be passed to the callback function.',
683
        'type' => 'blob',
684
        'not null' => TRUE,
685
        'size' => 'big',
686
      ),
687
      'label' => array(
688
        'description' => 'Label of the action.',
689
        'type' => 'varchar',
690
        'length' => 255,
691
        'not null' => TRUE,
692
        'default' => '0',
693
      ),
694
    ),
695
    'primary key' => array('aid'),
696
  );
697

    
698
  $schema['batch'] = array(
699
    'description' => 'Stores details about batches (processes that run in multiple HTTP requests).',
700
    'fields' => array(
701
      'bid' => array(
702
        'description' => 'Primary Key: Unique batch ID.',
703
        // This is not a serial column, to allow both progressive and
704
        // non-progressive batches. See batch_process().
705
        'type' => 'int',
706
        'unsigned' => TRUE,
707
        'not null' => TRUE,
708
      ),
709
      'token' => array(
710
        '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.",
711
        'type' => 'varchar',
712
        'length' => 64,
713
        'not null' => TRUE,
714
      ),
715
      'timestamp' => array(
716
        'description' => 'A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.',
717
        'type' => 'int',
718
        'not null' => TRUE,
719
      ),
720
      'batch' => array(
721
        'description' => 'A serialized array containing the processing data for the batch.',
722
        'type' => 'blob',
723
        'not null' => FALSE,
724
        'size' => 'big',
725
      ),
726
    ),
727
    'primary key' => array('bid'),
728
    'indexes' => array(
729
      'token' => array('token'),
730
    ),
731
  );
732

    
733
  $schema['blocked_ips'] = array(
734
    'description' => 'Stores blocked IP addresses.',
735
    'fields' => array(
736
       'iid' => array(
737
        'description' => 'Primary Key: unique ID for IP addresses.',
738
        'type' => 'serial',
739
        'unsigned' => TRUE,
740
        'not null' => TRUE,
741
      ),
742
      'ip' => array(
743
        'description' => 'IP address',
744
        'type' => 'varchar',
745
        'length' => 40,
746
        'not null' => TRUE,
747
        'default' => '',
748
      ),
749
    ),
750
    'indexes' => array(
751
      'blocked_ip' => array('ip'),
752
    ),
753
    'primary key' => array('iid'),
754
  );
755

    
756
  $schema['cache'] = array(
757
    'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
758
    'fields' => array(
759
      'cid' => array(
760
        'description' => 'Primary Key: Unique cache ID.',
761
        'type' => 'varchar',
762
        'length' => 255,
763
        'not null' => TRUE,
764
        'default' => '',
765
      ),
766
      'data' => array(
767
        'description' => 'A collection of data to cache.',
768
        'type' => 'blob',
769
        'not null' => FALSE,
770
        'size' => 'big',
771
      ),
772
      'expire' => array(
773
        'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
774
        'type' => 'int',
775
        'not null' => TRUE,
776
        'default' => 0,
777
      ),
778
      'created' => array(
779
        'description' => 'A Unix timestamp indicating when the cache entry was created.',
780
        'type' => 'int',
781
        'not null' => TRUE,
782
        'default' => 0,
783
      ),
784
      'serialized' => array(
785
        'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
786
        'type' => 'int',
787
        'size' => 'small',
788
        'not null' => TRUE,
789
        'default' => 0,
790
      ),
791
    ),
792
    'indexes' => array(
793
      'expire' => array('expire'),
794
    ),
795
    'primary key' => array('cid'),
796
  );
797
  $schema['cache_bootstrap'] = $schema['cache'];
798
  $schema['cache_bootstrap']['description'] = 'Cache table for data required to bootstrap Drupal, may be routed to a shared memory cache.';
799
  $schema['cache_form'] = $schema['cache'];
800
  $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.';
801
  $schema['cache_page'] = $schema['cache'];
802
  $schema['cache_page']['description'] = 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.';
803
  $schema['cache_menu'] = $schema['cache'];
804
  $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.';
805
  $schema['cache_path'] = $schema['cache'];
806
  $schema['cache_path']['description'] = 'Cache table for path alias lookup.';
807

    
808
  $schema['date_format_type'] = array(
809
    'description' => 'Stores configured date format types.',
810
    'fields' => array(
811
      'type' => array(
812
        'description' => 'The date format type, e.g. medium.',
813
        'type' => 'varchar',
814
        'length' => 64,
815
        'not null' => TRUE,
816
      ),
817
      'title' => array(
818
        'description' => 'The human readable name of the format type.',
819
        'type' => 'varchar',
820
        'length' => 255,
821
        'not null' => TRUE,
822
      ),
823
      'locked' => array(
824
        'description' => 'Whether or not this is a system provided format.',
825
        'type' => 'int',
826
        'size' => 'tiny',
827
        'default' => 0,
828
        'not null' => TRUE,
829
      ),
830
    ),
831
    'primary key' => array('type'),
832
    'indexes' => array(
833
      'title' => array('title'),
834
    ),
835
  );
836

    
837
  // This table's name is plural as some versions of MySQL can't create a
838
  // table named 'date_format'.
839
  $schema['date_formats'] = array(
840
    'description' => 'Stores configured date formats.',
841
    'fields' => array(
842
      'dfid' => array(
843
        'description' => 'The date format identifier.',
844
        'type' => 'serial',
845
        'not null' => TRUE,
846
        'unsigned' => TRUE,
847
      ),
848
      'format' => array(
849
        'description' => 'The date format string.',
850
        'type' => 'varchar',
851
        'length' => 100,
852
        'not null' => TRUE,
853
        'binary' => TRUE,
854
      ),
855
      'type' => array(
856
        'description' => 'The date format type, e.g. medium.',
857
        'type' => 'varchar',
858
        'length' => 64,
859
        'not null' => TRUE,
860
      ),
861
      'locked' => array(
862
        'description' => 'Whether or not this format can be modified.',
863
        'type' => 'int',
864
        'size' => 'tiny',
865
        'default' => 0,
866
        'not null' => TRUE,
867
      ),
868
    ),
869
    'primary key' => array('dfid'),
870
    'unique keys' => array('formats' => array('format', 'type')),
871
  );
872

    
873
  $schema['date_format_locale'] = array(
874
    'description' => 'Stores configured date formats for each locale.',
875
    'fields' => array(
876
      'format' => array(
877
        'description' => 'The date format string.',
878
        'type' => 'varchar',
879
        'length' => 100,
880
        'not null' => TRUE,
881
        'binary' => TRUE,
882
      ),
883
      'type' => array(
884
        'description' => 'The date format type, e.g. medium.',
885
        'type' => 'varchar',
886
        'length' => 64,
887
        'not null' => TRUE,
888
      ),
889
      'language' => array(
890
        'description' => 'A {languages}.language for this format to be used with.',
891
        'type' => 'varchar',
892
        'length' => 12,
893
        'not null' => TRUE,
894
      ),
895
    ),
896
    'primary key' => array('type', 'language'),
897
  );
898

    
899
  $schema['file_managed'] = array(
900
    'description' => 'Stores information for uploaded files.',
901
    'fields' => array(
902
      'fid' => array(
903
        'description' => 'File ID.',
904
        'type' => 'serial',
905
        'unsigned' => TRUE,
906
        'not null' => TRUE,
907
      ),
908
      'uid' => array(
909
        'description' => 'The {users}.uid of the user who is associated with the file.',
910
        'type' => 'int',
911
        'unsigned' => TRUE,
912
        'not null' => TRUE,
913
        'default' => 0,
914
      ),
915
      'filename' => array(
916
        '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.',
917
        'type' => 'varchar',
918
        'length' => 255,
919
        'not null' => TRUE,
920
        'default' => '',
921
      ),
922
      'uri' => array(
923
        'description' => 'The URI to access the file (either local or remote).',
924
        'type' => 'varchar',
925
        'length' => 255,
926
        'not null' => TRUE,
927
        'default' => '',
928
        'binary' => TRUE,
929
      ),
930
      'filemime' => array(
931
        'description' => "The file's MIME type.",
932
        'type' => 'varchar',
933
        'length' => 255,
934
        'not null' => TRUE,
935
        'default' => '',
936
      ),
937
      'filesize' => array(
938
        'description' => 'The size of the file in bytes.',
939
        'type' => 'int',
940
        'size' => 'big',
941
        'unsigned' => TRUE,
942
        'not null' => TRUE,
943
        'default' => 0,
944
      ),
945
      'status' => array(
946
        '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.',
947
        'type' => 'int',
948
        'not null' => TRUE,
949
        'default' => 0,
950
        'size' => 'tiny',
951
      ),
952
      'timestamp' => array(
953
        'description' => 'UNIX timestamp for when the file was added.',
954
        'type' => 'int',
955
        'unsigned' => TRUE,
956
        'not null' => TRUE,
957
        'default' => 0,
958
      ),
959
    ),
960
    'indexes' => array(
961
      'uid' => array('uid'),
962
      'status' => array('status'),
963
      'timestamp' => array('timestamp'),
964
    ),
965
    'unique keys' => array(
966
      'uri' => array('uri'),
967
    ),
968
    'primary key' => array('fid'),
969
    'foreign keys' => array(
970
      'file_owner' => array(
971
        'table' => 'users',
972
        'columns' => array('uid' => 'uid'),
973
      ),
974
    ),
975
  );
976

    
977
  $schema['file_usage'] = array(
978
    'description' => 'Track where a file is used.',
979
    'fields' => array(
980
      'fid' => array(
981
        'description' => 'File ID.',
982
        'type' => 'int',
983
        'unsigned' => TRUE,
984
        'not null' => TRUE,
985
      ),
986
      'module' => array(
987
        'description' => 'The name of the module that is using the file.',
988
        'type' => 'varchar',
989
        'length' => 255,
990
        'not null' => TRUE,
991
        'default' => '',
992
      ),
993
      'type' => array(
994
        'description' => 'The name of the object type in which the file is used.',
995
        'type' => 'varchar',
996
        'length' => 64,
997
        'not null' => TRUE,
998
        'default' => '',
999
      ),
1000
      'id' => array(
1001
        'description' => 'The primary key of the object using the file.',
1002
        'type' => 'int',
1003
        'unsigned' => TRUE,
1004
        'not null' => TRUE,
1005
        'default' => 0,
1006
      ),
1007
      'count' => array(
1008
        'description' => 'The number of times this file is used by this object.',
1009
        'type' => 'int',
1010
        'unsigned' => TRUE,
1011
        'not null' => TRUE,
1012
        'default' => 0,
1013
      ),
1014
    ),
1015
    'primary key' => array('fid', 'type', 'id', 'module'),
1016
    'indexes' => array(
1017
      'type_id' => array('type', 'id'),
1018
      'fid_count' => array('fid', 'count'),
1019
      'fid_module' => array('fid', 'module'),
1020
    ),
1021
  );
1022

    
1023
  $schema['flood'] = array(
1024
    'description' => 'Flood controls the threshold of events, such as the number of contact attempts.',
1025
    'fields' => array(
1026
      'fid' => array(
1027
        'description' => 'Unique flood event ID.',
1028
        'type' => 'serial',
1029
        'not null' => TRUE,
1030
      ),
1031
      'event' => array(
1032
        'description' => 'Name of event (e.g. contact).',
1033
        'type' => 'varchar',
1034
        'length' => 64,
1035
        'not null' => TRUE,
1036
        'default' => '',
1037
      ),
1038
      'identifier' => array(
1039
        'description' => 'Identifier of the visitor, such as an IP address or hostname.',
1040
        'type' => 'varchar',
1041
        'length' => 128,
1042
        'not null' => TRUE,
1043
        'default' => '',
1044
      ),
1045
      'timestamp' => array(
1046
        'description' => 'Timestamp of the event.',
1047
        'type' => 'int',
1048
        'not null' => TRUE,
1049
        'default' => 0,
1050
      ),
1051
      'expiration' => array(
1052
        'description' => 'Expiration timestamp. Expired events are purged on cron run.',
1053
        'type' => 'int',
1054
        'not null' => TRUE,
1055
        'default' => 0,
1056
      ),
1057
    ),
1058
    'primary key' => array('fid'),
1059
    'indexes' => array(
1060
      'allow' => array('event', 'identifier', 'timestamp'),
1061
      'purge' => array('expiration'),
1062
    ),
1063
  );
1064

    
1065
  $schema['menu_router'] = array(
1066
    'description' => 'Maps paths to various callbacks (access, page and title)',
1067
    'fields' => array(
1068
      'path' => array(
1069
        'description' => 'Primary Key: the Drupal path this entry describes',
1070
        'type' => 'varchar',
1071
        'length' => 255,
1072
        'not null' => TRUE,
1073
        'default' => '',
1074
      ),
1075
      'load_functions' => array(
1076
        '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.',
1077
        'type' => 'blob',
1078
        'not null' => TRUE,
1079
      ),
1080
      'to_arg_functions' => array(
1081
        '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.',
1082
        'type' => 'blob',
1083
        'not null' => TRUE,
1084
      ),
1085
      'access_callback' => array(
1086
        'description' => 'The callback which determines the access to this router path. Defaults to user_access.',
1087
        'type' => 'varchar',
1088
        'length' => 255,
1089
        'not null' => TRUE,
1090
        'default' => '',
1091
      ),
1092
      'access_arguments' => array(
1093
        'description' => 'A serialized array of arguments for the access callback.',
1094
        'type' => 'blob',
1095
        'not null' => FALSE,
1096
      ),
1097
      'page_callback' => array(
1098
        'description' => 'The name of the function that renders the page.',
1099
        'type' => 'varchar',
1100
        'length' => 255,
1101
        'not null' => TRUE,
1102
        'default' => '',
1103
      ),
1104
      'page_arguments' => array(
1105
        'description' => 'A serialized array of arguments for the page callback.',
1106
        'type' => 'blob',
1107
        'not null' => FALSE,
1108
      ),
1109
      'delivery_callback' => array(
1110
        'description' => 'The name of the function that sends the result of the page_callback function to the browser.',
1111
        'type' => 'varchar',
1112
        'length' => 255,
1113
        'not null' => TRUE,
1114
        'default' => '',
1115
      ),
1116
      'fit' => array(
1117
        'description' => 'A numeric representation of how specific the path is.',
1118
        'type' => 'int',
1119
        'not null' => TRUE,
1120
        'default' => 0,
1121
      ),
1122
      'number_parts' => array(
1123
        'description' => 'Number of parts in this router path.',
1124
        'type' => 'int',
1125
        'not null' => TRUE,
1126
        'default' => 0,
1127
        'size' => 'small',
1128
      ),
1129
      'context' => array(
1130
        'description' => 'Only for local tasks (tabs) - the context of a local task to control its placement.',
1131
        'type' => 'int',
1132
        'not null' => TRUE,
1133
        'default' => 0,
1134
      ),
1135
      'tab_parent' => array(
1136
        'description' => 'Only for local tasks (tabs) - the router path of the parent page (which may also be a local task).',
1137
        'type' => 'varchar',
1138
        'length' => 255,
1139
        'not null' => TRUE,
1140
        'default' => '',
1141
      ),
1142
      'tab_root' => array(
1143
        '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.',
1144
        'type' => 'varchar',
1145
        'length' => 255,
1146
        'not null' => TRUE,
1147
        'default' => '',
1148
      ),
1149
      'title' => array(
1150
        'description' => 'The title for the current page, or the title for the tab if this is a local task.',
1151
        'type' => 'varchar',
1152
        'length' => 255,
1153
        'not null' => TRUE,
1154
        'default' => '',
1155
      ),
1156
      'title_callback' => array(
1157
        'description' => 'A function which will alter the title. Defaults to t()',
1158
        'type' => 'varchar',
1159
        'length' => 255,
1160
        'not null' => TRUE,
1161
        'default' => '',
1162
      ),
1163
      'title_arguments' => array(
1164
        '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.',
1165
        'type' => 'varchar',
1166
        'length' => 255,
1167
        'not null' => TRUE,
1168
        'default' => '',
1169
      ),
1170
      'theme_callback' => array(
1171
        '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.',
1172
        'type' => 'varchar',
1173
        'length' => 255,
1174
        'not null' => TRUE,
1175
        'default' => '',
1176
      ),
1177
      'theme_arguments' => array(
1178
        'description' => 'A serialized array of arguments for the theme callback.',
1179
        'type' => 'varchar',
1180
        'length' => 255,
1181
        'not null' => TRUE,
1182
        'default' => '',
1183
      ),
1184
      'type' => array(
1185
        'description' => 'Numeric representation of the type of the menu item, like MENU_LOCAL_TASK.',
1186
        'type' => 'int',
1187
        'not null' => TRUE,
1188
        'default' => 0,
1189
      ),
1190
      'description' => array(
1191
        'description' => 'A description of this item.',
1192
        'type' => 'text',
1193
        'not null' => TRUE,
1194
      ),
1195
      'position' => array(
1196
        'description' => 'The position of the block (left or right) on the system administration page for this item.',
1197
        'type' => 'varchar',
1198
        'length' => 255,
1199
        'not null' => TRUE,
1200
        'default' => '',
1201
      ),
1202
      'weight' => array(
1203
        'description' => 'Weight of the element. Lighter weights are higher up, heavier weights go down.',
1204
        'type' => 'int',
1205
        'not null' => TRUE,
1206
        'default' => 0,
1207
      ),
1208
      'include_file' => array(
1209
        'description' => 'The file to include for this element, usually the page callback function lives in this file.',
1210
        'type' => 'text',
1211
        'size' => 'medium',
1212
      ),
1213
    ),
1214
    'indexes' => array(
1215
      'fit' => array('fit'),
1216
      'tab_parent' => array(array('tab_parent', 64), 'weight', 'title'),
1217
      'tab_root_weight_title' => array(array('tab_root', 64), 'weight', 'title'),
1218
    ),
1219
    'primary key' => array('path'),
1220
  );
1221

    
1222
  $schema['menu_links'] = array(
1223
    'description' => 'Contains the individual links within a menu.',
1224
    'fields' => array(
1225
     'menu_name' => array(
1226
        'description' => "The menu name. All links with the same menu name (such as 'navigation') are part of the same menu.",
1227
        'type' => 'varchar',
1228
        'length' => 32,
1229
        'not null' => TRUE,
1230
        'default' => '',
1231
      ),
1232
      'mlid' => array(
1233
        'description' => 'The menu link ID (mlid) is the integer primary key.',
1234
        'type' => 'serial',
1235
        'unsigned' => TRUE,
1236
        'not null' => TRUE,
1237
      ),
1238
      'plid' => array(
1239
        '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.',
1240
        'type' => 'int',
1241
        'unsigned' => TRUE,
1242
        'not null' => TRUE,
1243
        'default' => 0,
1244
      ),
1245
      'link_path' => array(
1246
        'description' => 'The Drupal path or external path this link points to.',
1247
        'type' => 'varchar',
1248
        'length' => 255,
1249
        'not null' => TRUE,
1250
        'default' => '',
1251
      ),
1252
      'router_path' => array(
1253
        'description' => 'For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.',
1254
        'type' => 'varchar',
1255
        'length' => 255,
1256
        'not null' => TRUE,
1257
        'default' => '',
1258
      ),
1259
      'link_title' => array(
1260
      'description' => 'The text displayed for the link, which may be modified by a title callback stored in {menu_router}.',
1261
        'type' => 'varchar',
1262
        'length' => 255,
1263
        'not null' => TRUE,
1264
        'default' => '',
1265
        'translatable' => TRUE,
1266
      ),
1267
      'options' => array(
1268
        'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.',
1269
        'type' => 'blob',
1270
        'not null' => FALSE,
1271
        'translatable' => TRUE,
1272
      ),
1273
      'module' => array(
1274
        'description' => 'The name of the module that generated this link.',
1275
        'type' => 'varchar',
1276
        'length' => 255,
1277
        'not null' => TRUE,
1278
        'default' => 'system',
1279
      ),
1280
      'hidden' => array(
1281
        '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)',
1282
        'type' => 'int',
1283
        'not null' => TRUE,
1284
        'default' => 0,
1285
        'size' => 'small',
1286
      ),
1287
      'external' => array(
1288
        'description' => 'A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).',
1289
        'type' => 'int',
1290
        'not null' => TRUE,
1291
        'default' => 0,
1292
        'size' => 'small',
1293
      ),
1294
      'has_children' => array(
1295
        'description' => 'Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).',
1296
        'type' => 'int',
1297
        'not null' => TRUE,
1298
        'default' => 0,
1299
        'size' => 'small',
1300
      ),
1301
      'expanded' => array(
1302
        '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)',
1303
        'type' => 'int',
1304
        'not null' => TRUE,
1305
        'default' => 0,
1306
        'size' => 'small',
1307
      ),
1308
      'weight' => array(
1309
        'description' => 'Link weight among links in the same menu at the same depth.',
1310
        'type' => 'int',
1311
        'not null' => TRUE,
1312
        'default' => 0,
1313
      ),
1314
      'depth' => array(
1315
        'description' => 'The depth relative to the top level. A link with plid == 0 will have depth == 1.',
1316
        'type' => 'int',
1317
        'not null' => TRUE,
1318
        'default' => 0,
1319
        'size' => 'small',
1320
      ),
1321
      'customized' => array(
1322
        'description' => 'A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).',
1323
        'type' => 'int',
1324
        'not null' => TRUE,
1325
        'default' => 0,
1326
        'size' => 'small',
1327
      ),
1328
      'p1' => array(
1329
        '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.',
1330
        'type' => 'int',
1331
        'unsigned' => TRUE,
1332
        'not null' => TRUE,
1333
        'default' => 0,
1334
      ),
1335
      'p2' => array(
1336
        'description' => 'The second mlid in the materialized path. See p1.',
1337
        'type' => 'int',
1338
        'unsigned' => TRUE,
1339
        'not null' => TRUE,
1340
        'default' => 0,
1341
      ),
1342
      'p3' => array(
1343
        'description' => 'The third mlid in the materialized path. See p1.',
1344
        'type' => 'int',
1345
        'unsigned' => TRUE,
1346
        'not null' => TRUE,
1347
        'default' => 0,
1348
      ),
1349
      'p4' => array(
1350
        'description' => 'The fourth mlid in the materialized path. See p1.',
1351
        'type' => 'int',
1352
        'unsigned' => TRUE,
1353
        'not null' => TRUE,
1354
        'default' => 0,
1355
      ),
1356
      'p5' => array(
1357
        'description' => 'The fifth mlid in the materialized path. See p1.',
1358
        'type' => 'int',
1359
        'unsigned' => TRUE,
1360
        'not null' => TRUE,
1361
        'default' => 0,
1362
      ),
1363
      'p6' => array(
1364
        'description' => 'The sixth mlid in the materialized path. See p1.',
1365
        'type' => 'int',
1366
        'unsigned' => TRUE,
1367
        'not null' => TRUE,
1368
        'default' => 0,
1369
      ),
1370
      'p7' => array(
1371
        'description' => 'The seventh mlid in the materialized path. See p1.',
1372
        'type' => 'int',
1373
        'unsigned' => TRUE,
1374
        'not null' => TRUE,
1375
        'default' => 0,
1376
      ),
1377
      'p8' => array(
1378
        'description' => 'The eighth mlid in the materialized path. See p1.',
1379
        'type' => 'int',
1380
        'unsigned' => TRUE,
1381
        'not null' => TRUE,
1382
        'default' => 0,
1383
      ),
1384
      'p9' => array(
1385
        'description' => 'The ninth mlid in the materialized path. See p1.',
1386
        'type' => 'int',
1387
        'unsigned' => TRUE,
1388
        'not null' => TRUE,
1389
        'default' => 0,
1390
      ),
1391
      'updated' => array(
1392
        'description' => 'Flag that indicates that this link was generated during the update from Drupal 5.',
1393
        'type' => 'int',
1394
        'not null' => TRUE,
1395
        'default' => 0,
1396
        'size' => 'small',
1397
      ),
1398
    ),
1399
    'indexes' => array(
1400
      'path_menu' => array(array('link_path', 128), 'menu_name'),
1401
      'menu_plid_expand_child' => array('menu_name', 'plid', 'expanded', 'has_children'),
1402
      'menu_parents' => array('menu_name', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9'),
1403
      'router_path' => array(array('router_path', 128)),
1404
    ),
1405
    'primary key' => array('mlid'),
1406
  );
1407

    
1408
  $schema['queue'] = array(
1409
    'description' => 'Stores items in queues.',
1410
    'fields' => array(
1411
      'item_id' => array(
1412
        'type' => 'serial',
1413
        'unsigned' => TRUE,
1414
        'not null' => TRUE,
1415
        'description' => 'Primary Key: Unique item ID.',
1416
      ),
1417
      'name' => array(
1418
        'type' => 'varchar',
1419
        'length' => 255,
1420
        'not null' => TRUE,
1421
        'default' => '',
1422
        'description' => 'The queue name.',
1423
      ),
1424
      'data' => array(
1425
        'type' => 'blob',
1426
        'not null' => FALSE,
1427
        'size' => 'big',
1428
        'serialize' => TRUE,
1429
        'description' => 'The arbitrary data for the item.',
1430
      ),
1431
      'expire' => array(
1432
        'type' => 'int',
1433
        'not null' => TRUE,
1434
        'default' => 0,
1435
        'description' => 'Timestamp when the claim lease expires on the item.',
1436
      ),
1437
      'created' => array(
1438
        'type' => 'int',
1439
        'not null' => TRUE,
1440
        'default' => 0,
1441
        'description' => 'Timestamp when the item was created.',
1442
      ),
1443
    ),
1444
    'primary key' => array('item_id'),
1445
    'indexes' => array(
1446
      'name_created' => array('name', 'created'),
1447
      'expire' => array('expire'),
1448
    ),
1449
  );
1450

    
1451
  $schema['registry'] = array(
1452
    'description' => "Each record is a function, class, or interface name and the file it is in.",
1453
    'fields' => array(
1454
      'name'   => array(
1455
        'description' => 'The name of the function, class, or interface.',
1456
        'type' => 'varchar',
1457
        'length' => 255,
1458
        'not null' => TRUE,
1459
        'default' => '',
1460
      ),
1461
      'type'   => array(
1462
        'description' => 'Either function or class or interface.',
1463
        'type' => 'varchar',
1464
        'length' => 9,
1465
        'not null' => TRUE,
1466
        'default' => '',
1467
      ),
1468
      'filename'   => array(
1469
        'description' => 'Name of the file.',
1470
        'type' => 'varchar',
1471
        'length' => 255,
1472
        'not null' => TRUE,
1473
      ),
1474
      'module' => array(
1475
        'description' => 'Name of the module the file belongs to.',
1476
        'type' => 'varchar',
1477
        'length' => 255,
1478
        'not null' => TRUE,
1479
        'default' => ''
1480
      ),
1481
      'weight' => array(
1482
        'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
1483
        'type' => 'int',
1484
        'not null' => TRUE,
1485
        'default' => 0,
1486
      ),
1487
    ),
1488
    'primary key' => array('name', 'type'),
1489
    'indexes' => array(
1490
      'hook' => array('type', 'weight', 'module'),
1491
    ),
1492
  );
1493

    
1494
  $schema['registry_file'] = array(
1495
    'description' => "Files parsed to build the registry.",
1496
    'fields' => array(
1497
      'filename'   => array(
1498
        'description' => 'Path to the file.',
1499
        'type' => 'varchar',
1500
        'length' => 255,
1501
        'not null' => TRUE,
1502
      ),
1503
      'hash'  => array(
1504
        'description' => "sha-256 hash of the file's contents when last parsed.",
1505
        'type' => 'varchar',
1506
        'length' => 64,
1507
        'not null' => TRUE,
1508
      ),
1509
    ),
1510
    'primary key' => array('filename'),
1511
  );
1512

    
1513
  $schema['semaphore'] = array(
1514
    'description' => 'Table for holding semaphores, locks, flags, etc. that cannot be stored as Drupal variables since they must not be cached.',
1515
    'fields' => array(
1516
      'name' => array(
1517
        'description' => 'Primary Key: Unique name.',
1518
        'type' => 'varchar',
1519
        'length' => 255,
1520
        'not null' => TRUE,
1521
        'default' => ''
1522
      ),
1523
      'value' => array(
1524
        'description' => 'A value for the semaphore.',
1525
        'type' => 'varchar',
1526
        'length' => 255,
1527
        'not null' => TRUE,
1528
        'default' => ''
1529
      ),
1530
      'expire' => array(
1531
        'description' => 'A Unix timestamp with microseconds indicating when the semaphore should expire.',
1532
        'type' => 'float',
1533
        'size' => 'big',
1534
        'not null' => TRUE
1535
      ),
1536
    ),
1537
    'indexes' => array(
1538
      'value' => array('value'),
1539
      'expire' => array('expire'),
1540
    ),
1541
    'primary key' => array('name'),
1542
  );
1543

    
1544
  $schema['sequences'] = array(
1545
    'description' => 'Stores IDs.',
1546
    'fields' => array(
1547
      'value' => array(
1548
        'description' => 'The value of the sequence.',
1549
        'type' => 'serial',
1550
        'unsigned' => TRUE,
1551
        'not null' => TRUE,
1552
      ),
1553
     ),
1554
    'primary key' => array('value'),
1555
  );
1556

    
1557
  $schema['sessions'] = array(
1558
    'description' => "Drupal's session handlers read and write into the sessions table. Each record represents a user session, either anonymous or authenticated.",
1559
    'fields' => array(
1560
      'uid' => array(
1561
        'description' => 'The {users}.uid corresponding to a session, or 0 for anonymous user.',
1562
        'type' => 'int',
1563
        'unsigned' => TRUE,
1564
        'not null' => TRUE,
1565
      ),
1566
      'sid' => array(
1567
        'description' => "A session ID. The value is generated by Drupal's session handlers.",
1568
        'type' => 'varchar',
1569
        'length' => 128,
1570
        'not null' => TRUE,
1571
      ),
1572
      'ssid' => array(
1573
        'description' => "Secure session ID. The value is generated by Drupal's session handlers.",
1574
        'type' => 'varchar',
1575
        'length' => 128,
1576
        'not null' => TRUE,
1577
        'default' => '',
1578
      ),
1579
      'hostname' => array(
1580
        'description' => 'The IP address that last used this session ID (sid).',
1581
        'type' => 'varchar',
1582
        'length' => 128,
1583
        'not null' => TRUE,
1584
        'default' => '',
1585
      ),
1586
      'timestamp' => array(
1587
        'description' => 'The Unix timestamp when this session last requested a page. Old records are purged by PHP automatically.',
1588
        'type' => 'int',
1589
        'not null' => TRUE,
1590
        'default' => 0,
1591
      ),
1592
      'cache' => array(
1593
        'description' => "The time of this user's last post. This is used when the site has specified a minimum_cache_lifetime. See cache_get().",
1594
        'type' => 'int',
1595
        'not null' => TRUE,
1596
        'default' => 0,
1597
      ),
1598
      'session' => array(
1599
        '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.',
1600
        'type' => 'blob',
1601
        'not null' => FALSE,
1602
        'size' => 'big',
1603
      ),
1604
    ),
1605
    'primary key' => array(
1606
      'sid',
1607
      'ssid',
1608
    ),
1609
    'indexes' => array(
1610
      'timestamp' => array('timestamp'),
1611
      'uid' => array('uid'),
1612
      'ssid' => array('ssid'),
1613
    ),
1614
    'foreign keys' => array(
1615
      'session_user' => array(
1616
        'table' => 'users',
1617
        'columns' => array('uid' => 'uid'),
1618
      ),
1619
    ),
1620
  );
1621

    
1622
  $schema['system'] = array(
1623
    'description' => "A list of all modules, themes, and theme engines that are or have been installed in Drupal's file system.",
1624
    'fields' => array(
1625
      'filename' => array(
1626
        'description' => 'The path of the primary file for this item, relative to the Drupal root; e.g. modules/node/node.module.',
1627
        'type' => 'varchar',
1628
        'length' => 255,
1629
        'not null' => TRUE,
1630
        'default' => '',
1631
      ),
1632
      'name' => array(
1633
        'description' => 'The name of the item; e.g. node.',
1634
        'type' => 'varchar',
1635
        'length' => 255,
1636
        'not null' => TRUE,
1637
        'default' => '',
1638
      ),
1639
      'type' => array(
1640
        'description' => 'The type of the item, either module, theme, or theme_engine.',
1641
        'type' => 'varchar',
1642
        'length' => 12,
1643
        'not null' => TRUE,
1644
        'default' => '',
1645
      ),
1646
      'owner' => array(
1647
        'description' => "A theme's 'parent' . Can be either a theme or an engine.",
1648
        'type' => 'varchar',
1649
        'length' => 255,
1650
        'not null' => TRUE,
1651
        'default' => '',
1652
      ),
1653
      'status' => array(
1654
        'description' => 'Boolean indicating whether or not this item is enabled.',
1655
        'type' => 'int',
1656
        'not null' => TRUE,
1657
        'default' => 0,
1658
      ),
1659
      'bootstrap' => array(
1660
        'description' => "Boolean indicating whether this module is loaded during Drupal's early bootstrapping phase (e.g. even before the page cache is consulted).",
1661
        'type' => 'int',
1662
        'not null' => TRUE,
1663
        'default' => 0,
1664
      ),
1665
      'schema_version' => array(
1666
        '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.",
1667
        'type' => 'int',
1668
        'not null' => TRUE,
1669
        'default' => -1,
1670
        'size' => 'small',
1671
      ),
1672
      'weight' => array(
1673
        'description' => "The order in which this module's hooks should be invoked relative to other modules. Equal-weighted modules are ordered by name.",
1674
        'type' => 'int',
1675
        'not null' => TRUE,
1676
        'default' => 0,
1677
      ),
1678
      'info' => array(
1679
        'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.",
1680
        'type' => 'blob',
1681
        'not null' => FALSE,
1682
      ),
1683
    ),
1684
    'primary key' => array('filename'),
1685
    'indexes' => array(
1686
      'system_list' => array('status', 'bootstrap', 'type', 'weight', 'name'),
1687
      'type_name' => array('type', 'name'),
1688
    ),
1689
  );
1690

    
1691
  $schema['url_alias'] = array(
1692
    'description' => 'A list of URL aliases for Drupal paths; a user may visit either the source or destination path.',
1693
    'fields' => array(
1694
      'pid' => array(
1695
        'description' => 'A unique path alias identifier.',
1696
        'type' => 'serial',
1697
        'unsigned' => TRUE,
1698
        'not null' => TRUE,
1699
      ),
1700
      'source' => array(
1701
        'description' => 'The Drupal path this alias is for; e.g. node/12.',
1702
        'type' => 'varchar',
1703
        'length' => 255,
1704
        'not null' => TRUE,
1705
        'default' => '',
1706
      ),
1707
      'alias' => array(
1708
        'description' => 'The alias for this path; e.g. title-of-the-story.',
1709
        'type' => 'varchar',
1710
        'length' => 255,
1711
        'not null' => TRUE,
1712
        'default' => '',
1713
      ),
1714
      'language' => array(
1715
        '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.",
1716
        'type' => 'varchar',
1717
        'length' => 12,
1718
        'not null' => TRUE,
1719
        'default' => '',
1720
      ),
1721
    ),
1722
    'primary key' => array('pid'),
1723
    'indexes' => array(
1724
      'alias_language_pid' => array('alias', 'language', 'pid'),
1725
      'source_language_pid' => array('source', 'language', 'pid'),
1726
    ),
1727
  );
1728

    
1729
  return $schema;
1730
}
1731

    
1732
/**
1733
 * The cache schema corresponding to system_update_7054.
1734
 *
1735
 * Drupal 7 adds several new cache tables. Since they all have identical schema
1736
 * this helper function allows them to re-use the same definition, without
1737
 * relying on system_schema(), which may change with future updates.
1738
 */
1739
function system_schema_cache_7054() {
1740
  return array(
1741
    'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
1742
    'fields' => array(
1743
      'cid' => array(
1744
        'description' => 'Primary Key: Unique cache ID.',
1745
        'type' => 'varchar',
1746
        'length' => 255,
1747
        'not null' => TRUE,
1748
        'default' => '',
1749
      ),
1750
      'data' => array(
1751
        'description' => 'A collection of data to cache.',
1752
        'type' => 'blob',
1753
        'not null' => FALSE,
1754
        'size' => 'big',
1755
      ),
1756
      'expire' => array(
1757
        'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
1758
        'type' => 'int',
1759
        'not null' => TRUE,
1760
        'default' => 0,
1761
      ),
1762
      'created' => array(
1763
        'description' => 'A Unix timestamp indicating when the cache entry was created.',
1764
        'type' => 'int',
1765
        'not null' => TRUE,
1766
        'default' => 0,
1767
      ),
1768
      'serialized' => array(
1769
        'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
1770
        'type' => 'int',
1771
        'size' => 'small',
1772
        'not null' => TRUE,
1773
        'default' => 0,
1774
      ),
1775
    ),
1776
    'indexes' => array(
1777
      'expire' => array('expire'),
1778
    ),
1779
    'primary key' => array('cid'),
1780
  );
1781
}
1782

    
1783

    
1784
// Updates for core.
1785

    
1786
function system_update_last_removed() {
1787
  return 6055;
1788
}
1789

    
1790
/**
1791
 * Implements hook_update_dependencies().
1792
 */
1793
function system_update_dependencies() {
1794
  // system_update_7053() queries the {block} table, so it must run after
1795
  // block_update_7002(), which creates that table.
1796
  $dependencies['system'][7053] = array(
1797
    'block' => 7002,
1798
  );
1799

    
1800
  // system_update_7061() queries the {node_revision} table, so it must run
1801
  // after node_update_7001(), which renames the {node_revisions} table.
1802
  $dependencies['system'][7061] = array(
1803
    'node' => 7001,
1804
  );
1805

    
1806
  // system_update_7067() migrates role permissions and therefore must run
1807
  // after the {role} and {role_permission} tables are properly set up, which
1808
  // happens in user_update_7007().
1809
  $dependencies['system'][7067] = array(
1810
    'user' => 7007,
1811
  );
1812

    
1813
  return $dependencies;
1814
}
1815

    
1816
/**
1817
 * @defgroup updates-6.x-to-7.x Updates from 6.x to 7.x
1818
 * @{
1819
 * Update functions from 6.x to 7.x.
1820
 */
1821

    
1822
/**
1823
 * Rename blog and forum permissions to be consistent with other content types.
1824
 */
1825
function system_update_7000() {
1826
  $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
1827
  foreach ($result as $role) {
1828
    $renamed_permission = $role->perm;
1829
    $renamed_permission = preg_replace('/(?<=^|,\ )create\ blog\ entries(?=,|$)/', 'create blog content', $renamed_permission);
1830
    $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ blog\ entries(?=,|$)/', 'edit own blog content', $renamed_permission);
1831
    $renamed_permission = preg_replace('/(?<=^|,\ )edit\ any\ blog\ entry(?=,|$)/', 'edit any blog content', $renamed_permission);
1832
    $renamed_permission = preg_replace('/(?<=^|,\ )delete\ own\ blog\ entries(?=,|$)/', 'delete own blog content', $renamed_permission);
1833
    $renamed_permission = preg_replace('/(?<=^|,\ )delete\ any\ blog\ entry(?=,|$)/', 'delete any blog content', $renamed_permission);
1834

    
1835
    $renamed_permission = preg_replace('/(?<=^|,\ )create\ forum\ topics(?=,|$)/', 'create forum content', $renamed_permission);
1836
    $renamed_permission = preg_replace('/(?<=^|,\ )delete\ any\ forum\ topic(?=,|$)/', 'delete any forum content', $renamed_permission);
1837
    $renamed_permission = preg_replace('/(?<=^|,\ )delete\ own\ forum\ topics(?=,|$)/', 'delete own forum content', $renamed_permission);
1838
    $renamed_permission = preg_replace('/(?<=^|,\ )edit\ any\ forum\ topic(?=,|$)/', 'edit any forum content', $renamed_permission);
1839
    $renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ forum\ topics(?=,|$)/', 'edit own forum content', $renamed_permission);
1840

    
1841
    if ($renamed_permission != $role->perm) {
1842
      db_update('permission')
1843
        ->fields(array('perm' => $renamed_permission))
1844
        ->condition('rid', $role->rid)
1845
        ->execute();
1846
    }
1847
  }
1848
}
1849

    
1850
/**
1851
 * Generate a cron key and save it in the variables table.
1852
 */
1853
function system_update_7001() {
1854
  variable_set('cron_key', drupal_random_key());
1855
}
1856

    
1857
/**
1858
 * Add a table to store blocked IP addresses.
1859
 */
1860
function system_update_7002() {
1861
  $schema['blocked_ips'] = array(
1862
    'description' => 'Stores blocked IP addresses.',
1863
    'fields' => array(
1864
      'iid' => array(
1865
        'description' => 'Primary Key: unique ID for IP addresses.',
1866
        'type' => 'serial',
1867
        'unsigned' => TRUE,
1868
        'not null' => TRUE,
1869
      ),
1870
      'ip' => array(
1871
        'description' => 'IP address',
1872
        'type' => 'varchar',
1873
        'length' => 32,
1874
        'not null' => TRUE,
1875
        'default' => '',
1876
      ),
1877
    ),
1878
    'indexes' => array(
1879
      'blocked_ip' => array('ip'),
1880
    ),
1881
    'primary key' => array('iid'),
1882
  );
1883

    
1884
  db_create_table('blocked_ips', $schema['blocked_ips']);
1885
}
1886

    
1887
/**
1888
 * Update {blocked_ips} with valid IP addresses from {access}.
1889
 */
1890
function system_update_7003() {
1891
  $messages = array();
1892
  $type = 'host';
1893
  $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
1894
    ':status' => 0,
1895
    ':type' => $type,
1896
  ));
1897
  foreach ($result as $blocked) {
1898
    if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) !== FALSE) {
1899
      db_insert('blocked_ips')
1900
        ->fields(array('ip' => $blocked->mask))
1901
        ->execute();
1902
    }
1903
    else {
1904
      $invalid_host = check_plain($blocked->mask);
1905
      $messages[] = t('The host !host is no longer blocked because it is not a valid IP address.', array('!host' => $invalid_host ));
1906
    }
1907
  }
1908
  if (isset($invalid_host)) {
1909
    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');
1910
  }
1911
  // Make sure not to block any IP addresses that were specifically allowed by access rules.
1912
  if (!empty($result)) {
1913
    $result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
1914
      ':status' => 1,
1915
      ':type' => $type,
1916
    ));
1917
    $or = db_condition('or');
1918
    foreach ($result as $allowed) {
1919
      $or->condition('ip', $allowed->mask, 'LIKE');
1920
    }
1921
    if (count($or)) {
1922
      db_delete('blocked_ips')
1923
        ->condition($or)
1924
        ->execute();
1925
    }
1926
  }
1927
}
1928

    
1929
/**
1930
 * Remove hardcoded numeric deltas from all blocks in core.
1931
 */
1932
function system_update_7004(&$sandbox) {
1933
  // Get an array of the renamed block deltas, organized by module.
1934
  $renamed_deltas = array(
1935
    'blog' => array('0' => 'recent'),
1936
    'book' => array('0' => 'navigation'),
1937
    'comment' => array('0' => 'recent'),
1938
    'forum' => array(
1939
      '0' => 'active',
1940
      '1' => 'new',
1941
    ),
1942
    'locale' => array('0' => LANGUAGE_TYPE_INTERFACE),
1943
    'node' => array('0' => 'syndicate'),
1944
    'poll' => array('0' => 'recent'),
1945
    'profile' => array('0' => 'author-information'),
1946
    'search' => array('0' => 'form'),
1947
    'statistics' => array('0' => 'popular'),
1948
    'system' => array('0' => 'powered-by'),
1949
    'user' => array(
1950
      '0' => 'login',
1951
      '1' => 'navigation',
1952
      '2' => 'new',
1953
      '3' => 'online',
1954
    ),
1955
  );
1956

    
1957
  $moved_deltas = array(
1958
    'user' => array('navigation' => 'system'),
1959
  );
1960

    
1961
  // Only run this the first time through the batch update.
1962
  if (!isset($sandbox['progress'])) {
1963
    // Rename forum module's block variables.
1964
    $forum_block_num_0 = variable_get('forum_block_num_0');
1965
    if (isset($forum_block_num_0)) {
1966
      variable_set('forum_block_num_active', $forum_block_num_0);
1967
      variable_del('forum_block_num_0');
1968
    }
1969
    $forum_block_num_1 = variable_get('forum_block_num_1');
1970
    if (isset($forum_block_num_1)) {
1971
      variable_set('forum_block_num_new', $forum_block_num_1);
1972
      variable_del('forum_block_num_1');
1973
    }
1974
  }
1975

    
1976
  update_fix_d7_block_deltas($sandbox, $renamed_deltas, $moved_deltas);
1977

    
1978
}
1979

    
1980
/**
1981
 * Remove throttle columns and variables.
1982
 */
1983
function system_update_7005() {
1984
  db_drop_field('blocks', 'throttle');
1985
  db_drop_field('system', 'throttle');
1986
  variable_del('throttle_user');
1987
  variable_del('throttle_anonymous');
1988
  variable_del('throttle_level');
1989
  variable_del('throttle_probability_limiter');
1990
}
1991

    
1992
/**
1993
 * Convert to new method of storing permissions.
1994
 */
1995
function system_update_7007() {
1996
  // Copy the permissions from the old {permission} table to the new {role_permission} table.
1997
  $messages = array();
1998
  $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
1999
  $query = db_insert('role_permission')->fields(array('rid', 'permission'));
2000
  foreach ($result as $role) {
2001
    foreach (array_unique(explode(', ', $role->perm)) as $perm) {
2002
      $query->values(array(
2003
        'rid' => $role->rid,
2004
        'permission' => $perm,
2005
      ));
2006
    }
2007
    $messages[] = t('Inserted into {role_permission} the permissions for role ID !id', array('!id' => $role->rid));
2008
  }
2009
  $query->execute();
2010
  db_drop_table('permission');
2011

    
2012
  return implode(', ', $messages);
2013
}
2014

    
2015
/**
2016
 * Rename the variable for primary links.
2017
 */
2018
function system_update_7009() {
2019
  $current_primary = variable_get('menu_primary_links_source');
2020
  if (isset($current_primary)) {
2021
    variable_set('menu_main_links_source', $current_primary);
2022
    variable_del('menu_primary_links_source');
2023
  }
2024
}
2025

    
2026
/**
2027
 * Split the 'bypass node access' permission from 'administer nodes'.
2028
 */
2029
function system_update_7011() {
2030
  // Get existing roles that can 'administer nodes'.
2031
  $rids = array();
2032
  $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer nodes'))->fetchCol();
2033
  // None found.
2034
  if (empty($rids)) {
2035
    return;
2036
  }
2037
  $insert = db_insert('role_permission')->fields(array('rid', 'permission'));
2038
  foreach ($rids as $rid) {
2039
    $insert->values(array(
2040
    'rid' => $rid,
2041
    'permission' => 'bypass node access',
2042
    ));
2043
  }
2044
  $insert->execute();
2045
}
2046

    
2047
/**
2048
 * Convert default time zone offset to default time zone name.
2049
 */
2050
function system_update_7013() {
2051
  $timezone = NULL;
2052
  $timezones = system_time_zones();
2053
  // If the contributed Date module set a default time zone name, use this
2054
  // setting as the default time zone.
2055
  if (($timezone_name = variable_get('date_default_timezone_name')) && isset($timezones[$timezone_name])) {
2056
    $timezone = $timezone_name;
2057
  }
2058
  // If the contributed Event module has set a default site time zone, look up
2059
  // the time zone name and use it as the default time zone.
2060
  if (!$timezone && ($timezone_id = variable_get('date_default_timezone_id', 0))) {
2061
    try {
2062
      $timezone_name = db_query('SELECT name FROM {event_timezones} WHERE timezone = :timezone_id', array(':timezone_id' => $timezone_id))->fetchField();
2063
      if (($timezone_name = str_replace(' ', '_', $timezone_name)) && isset($timezones[$timezone_name])) {
2064
        $timezone = $timezone_name;
2065
      }
2066
    }
2067
    catch (PDOException $e) {
2068
      // Ignore error if event_timezones table does not exist or unexpected
2069
      // schema found.
2070
    }
2071
  }
2072

    
2073
  // Check to see if timezone was overriden in update_prepare_d7_bootstrap().
2074
  $offset = variable_get('date_temporary_timezone');
2075
  // If not, use the default.
2076
  if (!isset($offset)) {
2077
    $offset = variable_get('date_default_timezone', 0);
2078
  }
2079

    
2080
  // If the previous default time zone was a non-zero offset, guess the site's
2081
  // intended time zone based on that offset and the server's daylight saving
2082
  // time status.
2083
  if (!$timezone && $offset) {
2084
    $timezone_name = timezone_name_from_abbr('', intval($offset), date('I'));
2085
    if ($timezone_name && isset($timezones[$timezone_name])) {
2086
      $timezone = $timezone_name;
2087
    }
2088
  }
2089
  // Otherwise, the default time zone offset was zero, which is UTC.
2090
  if (!$timezone) {
2091
    $timezone = 'UTC';
2092
  }
2093
  variable_set('date_default_timezone', $timezone);
2094
  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');
2095
  // Remove temporary override.
2096
  variable_del('date_temporary_timezone');
2097
}
2098

    
2099
/**
2100
 * Change the user logout path.
2101
 */
2102
function system_update_7015() {
2103
  db_update('menu_links')
2104
    ->fields(array('link_path' => 'user/logout'))
2105
    ->condition('link_path', 'logout')
2106
    ->execute();
2107
  db_update('menu_links')
2108
    ->fields(array('router_path' => 'user/logout'))
2109
    ->condition('router_path', 'logout')
2110
    ->execute();
2111

    
2112
  db_update('menu_links')
2113
    ->fields(array(
2114
      'menu_name' => 'user-menu',
2115
      'plid' => 0,
2116
    ))
2117
    ->condition(db_or()
2118
      ->condition('link_path', 'user/logout')
2119
      ->condition('router_path', 'user/logout')
2120
    )
2121
    ->condition('module', 'system')
2122
    ->condition('customized', 0)
2123
    ->execute();
2124
}
2125

    
2126
/**
2127
 * Remove custom datatype *_unsigned in PostgreSQL.
2128
 */
2129
function system_update_7016() {
2130
  // Only run these queries if the driver used is pgsql.
2131
  if (db_driver() == 'pgsql') {
2132
    $result = db_query("SELECT c.relname AS table, a.attname AS field,
2133
                        pg_catalog.format_type(a.atttypid, a.atttypmod) AS type
2134
                        FROM pg_catalog.pg_attribute a
2135
                        LEFT JOIN pg_class c ON (c.oid =  a.attrelid)
2136
                        WHERE pg_catalog.pg_table_is_visible(c.oid) AND c.relkind = 'r'
2137
                        AND pg_catalog.format_type(a.atttypid, a.atttypmod) LIKE '%unsigned%'");
2138
    foreach ($result as $row) {
2139
      switch ($row->type) {
2140
        case 'smallint_unsigned':
2141
          $datatype = 'int';
2142
          break;
2143
        case 'int_unsigned':
2144
        case 'bigint_unsigned':
2145
        default:
2146
          $datatype = 'bigint';
2147
          break;
2148
      }
2149
      db_query('ALTER TABLE ' . $row->table . ' ALTER COLUMN "' . $row->field . '" TYPE ' . $datatype);
2150
      db_query('ALTER TABLE ' . $row->table . ' ADD CHECK ("' . $row->field . '" >= 0)');
2151
    }
2152
    db_query('DROP DOMAIN IF EXISTS smallint_unsigned');
2153
    db_query('DROP DOMAIN IF EXISTS int_unsigned');
2154
    db_query('DROP DOMAIN IF EXISTS bigint_unsigned');
2155
  }
2156
}
2157

    
2158
/**
2159
 * Change the theme setting 'toggle_node_info' into a per content type variable.
2160
 */
2161
function system_update_7017() {
2162
  // Get the global theme settings.
2163
  $settings = variable_get('theme_settings', array());
2164
  // Get the settings of the default theme.
2165
  $settings = array_merge($settings, variable_get('theme_' . variable_get('theme_default', 'garland') . '_settings', array()));
2166

    
2167
  $types = _update_7000_node_get_types();
2168
  foreach ($types as $type) {
2169
    if (isset($settings['toggle_node_info_' . $type->type])) {
2170
      variable_set('node_submitted_' . $type->type, $settings['toggle_node_info_' . $type->type]);
2171
    }
2172
  }
2173

    
2174
  // Unset deprecated 'toggle_node_info' theme settings.
2175
  $theme_settings = variable_get('theme_settings', array());
2176
  foreach ($theme_settings as $setting => $value) {
2177
    if (substr($setting, 0, 16) == 'toggle_node_info') {
2178
      unset($theme_settings[$setting]);
2179
    }
2180
  }
2181
  variable_set('theme_settings', $theme_settings);
2182
}
2183

    
2184
/**
2185
 * Shorten the {system}.type column and modify indexes.
2186
 */
2187
function system_update_7018() {
2188
  db_drop_index('system', 'modules');
2189
  db_drop_index('system', 'type_name');
2190
  db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
2191
  db_add_index('system', 'type_name', array('type', 'name'));
2192
}
2193

    
2194
/**
2195
 * Enable field and field_ui modules.
2196
 */
2197
function system_update_7020() {
2198
  $module_list = array('field_sql_storage', 'field', 'field_ui');
2199
  module_enable($module_list, FALSE);
2200
}
2201

    
2202
/**
2203
 * Change the PHP for settings permission.
2204
 */
2205
function system_update_7021() {
2206
  db_update('role_permission')
2207
    ->fields(array('permission' => 'use PHP for settings'))
2208
    ->condition('permission', 'use PHP for block visibility')
2209
    ->execute();
2210
}
2211

    
2212
/**
2213
 * Enable field type modules.
2214
 */
2215
function system_update_7027() {
2216
  $module_list = array('text', 'number', 'list', 'options');
2217
  module_enable($module_list, FALSE);
2218
}
2219

    
2220
/**
2221
 * Add new 'view own unpublished content' permission for authenticated users.
2222
 * Preserves legacy behavior from Drupal 6.x.
2223
 */
2224
function system_update_7029() {
2225
  db_insert('role_permission')
2226
    ->fields(array(
2227
      'rid' => DRUPAL_AUTHENTICATED_RID,
2228
      'permission' => 'view own unpublished content',
2229
    ))
2230
    ->execute();
2231
}
2232

    
2233
/**
2234
* Alter field hostname to identifier in the {flood} table.
2235
 */
2236
function system_update_7032() {
2237
  db_drop_index('flood', 'allow');
2238
  db_change_field('flood', 'hostname', 'identifier', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
2239
  db_add_index('flood', 'allow', array('event', 'identifier', 'timestamp'));
2240
}
2241

    
2242
/**
2243
 * Move CACHE_AGGRESSIVE to CACHE_NORMAL.
2244
 */
2245
function system_update_7033() {
2246
  if (variable_get('cache') == 2) {
2247
    variable_set('cache', 1);
2248
    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.');
2249
  }
2250
}
2251

    
2252
/**
2253
 * Migrate the file path settings and create the new {file_managed} table.
2254
 */
2255
function system_update_7034() {
2256
  $files_directory = variable_get('file_directory_path', NULL);
2257
  if (variable_get('file_downloads', 1) == 1) {
2258
    // Our default is public, so we don't need to set anything.
2259
    if (!empty($files_directory)) {
2260
      variable_set('file_public_path', $files_directory);
2261
    }
2262
  }
2263
  elseif (variable_get('file_downloads', 1) == 2) {
2264
    variable_set('file_default_scheme', 'private');
2265
    if (!empty($files_directory)) {
2266
      variable_set('file_private_path', $files_directory);
2267
    }
2268
  }
2269
  variable_del('file_downloads');
2270

    
2271
  $schema['file_managed'] = array(
2272
    'description' => 'Stores information for uploaded files.',
2273
    'fields' => array(
2274
      'fid' => array(
2275
        'description' => 'File ID.',
2276
        'type' => 'serial',
2277
        'unsigned' => TRUE,
2278
        'not null' => TRUE,
2279
      ),
2280
      'uid' => array(
2281
        'description' => 'The {user}.uid of the user who is associated with the file.',
2282
        'type' => 'int',
2283
        'unsigned' => TRUE,
2284
        'not null' => TRUE,
2285
        'default' => 0,
2286
      ),
2287
      'filename' => array(
2288
        '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.',
2289
        'type' => 'varchar',
2290
        'length' => 255,
2291
        'not null' => TRUE,
2292
        'default' => '',
2293
        'binary' => TRUE,
2294
      ),
2295
      'uri' => array(
2296
        'description' => 'URI of file.',
2297
        'type' => 'varchar',
2298
        'length' => 255,
2299
        'not null' => TRUE,
2300
        'default' => '',
2301
        'binary' => TRUE,
2302
      ),
2303
      'filemime' => array(
2304
        'description' => "The file's MIME type.",
2305
        'type' => 'varchar',
2306
        'length' => 255,
2307
        'not null' => TRUE,
2308
        'default' => '',
2309
      ),
2310
      'filesize' => array(
2311
        'description' => 'The size of the file in bytes.',
2312
        'type' => 'int',
2313
        'unsigned' => TRUE,
2314
        'not null' => TRUE,
2315
        'default' => 0,
2316
      ),
2317
      'status' => array(
2318
        '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.',
2319
        'type' => 'int',
2320
        'not null' => TRUE,
2321
        'default' => 0,
2322
        'size' => 'tiny',
2323
      ),
2324
      'timestamp' => array(
2325
        'description' => 'UNIX timestamp for when the file was added.',
2326
        'type' => 'int',
2327
        'unsigned' => TRUE,
2328
        'not null' => TRUE,
2329
        'default' => 0,
2330
      ),
2331
    ),
2332
    'indexes' => array(
2333
      'uid' => array('uid'),
2334
      'status' => array('status'),
2335
      'timestamp' => array('timestamp'),
2336
    ),
2337
    'unique keys' => array(
2338
      'uri' => array('uri'),
2339
    ),
2340
    'primary key' => array('fid'),
2341
  );
2342

    
2343
  db_create_table('file_managed', $schema['file_managed']);
2344
}
2345

    
2346
/**
2347
 * Split the 'access site in maintenance mode' permission from 'administer site configuration'.
2348
 */
2349
function system_update_7036() {
2350
  // Get existing roles that can 'administer site configuration'.
2351
  $rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer site configuration'))->fetchCol();
2352
  // None found.
2353
  if (empty($rids)) {
2354
    return;
2355
  }
2356
  $insert = db_insert('role_permission')->fields(array('rid', 'permission'));
2357
  foreach ($rids as $rid) {
2358
    $insert->values(array(
2359
      'rid' => $rid,
2360
      'permission' => 'access site in maintenance mode',
2361
    ));
2362
  }
2363
  $insert->execute();
2364
}
2365

    
2366
/**
2367
 * Upgrade the {url_alias} table and create a cache bin for path aliases.
2368
 */
2369
function system_update_7042() {
2370
  // update_fix_d7_requirements() adds 'fake' source and alias columns to
2371
  // allow bootstrap to run without fatal errors. Remove those columns now
2372
  // so that we can rename properly.
2373
  db_drop_field('url_alias', 'source');
2374
  db_drop_field('url_alias', 'alias');
2375

    
2376
  // Drop indexes.
2377
  db_drop_index('url_alias', 'src_language_pid');
2378
  db_drop_unique_key('url_alias', 'dst_language_pid');
2379
  // Rename the fields, and increase their length to 255 characters.
2380
  db_change_field('url_alias', 'src', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
2381
  db_change_field('url_alias', 'dst', 'alias', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
2382
  // Add indexes back. We replace the unique key with an index since it never
2383
  // provided any meaningful unique constraint ('pid' is a primary key).
2384
  db_add_index('url_alias', 'source_language_pid', array('source', 'language', 'pid'));
2385
  db_add_index('url_alias', 'alias_language_pid', array('alias', 'language', 'pid'));
2386

    
2387
  // Now that the URL aliases are correct, we can rebuild the whitelist.
2388
  drupal_path_alias_whitelist_rebuild();
2389
}
2390

    
2391
/**
2392
 * Drop the actions_aid table.
2393
 */
2394
function system_update_7044() {
2395
  // The current value of the increment has been taken into account when
2396
  // creating the sequences table in update_fix_d7_requirements().
2397
  db_drop_table('actions_aid');
2398
}
2399

    
2400
/**
2401
 * Add expiration field to the {flood} table.
2402
 */
2403
function system_update_7045() {
2404
  db_add_field('flood', 'expiration', array('description' => 'Expiration timestamp. Expired events are purged on cron run.', 'type' => 'int', 'not null' => TRUE, 'default' => 0));
2405
  db_add_index('flood', 'purge', array('expiration'));
2406
}
2407

    
2408
/**
2409
 * Switch from the Minnelli theme if it is the default or admin theme.
2410
 */
2411
function system_update_7046() {
2412
  if (variable_get('theme_default') == 'minnelli' || variable_get('admin_theme') == 'minnelli') {
2413
    // Make sure Garland is enabled.
2414
    db_update('system')
2415
      ->fields(array('status' => 1))
2416
      ->condition('type', 'theme')
2417
      ->condition('name', 'garland')
2418
      ->execute();
2419
    if (variable_get('theme_default') != 'garland') {
2420
      // If the default theme isn't Garland, transfer all of Minnelli's old
2421
      // settings to Garland.
2422
      $settings = variable_get('theme_minnelli_settings', array());
2423
      // Set the theme setting width to "fixed" to match Minnelli's old layout.
2424
      $settings['garland_width'] = 'fixed';
2425
      variable_set('theme_garland_settings', $settings);
2426
      // Remove Garland's color files since they won't match Minnelli's.
2427
      foreach (variable_get('color_garland_files', array()) as $file) {
2428
        @drupal_unlink($file);
2429
      }
2430
      if (isset($file) && $file = dirname($file)) {
2431
        @drupal_rmdir($file);
2432
      }
2433
      variable_del('color_garland_palette');
2434
      variable_del('color_garland_stylesheets');
2435
      variable_del('color_garland_logo');
2436
      variable_del('color_garland_files');
2437
      variable_del('color_garland_screenshot');
2438
    }
2439
    if (variable_get('theme_default') == 'minnelli') {
2440
      variable_set('theme_default', 'garland');
2441
    }
2442
    if (variable_get('admin_theme') == 'minnelli') {
2443
      variable_set('admin_theme', 'garland');
2444
    }
2445
  }
2446
}
2447

    
2448
/**
2449
 * Normalize the front page path variable.
2450
 */
2451
function system_update_7047() {
2452
  variable_set('site_frontpage', drupal_get_normal_path(variable_get('site_frontpage', 'node')));
2453
}
2454

    
2455
/**
2456
 * Convert path languages from the empty string to LANGUAGE_NONE.
2457
 */
2458
function system_update_7048() {
2459
  db_update('url_alias')
2460
    ->fields(array('language' => LANGUAGE_NONE))
2461
    ->condition('language', '')
2462
    ->execute();
2463
}
2464

    
2465
/**
2466
 * Rename 'Default' profile to 'Standard.'
2467
 */
2468
function system_update_7049() {
2469
  if (variable_get('install_profile', 'standard') == 'default') {
2470
    variable_set('install_profile', 'standard');
2471
  }
2472
}
2473

    
2474
/**
2475
 * Change {batch}.id column from serial to regular int.
2476
 */
2477
function system_update_7050() {
2478
  db_change_field('batch', 'bid', 'bid', array('description' => 'Primary Key: Unique batch ID.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
2479
}
2480

    
2481
/**
2482
 * make the IP field IPv6 compatible
2483
 */
2484
function system_update_7051() {
2485
  db_change_field('blocked_ips', 'ip', 'ip', array('description' => 'IP address', 'type' => 'varchar', 'length' => 40, 'not null' => TRUE, 'default' => ''));
2486
}
2487

    
2488
/**
2489
 * Rename file to include_file in {menu_router} table.
2490
 */
2491
function system_update_7052() {
2492
  db_change_field('menu_router', 'file', 'include_file', array('type' => 'text', 'size' => 'medium'));
2493
}
2494

    
2495
/**
2496
 * Upgrade standard blocks and menus.
2497
 */
2498
function system_update_7053() {
2499
  if (db_table_exists('menu_custom')) {
2500
    // Create the same menus as in menu_install().
2501
    db_insert('menu_custom')
2502
      ->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."))
2503
      ->execute();
2504

    
2505
    db_insert('menu_custom')
2506
      ->fields(array('menu_name' => 'management', 'title' => 'Management', 'description' => "The <em>Management</em> menu contains links for administrative tasks."))
2507
      ->execute();
2508
  }
2509

    
2510
  block_flush_caches();
2511

    
2512
  // Show the new menu blocks along the navigation block.
2513
  $blocks = db_query("SELECT theme, status, region, weight, visibility, pages FROM {block} WHERE module = 'system' AND delta = 'navigation'");
2514
  $deltas = db_or()
2515
    ->condition('delta', 'user-menu')
2516
    ->condition('delta', 'management');
2517

    
2518
  foreach ($blocks as $block) {
2519
    db_update('block')
2520
      ->fields(array(
2521
        'status' => $block->status,
2522
        'region' => $block->region,
2523
        'weight' => $block->weight,
2524
        'visibility' => $block->visibility,
2525
        'pages' => $block->pages,
2526
      ))
2527
      ->condition('theme', $block->theme)
2528
      ->condition('module', 'system')
2529
      ->condition($deltas)
2530
      ->execute();
2531
  }
2532
}
2533

    
2534
/**
2535
 * Remove {cache_*}.headers columns.
2536
 */
2537
function system_update_7054() {
2538
  // Update: update_fix_d7_requirements() installs this version for cache_path
2539
  // already, so we don't include it in this particular update. It should be
2540
  // included in later updates though.
2541
  $cache_tables = array(
2542
    'cache' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
2543
    'cache_form' => 'Cache table for the form system to store recently built forms and their storage data, to be used in subsequent page requests.',
2544
    'cache_page' => 'Cache table used to store compressed pages for anonymous users, if page caching is enabled.',
2545
    'cache_menu' => 'Cache table for the menu system to store router information as well as generated link trees for various menu/page/user combinations.',
2546
  );
2547
  $schema = system_schema_cache_7054();
2548
  foreach ($cache_tables as $table => $description) {
2549
    $schema['description'] = $description;
2550
    db_drop_table($table);
2551
    db_create_table($table, $schema);
2552
  }
2553
}
2554

    
2555
/**
2556
 * Converts fields that store serialized variables from text to blob.
2557
 */
2558
function system_update_7055() {
2559
  $spec = array(
2560
    'description' => 'The value of the variable.',
2561
    'type' => 'blob',
2562
    'not null' => TRUE,
2563
    'size' => 'big',
2564
    'translatable' => TRUE,
2565
  );
2566
  db_change_field('variable', 'value', 'value', $spec);
2567

    
2568
  $spec = array(
2569
    'description' => 'Parameters to be passed to the callback function.',
2570
    'type' => 'blob',
2571
    'not null' => TRUE,
2572
    'size' => 'big',
2573
  );
2574
  db_change_field('actions', 'parameters', 'parameters', $spec);
2575

    
2576
  $spec = array(
2577
    'description' => 'A serialized array containing the processing data for the batch.',
2578
    'type' => 'blob',
2579
    'not null' => FALSE,
2580
    'size' => 'big',
2581
  );
2582
  db_change_field('batch', 'batch', 'batch', $spec);
2583

    
2584
  $spec = array(
2585
    '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.',
2586
    'type' => 'blob',
2587
    'not null' => TRUE,
2588
  );
2589
  db_change_field('menu_router', 'load_functions', 'load_functions', $spec);
2590

    
2591
  $spec = array(
2592
    '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.',
2593
    'type' => 'blob',
2594
    'not null' => TRUE,
2595
  );
2596
  db_change_field('menu_router', 'to_arg_functions', 'to_arg_functions', $spec);
2597

    
2598
  $spec = array(
2599
    'description' => 'A serialized array of arguments for the access callback.',
2600
    'type' => 'blob',
2601
    'not null' => FALSE,
2602
  );
2603
  db_change_field('menu_router', 'access_arguments', 'access_arguments', $spec);
2604

    
2605
  $spec = array(
2606
    'description' => 'A serialized array of arguments for the page callback.',
2607
    'type' => 'blob',
2608
    'not null' => FALSE,
2609
  );
2610
  db_change_field('menu_router', 'page_arguments', 'page_arguments', $spec);
2611

    
2612
  $spec = array(
2613
    'description' => 'A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.',
2614
    'type' => 'blob',
2615
    'not null' => FALSE,
2616
    'translatable' => TRUE,
2617
  );
2618
  db_change_field('menu_links', 'options', 'options', $spec);
2619

    
2620
  $spec = array(
2621
    '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.',
2622
    'type' => 'blob',
2623
    'not null' => FALSE,
2624
    'size' => 'big',
2625
  );
2626
  db_change_field('sessions', 'session', 'session', $spec);
2627

    
2628
  $spec = array(
2629
    'description' => "A serialized array containing information from the module's .info file; keys can include name, description, package, version, core, dependencies, and php.",
2630
    'type' => 'blob',
2631
    'not null' => FALSE,
2632
  );
2633
  db_change_field('system', 'info', 'info', $spec);
2634
}
2635

    
2636
/**
2637
 * Increase the size of session-ids.
2638
 */
2639
function system_update_7057() {
2640
  $spec = array(
2641
    'description' => "A session ID. The value is generated by PHP's Session API.",
2642
    'type' => 'varchar',
2643
    'length' => 128,
2644
    'not null' => TRUE,
2645
    'default' => '',
2646
  );
2647
  db_change_field('sessions', 'sid', 'sid', $spec);
2648
}
2649

    
2650
/**
2651
 * Remove cron semaphore variable.
2652
 */
2653
function system_update_7058() {
2654
  variable_del('cron_semaphore');
2655
}
2656

    
2657
/**
2658
 * Create the {file_usage} table.
2659
 */
2660
function system_update_7059() {
2661
  $spec = array(
2662
    'description' => 'Track where a file is used.',
2663
    'fields' => array(
2664
      'fid' => array(
2665
        'description' => 'File ID.',
2666
        'type' => 'int',
2667
        'unsigned' => TRUE,
2668
        'not null' => TRUE,
2669
      ),
2670
      'module' => array(
2671
        'description' => 'The name of the module that is using the file.',
2672
        'type' => 'varchar',
2673
        'length' => 255,
2674
        'not null' => TRUE,
2675
        'default' => '',
2676
      ),
2677
      'type' => array(
2678
        'description' => 'The name of the object type in which the file is used.',
2679
        'type' => 'varchar',
2680
        'length' => 64,
2681
        'not null' => TRUE,
2682
        'default' => '',
2683
      ),
2684
      'id' => array(
2685
        'description' => 'The primary key of the object using the file.',
2686
        'type' => 'int',
2687
        'unsigned' => TRUE,
2688
        'not null' => TRUE,
2689
        'default' => 0,
2690
      ),
2691
      'count' => array(
2692
        'description' => 'The number of times this file is used by this object.',
2693
        'type' => 'int',
2694
        'unsigned' => TRUE,
2695
        'not null' => TRUE,
2696
        'default' => 0,
2697
      ),
2698
    ),
2699
    'primary key' => array('fid', 'type', 'id', 'module'),
2700
    'indexes' => array(
2701
      'type_id' => array('type', 'id'),
2702
      'fid_count' => array('fid', 'count'),
2703
      'fid_module' => array('fid', 'module'),
2704
    ),
2705
  );
2706
  db_create_table('file_usage', $spec);
2707
}
2708

    
2709
/**
2710
 * Create fields in preparation for migrating upload.module to file.module.
2711
 */
2712
function system_update_7060() {
2713
  if (!db_table_exists('upload')) {
2714
    return;
2715
  }
2716

    
2717
  if (!db_query_range('SELECT 1 FROM {upload}', 0, 1)->fetchField()) {
2718
    // There is nothing to migrate. Delete variables and the empty table. There
2719
    // is no need to create fields that are not going to be used.
2720
    foreach (_update_7000_node_get_types() as $node_type) {
2721
      variable_del('upload_' . $node_type->type);
2722
    }
2723
    db_drop_table('upload');
2724
    return;
2725
  }
2726

    
2727
  // Check which node types have upload.module attachments enabled.
2728
  $context['types'] = array();
2729
  foreach (_update_7000_node_get_types() as $node_type) {
2730
    if (variable_get('upload_' . $node_type->type, 0)) {
2731
      $context['types'][$node_type->type] = $node_type->type;
2732
    }
2733
  }
2734

    
2735
  // The {upload} table will be deleted when this update is complete so we
2736
  // want to be careful to migrate all the data, even for node types that
2737
  // may have had attachments disabled after files were uploaded. Look for
2738
  // any other node types referenced by the upload records and add those to
2739
  // the list. The admin can always remove the field later.
2740
  $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');
2741
  foreach ($results as $row) {
2742
    if (!isset($context['types'][$row->type])) {
2743
      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)));
2744
      $context['types'][$row->type] = $row->type;
2745
    }
2746
  }
2747

    
2748
  // Create a single "upload" field on all the content types that have uploads
2749
  // enabled, then add an instance to each enabled type.
2750
  if (count($context['types']) > 0) {
2751
    module_enable(array('file'));
2752
    $field = array(
2753
      'field_name' => 'upload',
2754
      'type' => 'file',
2755
      'module' => 'file',
2756
      'locked' => FALSE,
2757
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
2758
      'translatable' => FALSE,
2759
      'settings' => array(
2760
        'display_field' => 1,
2761
        'display_default' => variable_get('upload_list_default', 1),
2762
        'uri_scheme' => file_default_scheme(),
2763
        'default_file' => 0,
2764
      ),
2765
    );
2766

    
2767
    $upload_size = variable_get('upload_uploadsize_default', 1);
2768
    $instance = array(
2769
      'field_name' => 'upload',
2770
      'entity_type' => 'node',
2771
      'bundle' => NULL,
2772
      'label' => 'File attachments',
2773
      'required' => 0,
2774
      'description' => '',
2775
      'widget' => array(
2776
        'weight' => '1',
2777
        'settings' => array(
2778
          'progress_indicator' => 'throbber',
2779
        ),
2780
        'type' => 'file_generic',
2781
      ),
2782
      'settings' => array(
2783
        'max_filesize' => $upload_size ? ($upload_size . ' MB') : '',
2784
        'file_extensions' => variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'),
2785
        'file_directory' => '',
2786
        'description_field' => 1,
2787
      ),
2788
      'display' => array(
2789
        'default' => array(
2790
          'label' => 'hidden',
2791
          'type' => 'file_table',
2792
          'settings' => array(),
2793
          'weight' => 0,
2794
          'module' => 'file',
2795
        ),
2796
        'full' => array(
2797
          'label' => 'hidden',
2798
          'type' => 'file_table',
2799
          'settings' => array(),
2800
          'weight' => 0,
2801
          'module' => 'file',
2802
        ),
2803
        'teaser' => array(
2804
          'label' => 'hidden',
2805
          'type' => 'hidden',
2806
          'settings' => array(),
2807
          'weight' => 0,
2808
          'module' => NULL,
2809
        ),
2810
        'rss' => array(
2811
          'label' => 'hidden',
2812
          'type' => 'file_table',
2813
          'settings' => array(),
2814
          'weight' => 0,
2815
          'module' => 'file',
2816
        ),
2817
      ),
2818
    );
2819

    
2820
    // Create the field.
2821
    _update_7000_field_create_field($field);
2822

    
2823
    // Create the instances.
2824
    foreach ($context['types'] as $bundle) {
2825
      $instance['bundle'] = $bundle;
2826
      _update_7000_field_create_instance($field, $instance);
2827
      // Now that the instance is created, we can safely delete any legacy
2828
      // node type information.
2829
      variable_del('upload_' . $bundle);
2830
    }
2831
  }
2832
  else {
2833
    // No uploads or content types with uploads enabled.
2834
    db_drop_table('upload');
2835
  }
2836
}
2837

    
2838
/**
2839
 * Migrate upload.module data to the newly created file field.
2840
 */
2841
function system_update_7061(&$sandbox) {
2842
  if (!db_table_exists('upload')) {
2843
    return;
2844
  }
2845

    
2846
  if (!isset($sandbox['progress'])) {
2847
    // Delete stale rows from {upload} where the fid is not in the {files} table.
2848
    db_delete('upload')
2849
      ->notExists(
2850
        db_select('files', 'f')
2851
        ->fields('f', array('fid'))
2852
        ->where('f.fid = {upload}.fid')
2853
      )
2854
      ->execute();
2855

    
2856
    // Delete stale rows from {upload} where the vid is not in the
2857
    // {node_revision} table. The table has already been renamed in
2858
    // node_update_7001().
2859
    db_delete('upload')
2860
      ->notExists(
2861
        db_select('node_revision', 'nr')
2862
        ->fields('nr', array('vid'))
2863
        ->where('nr.vid = {upload}.vid')
2864
      )
2865
      ->execute();
2866

    
2867
    // Retrieve a list of node revisions that have uploaded files attached.
2868
    // DISTINCT queries are expensive, especially when paged, so we store the
2869
    // data in its own table for the duration of the update.
2870
    if (!db_table_exists('system_update_7061')) {
2871
      $table = array(
2872
        'description' => t('Stores temporary data for system_update_7061.'),
2873
        'fields' => array('vid' => array('type' => 'int')),
2874
        'primary key' => array('vid'),
2875
      );
2876
      db_create_table('system_update_7061', $table);
2877
    }
2878
    $query = db_select('upload', 'u');
2879
    $query->distinct();
2880
    $query->addField('u','vid');
2881
    db_insert('system_update_7061')
2882
      ->from($query)
2883
      ->execute();
2884

    
2885
    // Retrieve a list of duplicate files with the same filepath. Only the
2886
    // most-recently uploaded of these will be moved to the new {file_managed}
2887
    // table (and all references will be updated to point to it), since
2888
    // duplicate file URIs are not allowed in Drupal 7.
2889
    // Since the Drupal 6 to 7 upgrade path leaves the {files} table behind
2890
    // after it's done, custom or contributed modules which need to migrate
2891
    // file references of their own can use a similar query to determine the
2892
    // file IDs that duplicate filepaths were mapped to.
2893
    $sandbox['duplicate_filepath_fids_to_use'] = db_query("SELECT filepath, MAX(fid) FROM {files} GROUP BY filepath HAVING COUNT(*) > 1")->fetchAllKeyed();
2894

    
2895
    // Initialize batch update information.
2896
    $sandbox['progress'] = 0;
2897
    $sandbox['last_vid_processed'] = -1;
2898
    $sandbox['max'] = db_query("SELECT COUNT(*) FROM {system_update_7061}")->fetchField();
2899
  }
2900

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

    
2907
  // Retrieve information on all the files attached to these revisions.
2908
  if (!empty($vids)) {
2909
    $node_revisions = array();
2910
    $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));
2911
    foreach ($result as $record) {
2912
      // For each uploaded file, retrieve the corresponding data from the old
2913
      // files table (since upload doesn't know about the new entry in the
2914
      // file_managed table).
2915
      $file = db_select('files', 'f')
2916
        ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp'))
2917
        ->condition('f.fid', $record->fid)
2918
        ->execute()
2919
        ->fetchAssoc();
2920
      if (!$file) {
2921
        continue;
2922
      }
2923

    
2924
      // If this file has a duplicate filepath, replace it with the
2925
      // most-recently uploaded file that has the same filepath.
2926
      if (isset($sandbox['duplicate_filepath_fids_to_use'][$file['filepath']]) && $record->fid != $sandbox['duplicate_filepath_fids_to_use'][$file['filepath']]) {
2927
        $file = db_select('files', 'f')
2928
          ->fields('f', array('fid', 'uid', 'filename', 'filepath', 'filemime', 'filesize', 'status', 'timestamp'))
2929
          ->condition('f.fid', $sandbox['duplicate_filepath_fids_to_use'][$file['filepath']])
2930
          ->execute()
2931
          ->fetchAssoc();
2932
      }
2933

    
2934
      // Add in the file information from the upload table.
2935
      $file['description'] = $record->description;
2936
      $file['display'] = $record->list;
2937

    
2938
      // Create one record for each revision that contains all the uploaded
2939
      // files.
2940
      $node_revisions[$record->vid]['nid'] = $record->nid;
2941
      $node_revisions[$record->vid]['vid'] = $record->vid;
2942
      $node_revisions[$record->vid]['type'] = $record->type;
2943
      $node_revisions[$record->vid]['file'][LANGUAGE_NONE][] = $file;
2944
    }
2945

    
2946
    // Now that we know which files belong to which revisions, update the
2947
    // files'// database entries, and save a reference to each file in the
2948
    // upload field on their node revisions.
2949
    $basename = variable_get('file_directory_path', conf_path() . '/files');
2950
    $scheme = file_default_scheme() . '://';
2951
    foreach ($node_revisions as $vid => $revision) {
2952
      foreach ($revision['file'][LANGUAGE_NONE] as $delta => $file) {
2953
        // We will convert filepaths to URI using the default scheme
2954
        // and stripping off the existing file directory path.
2955
        $file['uri'] = $scheme . preg_replace('!^' . preg_quote($basename) . '!', '', $file['filepath']);
2956
        // Normalize the URI but don't call file_stream_wrapper_uri_normalize()
2957
        // directly, since that is a higher-level API function which invokes
2958
        // hooks while validating the scheme, and those will not work during
2959
        // the upgrade. Instead, use a simpler version that just assumes the
2960
        // scheme from above is already valid.
2961
        if (($file_uri_scheme = file_uri_scheme($file['uri'])) && ($file_uri_target = file_uri_target($file['uri']))) {
2962
          $file['uri'] = $file_uri_scheme . '://' . $file_uri_target;
2963
        }
2964
        unset($file['filepath']);
2965
        // Insert into the file_managed table.
2966
        // Each fid should only be stored once in file_managed.
2967
        db_merge('file_managed')
2968
          ->key(array(
2969
            'fid' => $file['fid'],
2970
          ))
2971
          ->fields(array(
2972
            'uid' => $file['uid'],
2973
            'filename' => $file['filename'],
2974
            'uri' => $file['uri'],
2975
            'filemime' => $file['filemime'],
2976
            'filesize' => $file['filesize'],
2977
            'status' => $file['status'],
2978
            'timestamp' => $file['timestamp'],
2979
          ))
2980
          ->execute();
2981

    
2982
        // Add the usage entry for the file.
2983
        $file = (object) $file;
2984
        file_usage_add($file, 'file', 'node', $revision['nid']);
2985

    
2986
        // Update the node revision's upload file field with the file data.
2987
        $revision['file'][LANGUAGE_NONE][$delta] = array('fid' => $file->fid, 'display' => $file->display, 'description' => $file->description);
2988
      }
2989

    
2990
      // Write the revision's upload field data into the field_upload tables.
2991
      $node = (object) $revision;
2992
      _update_7000_field_sql_storage_write('node', $node->type, $node->nid, $node->vid, 'upload', $node->file);
2993

    
2994
      // Update our progress information for the batch update.
2995
      $sandbox['progress']++;
2996
      $sandbox['last_vid_processed'] = $vid;
2997
    }
2998
  }
2999

    
3000
  // If less than limit node revisions were processed, the update process is
3001
  // finished.
3002
  if (count($vids) < $limit) {
3003
    $finished = TRUE;
3004
  }
3005

    
3006
  // If there's no max value then there's nothing to update and we're finished.
3007
  if (empty($sandbox['max']) || isset($finished)) {
3008
    db_drop_table('upload');
3009
    db_drop_table('system_update_7061');
3010
    return t('Upload module has been migrated to File module.');
3011
  }
3012
  else {
3013
    // Indicate our current progress to the batch update system.
3014
    $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
3015
  }
3016
}
3017

    
3018
/**
3019
 * Replace 'system_list' index with 'bootstrap' index on {system}.
3020
 */
3021
function system_update_7062() {
3022
  db_drop_index('system', 'bootstrap');
3023
  db_drop_index('system', 'system_list');
3024
  db_add_index('system', 'system_list', array('status', 'bootstrap', 'type', 'weight', 'name'));
3025
}
3026

    
3027
/**
3028
 * Delete {menu_links} records for 'type' => MENU_CALLBACK which would not appear in a fresh install.
3029
 */
3030
function system_update_7063() {
3031
  // For router items where 'type' => MENU_CALLBACK, {menu_router}.type is
3032
  // stored as 4 in Drupal 6, and 0 in Drupal 7. Fortunately Drupal 7 doesn't
3033
  // store any types as 4, so delete both.
3034
  $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'));
3035
  foreach ($result as $record) {
3036
    db_delete('menu_links')->condition('mlid', $record->mlid)->execute();
3037
  }
3038
}
3039

    
3040
/**
3041
 * Remove block_callback field from {menu_router}.
3042
 */
3043
function system_update_7064() {
3044
  db_drop_field('menu_router', 'block_callback');
3045
}
3046

    
3047
/**
3048
 * Remove the default value for sid.
3049
 */
3050
function system_update_7065() {
3051
  $spec = array(
3052
    'description' => "A session ID. The value is generated by Drupal's session handlers.",
3053
    'type' => 'varchar',
3054
    'length' => 128,
3055
    'not null' => TRUE,
3056
  );
3057
  db_drop_primary_key('sessions');
3058
  db_change_field('sessions', 'sid', 'sid', $spec, array('primary key' => array('sid', 'ssid')));
3059
  // Delete any sessions with empty session ID.
3060
  db_delete('sessions')->condition('sid', '')->execute();
3061
}
3062

    
3063
/**
3064
 * Migrate the 'file_directory_temp' variable.
3065
 */
3066
function system_update_7066() {
3067
  $d6_file_directory_temp = variable_get('file_directory_temp', file_directory_temp());
3068
  variable_set('file_temporary_path', $d6_file_directory_temp);
3069
  variable_del('file_directory_temp');
3070
}
3071

    
3072
/**
3073
 * Grant administrators permission to view the administration theme.
3074
 */
3075
function system_update_7067() {
3076
  // Users with access to administration pages already see the administration
3077
  // theme in some places (if one is enabled on the site), so we want them to
3078
  // continue seeing it.
3079
  $admin_roles = user_roles(FALSE, 'access administration pages');
3080
  foreach (array_keys($admin_roles) as $rid) {
3081
    _update_7000_user_role_grant_permissions($rid, array('view the administration theme'), 'system');
3082
  }
3083
  // The above check is not guaranteed to reach all administrative users of the
3084
  // site, so if the site is currently using an administration theme, display a
3085
  // message also.
3086
  if (variable_get('admin_theme')) {
3087
    if (empty($admin_roles)) {
3088
      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>.');
3089
    }
3090
    else {
3091
      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>.');
3092
    }
3093
  }
3094
}
3095

    
3096
/**
3097
 * Update {url_alias}.language description.
3098
 */
3099
function system_update_7068() {
3100
  $spec = array(
3101
    '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.",
3102
    'type' => 'varchar',
3103
    'length' => 12,
3104
    'not null' => TRUE,
3105
    'default' => '',
3106
  );
3107
  db_change_field('url_alias', 'language', 'language', $spec);
3108
}
3109

    
3110
/**
3111
 * Remove the obsolete 'site_offline' variable.
3112
 *
3113
 * @see update_fix_d7_requirements()
3114
 */
3115
function system_update_7069() {
3116
  variable_del('site_offline');
3117
}
3118

    
3119
/**
3120
 * @} End of "defgroup updates-6.x-to-7.x".
3121
 * The next series of updates should start at 8000.
3122
 */
3123

    
3124
/**
3125
 * @defgroup updates-7.x-extra Extra updates for 7.x
3126
 * @{
3127
 * Update functions between 7.x versions.
3128
 */
3129

    
3130
/**
3131
 * Remove the obsolete 'drupal_badge_color' and 'drupal_badge_size' variables.
3132
 */
3133
function system_update_7070() {
3134
  variable_del('drupal_badge_color');
3135
  variable_del('drupal_badge_size');
3136
}
3137

    
3138
/**
3139
 * Add index missed during upgrade, and fix field default.
3140
 */
3141
function system_update_7071() {
3142
  db_drop_index('date_format_type', 'title');
3143
  db_add_index('date_format_type', 'title', array('title'));
3144
  db_change_field('registry', 'filename', 'filename', array(
3145
    'type' => 'varchar',
3146
    'length' => 255,
3147
    'not null' => TRUE,
3148
  ));
3149
}
3150

    
3151
/**
3152
 * Remove the obsolete 'site_offline_message' variable.
3153
 *
3154
 * @see update_fix_d7_requirements()
3155
 */
3156
function system_update_7072() {
3157
  variable_del('site_offline_message');
3158
}
3159

    
3160
/**
3161
 * Add binary to {file_managed}, in case system_update_7034() was run without
3162
 * it.
3163
 */
3164
function system_update_7073() {
3165
  db_change_field('file_managed', 'filename', 'filename', array(
3166
    '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.',
3167
    'type' => 'varchar',
3168
    'length' => 255,
3169
    'not null' => TRUE,
3170
    'default' => '',
3171
    'binary' => TRUE,
3172
  ));
3173
  db_drop_unique_key('file_managed', 'uri');
3174
  db_change_field('file_managed', 'uri', 'uri', array(
3175
    'description' => 'The URI to access the file (either local or remote).',
3176
    'type' => 'varchar',
3177
    'length' => 255,
3178
    'not null' => TRUE,
3179
    'default' => '',
3180
    'binary' => TRUE,
3181
  ));
3182
  db_add_unique_key('file_managed', 'uri', array('uri'));
3183
}
3184

    
3185
/**
3186
 * This update has been removed and will not run.
3187
 */
3188
function system_update_7074() {
3189
  // This update function previously converted menu_links query strings to
3190
  // arrays. It has been removed for now due to incompatibility with
3191
  // PostgreSQL.
3192
}
3193

    
3194
/**
3195
 * Convert menu_links query strings into arrays.
3196
 */
3197
function system_update_7076() {
3198
  $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC))
3199
    ->fields('ml', array('mlid', 'options'));
3200
  foreach ($query->execute() as $menu_link) {
3201
    if (strpos($menu_link['options'], 'query') !== FALSE) {
3202
      $menu_link['options'] = unserialize($menu_link['options']);
3203
      if (isset($menu_link['options']['query']) && is_string($menu_link['options']['query'])) {
3204
        $menu_link['options']['query'] = drupal_get_query_array($menu_link['options']['query']);
3205
        db_update('menu_links')
3206
          ->fields(array(
3207
            'options' => serialize($menu_link['options']),
3208
          ))
3209
          ->condition('mlid', $menu_link['mlid'], '=')
3210
          ->execute();
3211
      }
3212
    }
3213
  }
3214
}
3215

    
3216
/**
3217
 * Revert {file_managed}.filename changed to a binary column.
3218
 */
3219
function system_update_7077() {
3220
  db_change_field('file_managed', 'filename', 'filename', array(
3221
    '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.',
3222
    'type' => 'varchar',
3223
    'length' => 255,
3224
    'not null' => TRUE,
3225
    'default' => '',
3226
  ));
3227
}
3228

    
3229

    
3230
/**
3231
 * Add binary to {date_formats}.format.
3232
 */
3233
function system_update_7078() {
3234
  db_drop_unique_key('date_formats', 'formats');
3235
  db_change_field('date_formats', 'format', 'format', array(
3236
    'description' => 'The date format string.',
3237
    'type' => 'varchar',
3238
    'length' => 100,
3239
    'not null' => TRUE,
3240
    'binary' => TRUE,
3241
  ), array('unique keys' => array('formats' => array('format', 'type'))));
3242
}
3243

    
3244
/**
3245
 * Convert the 'filesize' column in {file_managed} to a bigint.
3246
 */
3247
function system_update_7079() {
3248
  $spec = array(
3249
    'description' => 'The size of the file in bytes.',
3250
    'type' => 'int',
3251
    'size' => 'big',
3252
    'unsigned' => TRUE,
3253
    'not null' => TRUE,
3254
    'default' => 0,
3255
  );
3256
  db_change_field('file_managed', 'filesize', 'filesize', $spec);
3257
}
3258

    
3259
/**
3260
 * Convert the 'format' column in {date_format_locale} to case sensitive varchar.
3261
 */
3262
function system_update_7080() {
3263
  $spec = array(
3264
    'description' => 'The date format string.',
3265
    'type' => 'varchar',
3266
    'length' => 100,
3267
    'not null' => TRUE,
3268
    'binary' => TRUE,
3269
  );
3270
  db_change_field('date_format_locale', 'format', 'format', $spec);
3271
}
3272

    
3273
/**
3274
 * Remove the Drupal 6 default install profile if it is still in the database.
3275
 */
3276
function system_update_7081() {
3277
  // Sites which used the default install profile in Drupal 6 and then updated
3278
  // to Drupal 7.44 or earlier will still have a record of this install profile
3279
  // in the database that needs to be deleted.
3280
  db_delete('system')
3281
    ->condition('filename', 'profiles/default/default.profile')
3282
    ->condition('type', 'module')
3283
    ->condition('status', 0)
3284
    ->condition('schema_version', 0)
3285
    ->execute();
3286
}
3287

    
3288
/**
3289
 * @} End of "defgroup updates-7.x-extra".
3290
 * The next series of updates should start at 8000.
3291
 */