function system_update_8004

Add {file_managed}.langcode field.

See also

http://drupal.org/node/1454538

Related topics

File

drupal/core/modules/system/system.install, line 1289
Install, update and uninstall functions for the system module.

Code

function system_update_8004() {
  $langcode_field = array(
    'description' => 'The {language}.langcode of this file.',
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
  );

  // If a Drupal 7 contrib module already added a langcode field to support
  // internationalization, keep it, but standardize the specification.
  // Otherwise, add the field.
  if (db_field_exists('file_managed', 'langcode')) {

    // According to the documentation of db_change_field(), indices using the
    // field should be dropped first; if the contrib module created any indices,
    // it is its responsibility to drop them in an update function that runs
    // before this one, which it can enforce via hook_update_dependencies().
    db_change_field('file_managed', 'langcode', 'langcode', $langcode_field);
  }
  else {

    // Files can be language-specific (e.g., a scanned document) or not (e.g.,
    // a photograph). For a site being updated, Drupal does not have a way to
    // determine which existing files are language-specific and in what
    // language. Our best guess is to set all of them to Language::LANGCODE_NOT_SPECIFIED.
    $langcode_field['initial'] = Language::LANGCODE_NOT_SPECIFIED;
    db_add_field('file_managed', 'langcode', $langcode_field);
  }
}