You are here

function i18n_install_create_fields in Internationalization 7

Add fields to the schema if they don't exist.

Parameters

string $table: The name of the database table.

array $fields: The list of database fields to create.

boolean $force_rebuild_schema: Whether to force drupal_get_schema() to rebuild the schema. This may be necessary when additional implementations of hook_schema_alter() have become available since the schema was originally built.

5 calls to i18n_install_create_fields()
i18n_block_install in i18n_block/i18n_block.install
Implements hook_install().
i18n_menu_install in i18n_menu/i18n_menu.install
Implements hook_install().
i18n_string_install in i18n_string/i18n_string.install
Implements hook_install().
i18n_taxonomy_install in i18n_taxonomy/i18n_taxonomy.install
Set language field in its own table. Do not drop node.language now, just in case. TO-DO: Drop old tables, fields
i18n_taxonomy_update_7004 in i18n_taxonomy/i18n_taxonomy.install
Update D6 language fields in {taxonomy_vocabulary} and {taxonomy_term_data}.

File

./i18n.install, line 36
Installation file for Internationalization (i18n) module.

Code

function i18n_install_create_fields($table, $fields, $force_rebuild_schema = FALSE) {
  static $schema;
  $rebuild_schema = !isset($schema) || $force_rebuild_schema;
  $schema = drupal_get_schema($table, $rebuild_schema);
  foreach ($fields as $field) {
    if (!empty($schema['fields'][$field])) {
      if (!db_field_exists($table, $field)) {
        db_add_field($table, $field, $schema['fields'][$field]);
      }
      else {

        // The field exists, make sure field definition is up to date.
        db_change_field($table, $field, $field, $schema['fields'][$field]);
      }
    }
  }
}