-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathSearchClearCommand.php
More file actions
48 lines (40 loc) · 1.6 KB
/
SearchClearCommand.php
File metadata and controls
48 lines (40 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Algolia\SearchBundle\Command;
use Algolia\SearchBundle\Responses\NullResponse;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* @internal
*/
#[AsCommand(name: 'search:clear')]
final class SearchClearCommand extends IndexCommand
{
protected function configure(): void
{
$this
->setDescription('Clear index (remove all data but keep index and settings)')
->addOption('indices', 'i', InputOption::VALUE_OPTIONAL, 'Comma-separated list of index names')
->addArgument(
'extra',
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
'Check your engine documentation for available options'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$indexToClear = $this->getEntitiesFromArgs($input, $output);
foreach ($indexToClear as $indexName => $className) {
$success = $this->searchService->clear($className);
if (!$success instanceof NullResponse) {
$output->writeln('Cleared <info>' . $indexName . '</info> index of <comment>' . $className . '</comment> ');
} else {
$output->writeln('<error>Index <info>' . $indexName . '</info> couldn\'t be cleared</error>');
}
}
$output->writeln('<info>Done!</info>');
return 0;
}
}