@since 0.7

@param EntityDocument $entityDocument
@param EditInfo $editInfo

@return EntityDocument
191648
public function save( EntityDocument $entityDocument, EditInfo $editInfo ) {
		return $this->revisionSaver->save( new Revision( new Content( $entityDocument ) ), $editInfo );
	}
375939
protected function prepareDocumentForGet(AbstractDocument $entity): bool
    {
        $document = $entity->getMongoDocument();

        if (!$document or empty($document)) {
            return true;
        }

        foreach ($document as $key => $value) {
            if ($value instanceof BSONDocument) {
                $value = $value->getArrayCopy();
            }
            if (is_array($value) and array_key_exists('document_serialization', $value)){
                $documentEntity = $this->loadDocumentSerializedEntity($value);

                $entity->__set($key, $documentEntity);
            }
        }

        return true;
    }
1332072
public function getStableVersion(DocumentationEntity $entity)
    {
        foreach ($this->getEntities() as $check) {
            if ($check->getKey() == $entity->getKey()) {
                if ($check->getLanguage() == $entity->getLanguage()) {
                    if ($check->getIsStable()) {
                        return $check;
                    }
                }
            }
        }

        return $entity;
    }
461539
public function documentToEntity($document, string $entityClassName)
    {
        if (!$this->annotationParser->isEntityClass($entityClassName)) {
            return $document;
        }

        try {
            $reflectClass = new \ReflectionClass($entityClassName);
        } catch (\Exception $exception) {
            return $document;
        }

        $entity = new $entityClassName();

        foreach ($reflectClass->getProperties() as $documentProperty) {
            if ($documentProperty->isStatic()) {
                continue;
            }

            $annotation = $this->annotationParser->getPropertyAnnotation($documentProperty);
            if (null === $annotation) {
                continue;
            }

            $propertyName = $annotation->name ?? $documentProperty->getName();
            if ($annotation->id) {
                $propertyName = '_id';
            }
            $propertyValue = $document->{$propertyName} ?? null;
            $fieldValue = $this->propertyToField($propertyValue, $annotation);

            $documentProperty->setAccessible(true);
            $documentProperty->setValue($entity, $fieldValue);
        }

        return $entity;
    }
193073
public function create($rawDocument)
    {
        /** @var \Magento\Framework\Search\DocumentField[] $fields */

        $entityIdFieldName = $this->entityMetadata->getEntityId();

        $rawDocument[Document::ID] = $rawDocument[$entityIdFieldName];

        return $this->objectManager->create($this->instanceName, ['data' => $rawDocument]);
    }
495394
private function buildDocument($objDocument)
  {
    $document = new \Document($objDocument->id, $objDocument->name);
    $document->categoryId = $objDocument->pid;
    $document->description = $objDocument->description;
    $document->keywords = $objDocument->keywords;
    $document->fileName = $objDocument->data_file_name;
    $document->fileType = $objDocument->data_file_type;
    $document->fileSize = $objDocument->data_file_size;
    $document->filePreview = $objDocument->data_file_preview;
    $document->versionMajor = $objDocument->version_major;
    $document->versionMinor = $objDocument->version_minor;
    $document->versionPatch = $objDocument->version_patch;
    $document->uploadMemberId = $objDocument->upload_member;
    $document->uploadMemberName = $objDocument->upload_member_name;
    $document->uploadDate = $objDocument->upload_date;
    $document->lasteditMemberId = $objDocument->lastedit_member;
    $document->lasteditMemberName = $objDocument->lastedit_member_name;
    $document->lasteditDate = $objDocument->lastedit_date;
    $document->published = $objDocument->published;
    
    // HOOK: modify the document
    if (isset($GLOBALS['TL_HOOKS']['dmsModifyLoadedDocument']) && is_array($GLOBALS['TL_HOOKS']['dmsModifyLoadedDocument']))
    {
      foreach ($GLOBALS['TL_HOOKS']['dmsModifyLoadedDocument'] as $callback)
      {
        $this->import($callback[0]);
        $document = $this->{$callback[0]}->{$callback[1]}($document, $objDocument);
      }
    }
    
    return $document;
  }
186223
public function toXML(DOMElement $parent = null) : DOMElement
    {
        if (empty($this->entityID)) {
            throw new \Exception('Cannot convert EntityDescriptor to XML without an EntityID set.');
        }

        if ($parent === null) {
            $doc = DOMDocumentFactory::create();
            $e = $doc->createElementNS(Constants::NS_MD, 'md:EntityDescriptor');
            $doc->appendChild($e);
        } else {
            $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, 'md:EntityDescriptor');
            $parent->appendChild($e);
        }

        $e->setAttribute('entityID', $this->entityID);

        if ($this->ID !== null) {
            $e->setAttribute('ID', $this->ID);
        }

        if ($this->validUntil !== null) {
            $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil));
        }

        if ($this->cacheDuration !== null) {
            $e->setAttribute('cacheDuration', $this->cacheDuration);
        }

        Extensions::addList($e, $this->Extensions);

        foreach ($this->RoleDescriptor as $n) {
            $n->toXML($e);
        }

        if ($this->AffiliationDescriptor !== null) {
            $this->AffiliationDescriptor->toXML($e);
        }

        if ($this->Organization !== null) {
            $this->Organization->toXML($e);
        }

        foreach ($this->ContactPerson as $cp) {
            $cp->toXML($e);
        }

        foreach ($this->AdditionalMetadataLocation as $n) {
            $n->toXML($e);
        }

        /** @var \DOMElement $child */
        $child = $e->firstChild;
        $this->signElement($e, $child);

        return $e;
    }
