Skip to content

Commit

Permalink
Always use prefixed_name
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Oct 4, 2024
1 parent 4c5f1fc commit 396ff0e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
14 changes: 2 additions & 12 deletions src/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,9 @@ public function __construct(SearchService $searchService)
parent::__construct();
}

protected function getIndices(): Collection
{
return (new Collection($this->searchService->getConfiguration()->get('indices')))
->transform(function (array $item) {
$item['name'] = $this->prefix.$item['name'];

return $item;
});
}

protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $output): Collection
{
$indices = $this->getIndices();
$indices = new Collection($this->searchService->getConfiguration()->get('indices'));
$indexNames = new Collection();

if ($indexList = $input->getOption('indices')) {
Expand All @@ -62,7 +52,7 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
}

if (\count($indexNames) > 0) {
return $indices->reject(fn (array $item) => !\in_array($item['name'], $indexNames->all(), true));
return $indices->reject(fn (array $item) => !\in_array($item['prefixed_name'], $indexNames->all(), true));
}

return $indices;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MeilisearchClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/** @var array<string, mixed> $index */
foreach ($indexToClear as $index) {
$indexName = $index['name'];
$indexName = $index['prefixed_name'];
$className = $index['class'];
$msg = "Cleared <info>$indexName</info> index of <comment>$className</comment>";
$array = $this->searchService->clear($className);
Expand Down
10 changes: 6 additions & 4 deletions src/Command/MeilisearchCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}

$output->writeln('<info>Creating index '.$index['name'].' for '.$entityClassName.'</info>');
$indexName = $index['prefixed_name'];

$task = $this->searchClient->createIndex($index['name']);
$output->writeln('<info>Creating index '.$indexName.' for '.$entityClassName.'</info>');

$task = $this->searchClient->createIndex($indexName);
$this->searchClient->waitForTask($task['taskUid'], $responseTimeout);

if ($updateSettings) {
$this->settingsUpdater->update($index['name'], $responseTimeout);
$this->settingsUpdater->update($indexName, $responseTimeout);
}
}

Expand All @@ -95,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

private function entitiesToIndex($indexes): array
private function entitiesToIndex(Collection $indexes): array
{
foreach ($indexes as $key => $index) {
$entityClassName = $index['class'];
Expand Down
5 changes: 4 additions & 1 deletion src/Command/MeilisearchDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/** @var array<string, mixed> $index */
foreach ($indexToDelete as $index) {
$indexName = $index['name'];
$indexName = $index['prefixed_name'];

try {
$this->searchService->deleteByIndexName($indexName);
} catch (ApiException $e) {
$output->writeln('Cannot delete '.$indexName.': '.$e->getMessage());

continue;
}

$output->writeln('Deleted <info>'.$indexName.'</info>');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Command/MeilisearchImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private function formatIndexingResponse(array $batch, int $responseTimeout): arr
return $formattedResponse;
}

private function entitiesToIndex($indexes): array
private function entitiesToIndex(Collection $indexes): array
{
foreach ($indexes as $key => $index) {
$entityClassName = $index['class'];
Expand Down Expand Up @@ -240,7 +240,7 @@ private function swapIndices(Collection $indexes, string $prefix, OutputInterfac

foreach ($indexes as $index) {
$tempIndex = $index;
$tempIndex['name'] = $prefix.$tempIndex['name'];
$tempIndex['name'] = $prefix.$tempIndex['prefixed_name'];
$pair = [$tempIndex['name'], $index['name']];

// Indexes must be declared only once during a swap
Expand Down
2 changes: 1 addition & 1 deletion src/Command/MeilisearchUpdateSettingsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

private function entitiesToIndex($indexes): array
private function entitiesToIndex(Collection $indexes): array
{
foreach ($indexes as $key => $index) {
$entityClassName = $index['class'];
Expand Down

0 comments on commit 396ff0e

Please sign in to comment.