Skip to content

Commit 396ff0e

Browse files
committed
Always use prefixed_name
1 parent 4c5f1fc commit 396ff0e

File tree

6 files changed

+16
-21
lines changed

6 files changed

+16
-21
lines changed

src/Command/IndexCommand.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,9 @@ public function __construct(SearchService $searchService)
2626
parent::__construct();
2727
}
2828

29-
protected function getIndices(): Collection
30-
{
31-
return (new Collection($this->searchService->getConfiguration()->get('indices')))
32-
->transform(function (array $item) {
33-
$item['name'] = $this->prefix.$item['name'];
34-
35-
return $item;
36-
});
37-
}
38-
3929
protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $output): Collection
4030
{
41-
$indices = $this->getIndices();
31+
$indices = new Collection($this->searchService->getConfiguration()->get('indices'));
4232
$indexNames = new Collection();
4333

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

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

6858
return $indices;

src/Command/MeilisearchClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3333

3434
/** @var array<string, mixed> $index */
3535
foreach ($indexToClear as $index) {
36-
$indexName = $index['name'];
36+
$indexName = $index['prefixed_name'];
3737
$className = $index['class'];
3838
$msg = "Cleared <info>$indexName</info> index of <comment>$className</comment>";
3939
$array = $this->searchService->clear($className);

src/Command/MeilisearchCreateCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8080
continue;
8181
}
8282

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

85-
$task = $this->searchClient->createIndex($index['name']);
85+
$output->writeln('<info>Creating index '.$indexName.' for '.$entityClassName.'</info>');
86+
87+
$task = $this->searchClient->createIndex($indexName);
8688
$this->searchClient->waitForTask($task['taskUid'], $responseTimeout);
8789

8890
if ($updateSettings) {
89-
$this->settingsUpdater->update($index['name'], $responseTimeout);
91+
$this->settingsUpdater->update($indexName, $responseTimeout);
9092
}
9193
}
9294

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

98-
private function entitiesToIndex($indexes): array
100+
private function entitiesToIndex(Collection $indexes): array
99101
{
100102
foreach ($indexes as $key => $index) {
101103
$entityClassName = $index['class'];

src/Command/MeilisearchDeleteCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3535

3636
/** @var array<string, mixed> $index */
3737
foreach ($indexToDelete as $index) {
38-
$indexName = $index['name'];
38+
$indexName = $index['prefixed_name'];
39+
3940
try {
4041
$this->searchService->deleteByIndexName($indexName);
4142
} catch (ApiException $e) {
4243
$output->writeln('Cannot delete '.$indexName.': '.$e->getMessage());
44+
4345
continue;
4446
}
47+
4548
$output->writeln('Deleted <info>'.$indexName.'</info>');
4649
}
4750

src/Command/MeilisearchImportCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private function formatIndexingResponse(array $batch, int $responseTimeout): arr
211211
return $formattedResponse;
212212
}
213213

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

241241
foreach ($indexes as $index) {
242242
$tempIndex = $index;
243-
$tempIndex['name'] = $prefix.$tempIndex['name'];
243+
$tempIndex['name'] = $prefix.$tempIndex['prefixed_name'];
244244
$pair = [$tempIndex['name'], $index['name']];
245245

246246
// Indexes must be declared only once during a swap

src/Command/MeilisearchUpdateSettingsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7777
return 0;
7878
}
7979

80-
private function entitiesToIndex($indexes): array
80+
private function entitiesToIndex(Collection $indexes): array
8181
{
8282
foreach ($indexes as $key => $index) {
8383
$entityClassName = $index['class'];

0 commit comments

Comments
 (0)