You are here

public function MigrateDestinationEntityAPI::getKeySchema in Migrate Extras 7.2

Gets the schema for the base key(s) of an entity type.

Parameters

string $entity_type: A Drupal entity type.

File

./entity_api.inc, line 48
Support for entity types implementing the Entity API.

Class

MigrateDestinationEntityAPI
Destination class implementing migration into entity types.

Code

public function getKeySchema($entity_type = NULL) {

  // Migrate UI invokes $destination->getKeySchema() without any parameters.
  if (!$entity_type) {
    if (isset($this)) {
      if ($this instanceof MigrateDestination) {
        $entity_type = $this->entityType;
      }
      elseif ($this instanceof Migration) {
        $entity_type = $this->destination->entityType;
      }
    }
    else {
      return array();
    }
  }
  $info = entity_get_info($entity_type);
  $schema = drupal_get_schema($info['base table']);
  $key = isset($info['entity keys']['name']) ? $info['entity keys']['name'] : $info['entity keys']['id'];
  $key_schema = $schema['fields'][$key];
  $revision_key = isset($info['entity keys']['revision']) ? $info['entity keys']['revision'] : NULL;
  $revision_schema = empty($revision_key) ? NULL : $schema['fields'][$revision_key];

  // We can't have any form of serial fields here, since the mapping table
  // already has it's own.
  $key_schema['auto_increment'] = FALSE;
  if ($key_schema['type'] == 'serial') {
    $key_schema['type'] = 'int';
  }
  $return = array(
    $key => $key_schema,
  );
  if (!empty($revision_key)) {
    $return[$revision_key] = $revision_schema;
  }
  return $return;
}