You are here

public function Table::changeIndex in Data 8

Change indexes of a table.

Throws

DataException

File

src/Table.php, line 369

Class

Table
Manages data access and manipulation for a single data table. Use data_create_table() or data_get_table() to instantiate an object from this class.

Namespace

Drupal\data

Code

public function changeIndex($fields) {
  $schema = $this->table_schema;

  // @TODO: This array_keys() reduces indexes to single field indexes.
  // Will need adjustment when multi-field indexes are implemented.
  $indexes = isset($schema['indexes']) ? array_keys($schema['indexes']) : array();
  $add = array_diff($fields, $indexes);
  $drop = array_diff($indexes, $fields);
  foreach ($add as $field) {
    $this
      ->addIndex($field);
  }
  foreach ($drop as $field) {
    $this
      ->dropIndex($field);
  }
}