You are here

public function EntityShareEntityImport::getLocalEntityIds in Entity Share 7

Test if uuid already exists and get the local entity id.

Parameters

object $entity: Entity or sub entity to import.

Return value

array|bool Local ids of the entity, FALSE if problem.

Throws

EntityShareImportException Import exception.

1 call to EntityShareEntityImport::getLocalEntityIds()
EntityShareEntityImport::setLocalEntityIds in includes/entity_share.entity.import.inc
Set the local entity ids.

File

includes/entity_share.entity.import.inc, line 65
Class for handling Entity Import.

Class

EntityShareEntityImport
Manage general entity import.

Code

public function getLocalEntityIds($entity = NULL) {
  if (!isset($entity)) {
    $entity = $this
      ->getEntity();
  }
  if (!is_object($entity)) {
    throw new EntityShareImportException('Object expected for $entity variable');
  }
  $entity_id = NULL;
  $revision_id = NULL;

  // Uuid.
  $entity_info = entity_get_info($entity->entity_type);
  $uuid_key = $entity_info['entity keys']['uuid'];
  if (isset($entity_info['entity keys']['revision uuid'])) {
    $vuuid_key = $entity_info['entity keys']['revision uuid'];
    if (isset($entity->{$vuuid_key})) {
      $vuuid = $entity->{$vuuid_key};
    }
  }
  $uuid = $entity->{$uuid_key};
  $entity_ids = entity_get_id_by_uuid($entity->entity_type, array(
    $uuid,
  ));
  if (!isset($entity_ids[$uuid])) {
    return FALSE;
  }
  $entity_id = $entity_ids[$uuid];
  if (isset($vuuid)) {
    $revision_ids = entity_get_id_by_uuid($entity->entity_type, array(
      $vuuid,
    ), TRUE);
    if (isset($revision_ids[$vuuid])) {
      $revision_id = $revision_ids[$vuuid];
    }
  }
  return array(
    'entity_id' => $entity_id,
    'revision_id' => $revision_id,
  );
}