You are here

function entityreference_update_7001 in Entity reference 7

Drop "target_type" from the field schema.

File

./entityreference.install, line 102

Code

function entityreference_update_7001() {
  if (!module_exists('field_sql_storage')) {
    return;
  }
  foreach (field_info_fields() as $field_name => $field) {
    if ($field['type'] != 'entityreference') {

      // Not an entity reference field.
      continue;
    }

    // Update the field settings.
    $field = field_info_field($field_name);
    unset($field['indexes']['target_entity']);
    $field['indexes']['target_id'] = array(
      'target_id',
    );
    field_update_field($field);
    if ($field['storage']['type'] !== 'field_sql_storage') {

      // Field doesn't use SQL storage, we cannot modify the schema.
      continue;
    }
    $table_name = _field_sql_storage_tablename($field);
    $revision_name = _field_sql_storage_revision_tablename($field);
    db_drop_index($table_name, $field_name . '_target_entity');
    db_drop_index($table_name, $field_name . '_target_id');
    db_drop_field($table_name, $field_name . '_target_type');
    db_add_index($table_name, $field_name . '_target_id', array(
      $field_name . '_target_id',
    ));
    db_drop_index($revision_name, $field_name . '_target_entity');
    db_drop_index($revision_name, $field_name . '_target_id');
    db_drop_field($revision_name, $field_name . '_target_type');
    db_add_index($revision_name, $field_name . '_target_id', array(
      $field_name . '_target_id',
    ));
  }
}