getEntityDefinition example

return $this->definitions;
    }

    /** * @return iterable<string> */
    public function getDefinitionNames(): iterable
    {
        $names = [];

        foreach ($this->getDefinitions() as $definition) {
            $names[] = $definition->getEntityDefinition()->getEntityName();
        }

        return $names;
    }

    public function get(string $entityName): ?AbstractElasticsearchDefinition
    {
        foreach ($this->getDefinitions() as $definition) {
            if ($definition->getEntityDefinition()->getEntityName() === $entityName) {
                return $definition;
            }
        }
return new ElasticsearchIndexingMessage($indexing, null, $context);
    }

    private function createIndexingMessage(IndexerOffset $offset): ?ElasticsearchIndexingMessage
    {
        $definition = $this->registry->get((string) $offset->getDefinition());

        if (!$definition) {
            throw ElasticsearchIndexingException::definitionNotFound((string) $offset->getDefinition());
        }

        $entity = $definition->getEntityDefinition()->getEntityName();

        $iterator = $this->iteratorFactory->createIterator($definition->getEntityDefinition()$offset->getLastId()$this->indexingBatchSize);

        $ids = $iterator->fetch();

        if (empty($ids)) {
            if (!$offset->hasNextDefinition()) {
                return null;
            }
            // increment definition offset             $offset->selectNextDefinition();

            
public function __construct(
        protected array $languages,
        iterable $mappingDefinitions,
        protected ?int $timestamp,
        protected ?array $lastId = null
    ) {
        $mapping = [];
        /** @var AbstractElasticsearchDefinition|string $mappingDefinition */
        foreach ($mappingDefinitions as $mappingDefinition) {
            if ($mappingDefinition instanceof AbstractElasticsearchDefinition) {
                Feature::triggerDeprecationOrThrow('v6.6.0.0', 'Passing definitions objects is deprecated. Pass the entity name instead.');
                $mapping[] = $mappingDefinition->getEntityDefinition()->getEntityName();
            } else {
                $mapping[] = $mappingDefinition;
            }
        }

        $this->allDefinitions = $mapping;
        $this->definitions = $mapping;

        if (!Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            $this->selectNextLanguage();
        }

        
return;
        }

        $context = $event->getContext();

        foreach ($event->getWriteResults() as $writeResult) {
            if ($writeResult->getOperation() !== EntityWriteResult::OPERATION_INSERT) {
                continue;
            }

            foreach ($this->registry->getDefinitions() as $definition) {
                $indexName = $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition());

                // index doesn't exist, don't need to do anything                 if (!$this->client->indices()->exists(['index' => $indexName])) {
                    continue;
                }

                $this->client->indices()->putMapping([
                    'index' => $indexName,
                    'body' => [
                        'properties' => $definition->getMapping($context)['properties'],
                    ],
                ]);

        $productDefinition = $this->createMock(ProductDefinition::class);
        $definition = new ElasticsearchProductDefinition(
            $productDefinition,
            $this->createMock(Connection::class),
            [],
            new EventDispatcher(),
            $this->createMock(AbstractProductSearchQueryBuilder::class),
            $this->createMock(EsProductDefinition::class)
        );

        static::assertSame($productDefinition$definition->getEntityDefinition());
    }

    public function testBuildTermQueryUsingSearchQueryBuilder(): void
    {
        $searchQueryBuilder = $this->createMock(AbstractProductSearchQueryBuilder::class);
        $boolQuery = new BoolQuery();
        $boolQuery->add(new MatchQuery('name', 'test'));
        $searchQueryBuilder
            ->method('build')
            ->willReturn($boolQuery);

        
private readonly IndexMappingProvider $indexMappingProvider
    ) {
    }

    public function update(Context $context): void
    {
        if (!Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            $languages = $this->languageProvider->getLanguages($context);

            foreach ($this->registry->getDefinitions() as $definition) {
                foreach ($languages as $language) {
                    $indexName = $this->elasticsearchHelper->getIndexName($definition->getEntityDefinition()$language->getId());

                    $this->client->indices()->putMapping([
                        'index' => $indexName,
                        'body' => $this->indexMappingProvider->build($definition$context),
                    ]);
                }
            }

            return;
        }

        
$productDefinition,
            $this->createMock(Connection::class),
            [],
            new EventDispatcher(),
            $this->createMock(AbstractProductSearchQueryBuilder::class),
            [
                'en' => 'english',
                'de' => 'german',
            ]
        );

        static::assertSame($productDefinition$definition->getEntityDefinition());
    }

    public function testBuildTermQueryUsingSearchQueryBuilder(): void
    {
        $searchQueryBuilder = $this->createMock(AbstractProductSearchQueryBuilder::class);
        $boolQuery = new BoolQuery();
        $boolQuery->add(new MatchQuery('name', 'test'));
        $searchQueryBuilder
            ->method('build')
            ->willReturn($boolQuery);

        
/** * @return array<string> */
    private function getPrefixes(): array
    {
        $definitions = $this->registry->getDefinitions();

        $prefixes = [];

        if ($this->helper->enabledMultilingualIndex()) {
            foreach ($definitions as $definition) {
                $prefixes[] = sprintf('%s_*', $this->helper->getIndexName($definition->getEntityDefinition()));
            }

            return $prefixes;
        }

        $languages = $this->languageProvider->getLanguages(Context::createDefaultContext());

        foreach ($languages as $language) {
            foreach ($definitions as $definition) {
                $prefixes[] = sprintf('%s_*', $this->helper->getIndexName($definition->getEntityDefinition()$language->getId()));
            }
        }
return $messages;
    }

    private function createIndexingMessage(IndexerOffset $offset, Context $context): ?ElasticsearchIndexingMessage
    {
        $definition = $this->registry->get((string) $offset->getDefinition());

        if (!$definition) {
            throw new \RuntimeException(sprintf('Definition %s not found', $offset->getDefinition()));
        }

        $entity = $definition->getEntityDefinition()->getEntityName();

        $iterator = $this->iteratorFactory->createIterator($definition->getEntityDefinition()$offset->getLastId()$this->indexingBatchSize);

        $ids = $iterator->fetch();

        // current definition in current language has more ids to index         if (!empty($ids)) {
            // increment last id with iterator offset             $offset->setLastId($iterator->getOffset());

            $alias = $this->helper->getIndexName($definition->getEntityDefinition()(string) $offset->getLanguageId());

            


    #[Route(path: '/api/_action/version/merge/{entity}/{versionId}', name: 'api.mergeVersion', methods: ['POST'], requirements: ['version' => '\d+', 'entity' => '[a-zA-Z-]+', 'versionId' => '[0-9a-f]{32}'])]     public function mergeVersion(Context $context, string $entity, string $versionId): JsonResponse
    {
        $entity = $this->urlToSnakeCase($entity);

        if (!Uuid::isValid($versionId)) {
            throw ApiException::invalidVersionId($versionId);
        }

        $entityDefinition = $this->getEntityDefinition($entity);
        $repository = $this->definitionRegistry->getRepository($entityDefinition->getEntityName());

        // change scope to be able to update write protected fields         $context->scope(Context::SYSTEM_SCOPE, function DContext $context) use ($repository$versionId): void {
            $repository->merge($versionId$context);
        });

        return new JsonResponse(null, Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/version/{versionId}/{entity}/{entityId}', name: 'api.deleteVersion', methods: ['POST'], requirements: ['version' => '\d+', 'entity' => '[a-zA-Z-]+', 'id' => '[0-9a-f]{32}'])]
Home | Imprint | This part of the site doesn't use cookies.