function taxonomy_update_8001

Adds langcode field to {taxonomy_term_data} and {taxonomy_vocabulary}.

See also

http://drupal.org/node/1454538

File

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

Code

function taxonomy_update_8001() {
  $descriptions = array(
    'taxonomy_term_data' => 'The {language}.langcode of this term.',
    'taxonomy_vocabulary' => 'The {language}.langcode of this vocabulary.',
  );
  foreach ($descriptions as $table => $description) {
    $langcode_field = array(
      'description' => $description,
      '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($table, '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($table, 'langcode', 'langcode', $langcode_field);
    }
    else {

      // When updating from a site that did not already have taxonomy
      // internationalization, initialize all existing vocabularies and terms as
      // being in the site's default language.
      $langcode_field['initial'] = language_default()->langcode;
      db_add_field($table, 'langcode', $langcode_field);
    }
  }
}