646477
public function find($entityName, $identifier, $lockMode = LockMode::NONE, $lockVersion = null)
    {
        return $this->getRepository($entityName)->find($identifier, $lockMode, $lockVersion);
    }
473117
public function prepareFor(ContentStreamAware $entity, $type, $locale, $revision = 'default', $save = TRUE) {
    try {
      $contentStream = 
         $entity->getContentStream()
           ->locale($locale)
           ->type($type)
           ->revision($revision)
           ->one()
       ;
     } catch (NoContentStreamsFoundException $e) {
       $contentStream = 
         $this->createEmptyEntity($revision)
           ->setLocale($locale)
           ->setRevision($revision)
           ->setType($type);

       $entity->addContentStream($contentStream);

       
       if ($save) {
         $this->repository->save($contentStream);
         $this->repository->persist($entity);
       }
     }

    return $contentStream;
  }
1241729
protected function populate($entity, array $entityData)
    {
        foreach ($entityData as $key => $value) {
            if ($this->propertyAccessor->isWritable($entity, $key)) {
                $this->propertyAccessor->setValue($entity, $key, $value);
            }
        }

        return $entity;
    }
1150434
private function findFieldInstances($entityType, $entityInfo)
    {
        $ret = [];

        // Add field properties, since Drupal does not differenciate entity
        // bundles using different class for different object, we are just
        // gonna give the whole field list
        foreach (field_info_instances($entityType) as $fields) {
            foreach ($fields as $name => $instance) {

                if (isset($ret[$name])) {
                    continue;
                }

                $ret[$name] = $instance;
            }
        }

        return $ret;
    }
1228175
public function updateOne($moduleName, $entityID, array $params)
    {
        if (!is_assoc_array($params)) {
            throw new WSException(
                "You have to specify at least one search parameter (prop => value) 
                in order to be able to update the entity(ies)"
            );
        }

        // Fail if no ID was supplied
        if (empty($entityID)) {
            throw new WSException("The list of contraints must contain a valid ID");
        }

        // Preprend so-called moduleid if needed
        $entityID = $this->wsClient->modules->getTypedID($moduleName, $entityID);

        // Check if the entity exists + retrieve its data so it can be used below
        $entityData = $this->findOneByID($moduleName, $entityID);
        if ($entityData === false && !is_array($entityData)) {
            throw new WSException("Such entity doesn't exist, so it cannot be updated");
        }

        // The new data overrides the existing one needed to provide
        // mandatory field values to WS 'update' operation
        $params = array_merge(
            $entityData,
            $params
        );

        $requestData = [
            'elementType' => $moduleName,
            'element'     => json_encode($params)
        ];

        return $this->wsClient->invokeOperation('update', $requestData);
    }
629169
private void updateDocument(EntityMetadata metadata, final MetamodelImpl metaModel, Object entity, String parentId,
            Class<? extends Object> class1, boolean b)
    {
        updateOrCreateIndex(metadata, metaModel, entity, parentId, entity.getClass(), true);
        onCommit();
    }
281296
public function addDocumentInfo(PHPCrawlerDocumentInfo $DocInfo)
  {
    // If queue is full -> wait a little
    while ($this->getDocumentInfoCount() >= $this->queue_max_size)
    {
      usleep(500000);
    }
    
    $this->createPreparedStatements();
    
    $ser = serialize($DocInfo);
    
    $this->PDO->exec("BEGIN EXCLUSIVE TRANSACTION");
    $this->preparedInsertStatement->bindParam(1, $ser, PDO::PARAM_LOB);
    $this->preparedInsertStatement->execute();
    $this->preparedSelectStatement->closeCursor();
    $this->PDO->exec("COMMIT");
  }
510182
protected function generateFieldReadStatement(Entity $entity, FieldDescriptorProto $field)
    {
        $generator = new ReadFieldStatementGenerator($this->context);

        $generator->setBreakMode(ReadFieldStatementGenerator::BREAK_MODE_RETURN);
        $generator->setTargetVar('$value');

        return $generator->generateFieldReadStatement($entity, $field);
    }
1123033
public function save( Revision $revision, EditInfo $editInfo = null ) {
		$editInfo = $editInfo ? $editInfo : $revision->getEditInfo();

		$result = $this->api->postRequest(
			new SimpleRequest( 'edit', $this->getEditParams( $revision, $editInfo ) )
		);
		return ( $result['edit']['result'] == 'Success' );
	}
948223
protected function generateFieldCondition(Entity $entity, FieldDescriptorProto $field)
    {
        $tag   = $field->getNumber();
        $lines = $this->generateFieldReadStatement($entity, $field);
        $lines = $this->addIndentation($lines, 1);

        $body[] = 'if ($tag === ' . $tag . ') {';
        $body   = array_merge($body, $lines);
        $body[] = '}';
        $body[] = null;

        return $body;
    }