getExistence example


                $field = $definition->getFields()->get($key);

                $mappedBytes[$field->getStorageName()] = $field->getSerializer()->encode(
                    $field,
                    EntityExistence::createForEntity($definition->getEntityName()[$key => $value]),
                    new KeyValuePair($key$value, true),
                    $parameters,
                )->current();
            }

            $existence = $this->gateway->getExistence($definition$mappedBytes[]$commandQueue);

            if ($existence->exists()) {
                $commandQueue->add($definitionnew DeleteCommand($definition$mappedBytes$existence));

                continue;
            }

            $stripped = [];
            /** * @var string $key * @var string $value */
$fkField = $definition->getFields()->getByStorageName(
            $parent->getEntityName() . '_id'
        );
        $parentPrimaryKey = [
            'id' => $primaryKey[$fkField->getStorageName()],
        ];

        if ($parent->isVersionAware()) {
            $parentPrimaryKey['versionId'] = $primaryKey[$parent->getEntityName() . '_version_id'];
        }

        $existence = $this->getExistence($parent$parentPrimaryKey[]$commandQueue);

        return $existence->isChild();
    }
}
public function update(EntityWrittenContainerEvent $event): ?EntityIndexingMessage
    {
        $categoryEvent = $event->getEventByEntityName(CategoryDefinition::ENTITY_NAME);

        if (!$categoryEvent) {
            return null;
        }

        $ids = $categoryEvent->getIds();
        $idsWithChangedParentIds = [];
        foreach ($categoryEvent->getWriteResults() as $result) {
            if (!$result->getExistence()) {
                continue;
            }
            $state = $result->getExistence()->getState();

            if (isset($state['parent_id'])) {
                $ids[] = Uuid::fromBytesToHex($state['parent_id']);
            }

            $payload = $result->getPayload();
            if (\array_key_exists('parentId', $payload)) {
                if ($payload['parentId'] !== null) {
                    
if ($event === null) {
            return;
        }

        if (!$this->elasticsearchHelper->allowIndexing()) {
            return;
        }

        $newCreatedFields = [];

        foreach ($event->getWriteResults() as $writeResult) {
            $existence = $writeResult->getExistence();

            if ($existence && $existence->exists()) {
                continue;
            }

            /** @var array<mixed> $esType */
            $esType = self::getTypeFromCustomFieldType($writeResult->getProperty('type'));

            $newCreatedFields[(string) $writeResult->getProperty('name')] = $esType;
        }

        
$parameters->getContext()->set(
                $parameters->getDefinition()->getEntityName(),
                $pkField->getPropertyName(),
                $pkField->getSerializer()->decode($pkField$pkData[$pkField->getStorageName()]),
            );
        }

        if ($definition instanceof MappingEntityDefinition) {
            // gateway will execute always a replace into             $existence = EntityExistence::createForEntity($definition->getEntityName()[]);
        } else {
            $existence = $this->entityExistenceGateway->getExistence($definition$pkData$rawData$parameters->getCommandQueue());
        }

        $stack = $this->createDataStack($existence$definition$parameters$rawData);

        $mainFields = $this->getMainFields($fields);

        // without child association         $data = $this->map($mainFields$stack$existence$parameters);

        $this->updateCommandQueue($definition$parameters$existence$pkData$data);

        
return $this->payloads;
    }

    /** * @return EntityExistence[] */
    public function getExistences(): array
    {
        if (empty($this->existences)) {
            $this->existences = [];
            foreach ($this->writeResults as $entityWriteResult) {
                if ($entityWriteResult->getExistence()) {
                    $this->existences[] = $entityWriteResult->getExistence();
                }
            }
        }

        return $this->existences;
    }

    /** * @return EntityWriteResult[] */
    


        if (empty($payload)) {
            return null;
        }

        return new EntityWriteResult(
            $writeResult->getPrimaryKey(),
            $payload,
            $writeResult->getEntityName(),
            $writeResult->getOperation(),
            $writeResult->getExistence(),
            $writeResult->getChangeSet()
        );
    }

    /** * @param EntityWriteResult[] $writeResults * @param string|array<string, string> $entityKey * * @return EntityWriteResult[] */
    private function findWriteResultByPrimaryKey(array $writeResults, array|string $entityKey): array
    {
Home | Imprint | This part of the site doesn't use cookies.