getAllUsedIndices example

$connection->executeStatement('DELETE FROM custom_field');

        $command = new ElasticsearchIndexingCommand(
            $this->getContainer()->get(ElasticsearchIndexer::class),
            $this->getContainer()->get('messenger.bus.shopware'),
            $this->getContainer()->get(CreateAliasTaskHandler::class),
            true
        );

        $command->run(new ArrayInput([])new NullOutput());

        static::assertNotEmpty($this->indexDetector->getAllUsedIndices());
    }

    /** * @depends testCreateIndices */
    public function testCreateCustomFields(): void
    {
        $customFieldRepository = $this->getContainer()->get('custom_field_set.repository');
        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            $this->getContainer()->get(AbstractKeyValueStorage::class)->set(ElasticsearchIndexer::ENABLE_MULTILINGUAL_INDEX_KEY, 1);
        }

        
$esHelper = $this->createMock(ElasticsearchHelper::class);

        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            $esHelper->method('enabledMultilingualIndex')->willReturn(true);
        }

        $detector = new ElasticsearchOutdatedIndexDetector($client$registry$esHelper$this->createMock(ElasticsearchLanguageProvider::class));
        $arr = $detector->get();
        static::assertNotNull($arr);
        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            static::assertCount(1, $arr);
            static::assertCount(2, $detector->getAllUsedIndices());
        } else {
            static::assertCount(2, $arr);
            static::assertCount(4, $detector->getAllUsedIndices());
        }
    }

    public function testDoesNothingWithoutIndices(): void
    {
        $indices = $this->createMock(IndicesNamespace::class);
        $indices
            ->expects(static::exactly(0))
            
protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);
        $answer = $io->ask('Are you sure you want to reset the Elasticsearch indexing?', 'yes');

        if ($answer !== 'yes') {
            $io->error('Canceled clearing indexing process');

            return self::SUCCESS;
        }

        $indices = $this->detector->getAllUsedIndices();

        foreach ($indices as $index) {
            $this->client->indices()->delete(['index' => $index]);
        }

        $this->connection->executeStatement('TRUNCATE elasticsearch_index_task');

        try {
            $gateway = $this->gatewayRegistry->get(IncrementGatewayRegistry::MESSAGE_QUEUE_POOL);
            $gateway->reset('message_queue_stats', ElasticsearchIndexingMessage::class);
        } catch (IncrementGatewayNotFoundException) {
            
default => [
                'type' => 'keyword',
            ],
        };
    }

    /** * @param array<string, array<mixed>> $newCreatedFields */
    private function createNewFieldsInIndices(array $newCreatedFields): void
    {
        $indices = $this->indexDetector->getAllUsedIndices();

        $enabledMultilingualIndex = $this->elasticsearchHelper->enabledMultilingualIndex();
        $languageIds = $enabledMultilingualIndex ? $this->connection->fetchFirstColumn('SELECT LOWER(HEX(`id`)) FROM language') : [];

        foreach ($indices as $indexName) {
            // Check if index is old language based index             $isLanguageBasedIndex = true;

            $body = [
                'properties' => [
                    'customFields' => [
                        
Home | Imprint | This part of the site doesn't use cookies.