Exemplo n.º 1
0
 /**
  * Given an array of revision IDs and UUIDs and an entity, searches through
  * our site for a matching revision UUID. If there are no matching UUIDs,
  * this function returns false.
  *
  * @param array  $revisions The list of revisions. Each item contains an ID and
  *                          UUID field.
  * @param Entity $entity    The entity on our side to check for revisions.
  *
  * @return array|bool
  */
 protected function findMatchingRevision($revisions, Entity $entity)
 {
     $revision_uuids = array();
     foreach ($revisions as $revision) {
         $revision_uuids[] = $revision['uuid'];
     }
     // Get the revisions on our end and find the nearest one that matches.
     $our_revisions = Entity::getAllRevisions($entity->id(), $entity->type());
     if (!$our_revisions || !is_array($our_revisions)) {
         return false;
     }
     foreach ($our_revisions as $revision) {
         if (in_array($revision['uuid'], $revision_uuids)) {
             return $revision['uuid'];
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Create reference definition.
  *
  * Creates an entity reference definition, storing the UUID, VUUID and entity
  * type for the provided entity.
  *
  * @param Entity $entity       The entity to generate the definition for.
  *
  * @return array The generated definition.
  */
 public static function createReferenceDefinition(Entity $entity)
 {
     $value = array();
     $value['uuid'] = $entity->uuid();
     $value['vuuid'] = $entity->vuuid();
     $value['entity_type'] = $entity->type();
     $value['original'] = $entity->id();
     $value['original_revision'] = $entity->revision();
     $value['revisions'] = Entity::getAllRevisions($entity->id(), $entity->type());
     return $value;
 }
Exemplo n.º 3
0
 /**
  * Sets the value of the source entity in the relationship
  * to contain $key pointing to the destination entity ID.
  *
  * @param array  $relationship    The relationship.
  * @param string $key             The key to set (target_id, tid, fid, etc.)
  * @param array  $value_overrides An array of values to override on the field value.
  *
  * @return bool
  * @throws \Exception
  */
 protected function setValueWithKey(array $relationship, $key, array $value_overrides = array())
 {
     $destination_entity_id = $this->getDestinationEntityID($relationship);
     $stub_entity = $this->getSourceStubEntity($relationship);
     if (!$destination_entity_id || !$stub_entity) {
         return false;
     }
     // Get all revisions on the stub entity.
     list($source_entity_id, , ) = entity_extract_ids($relationship['source_type'], $stub_entity);
     if (Entity::typeSupportsRevisions($relationship['source_type'])) {
         $source_entity_revisions = Entity::getAllRevisions($source_entity_id, $relationship['source_type']);
         if (!is_array($source_entity_revisions)) {
             throw new \Exception('No revisions were found for the entity that should support revisions.');
         }
         $index = array_search($relationship['source_vuuid'], $source_entity_revisions);
         foreach (array_slice($source_entity_revisions, $index) as $revision_uuid) {
             $mock_relationship = $relationship;
             $mock_relationship['source_vuuid'] = $revision_uuid;
             $mock_stub_entity = $this->getSourceStubEntity($mock_relationship);
             $field_value = array($key => $destination_entity_id);
             $field_value = array_replace_recursive($field_value, $value_overrides);
             $this->setFieldValue($relationship['source_type'], $mock_stub_entity, $relationship['field_name'], $relationship['delta'], $field_value);
         }
     }
     // Finally, set the general value without revisions.
     $field_value = array($key => $destination_entity_id);
     $field_value = array_replace_recursive($field_value, $value_overrides);
     $this->setFieldValue($relationship['source_type'], $stub_entity, $relationship['field_name'], $relationship['delta'], $field_value);
     return true;
 }