You are here

function field_collection_update_7007 in Field collection 7

Add index on {$field_collection_field}_value column for all tables.

File

./field_collection.install, line 342
Install, update and uninstall functions for the field_collection module.

Code

function field_collection_update_7007() {
  foreach (field_read_fields(array(
    'type' => 'field_collection',
  )) as $field_name => $field) {
    if (!isset($field['indexes']['value'])) {

      // Add index on the value column and update the field.
      $field['indexes']['value'] = array(
        'value',
      );
      field_update_field($field);
    }
    $table_prefixes = array(
      'field_data',
      'field_revision',
    );
    foreach ($table_prefixes as $table_prefix) {
      $table = "{$table_prefix}_{$field_name}";
      $value_column = "{$field_name}_value";
      if (!db_index_exists($table, $value_column)) {

        // Add index on the value column.
        db_add_index($table, $value_column, array(
          $value_column,
        ));
      }
    }
  }
}