Skip to content

Commit

Permalink
invert behavior to provide safer defaults, resolve #27
Browse files Browse the repository at this point in the history
  • Loading branch information
limenet committed Apr 7, 2023
1 parent 3f13c49 commit 64ee315
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/Command/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Cleanup extends BaseCommand
{
protected const OPTION_ONLY_KNOWN = 'only-known';
protected const OPTION_ALL_IN_CLUSTER = 'all';

public function __construct(
protected ElasticsearchClient $esClient,
Expand All @@ -25,24 +25,24 @@ public function __construct(
protected function configure(): void
{
$this->setName(self::COMMAND_NAMESPACE . 'cleanup')
->setDescription('Deletes ALL Elasticsearch indices and aliases')
->setDescription('Deletes Elasticsearch indices and aliases known to (i.e. created by) the bundle')
->addOption(
self::OPTION_ONLY_KNOWN,
'k',
self::OPTION_ALL_IN_CLUSTER,
'a',
InputOption::VALUE_NONE,
'Delete only indices known to (i.e. created by) the bundle'
'Delete all indices in cluster including indices not created by this bundle but e.g. by Pimcore Enterprise features'
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->output->writeln(
$this->input->getOption(self::OPTION_ONLY_KNOWN) === true
? 'Only deleting KNOWN indices'
: 'Deleting ALL indices in the cluster'
$this->input->getOption(self::OPTION_ALL_IN_CLUSTER) === true
? 'Deleting ALL indices in the cluster'
: 'Only deleting KNOWN indices'
);
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Are you sure you want to delete all indices and aliases? (y/n)', false);
$question = new ConfirmationQuestion('Are you sure you want to proceed deleting indices and aliases? (y/N)', false);

if (!$helper->ask($input, $output, $question)) {
return self::FAILURE;
Expand All @@ -68,22 +68,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
*/
private function getIndices(): array
{
if ($this->input->getOption(self::OPTION_ONLY_KNOWN) === true) {
$indices = [];
if ($this->input->getOption(self::OPTION_ALL_IN_CLUSTER) === true) {
return $this->esClient->getCluster()->getIndexNames();
}

foreach ($this->indexRepository->flattened() as $indexConfig) {
if ($indexConfig->usesBlueGreenIndices()) {
$indices[] = $indexConfig->getBlueGreenActiveElasticaIndex()->getName();
$indices[] = $indexConfig->getBlueGreenInactiveElasticaIndex()->getName();
continue;
}
$indices = [];

$indices[] = $indexConfig->getName();
foreach ($this->indexRepository->flattened() as $indexConfig) {
if ($indexConfig->usesBlueGreenIndices()) {
$indices[] = $indexConfig->getBlueGreenActiveElasticaIndex()->getName();
$indices[] = $indexConfig->getBlueGreenInactiveElasticaIndex()->getName();
continue;
}

return $indices;
$indices[] = $indexConfig->getName();
}

return $this->esClient->getCluster()->getIndexNames();
return $indices;
}
}

0 comments on commit 64ee315

Please sign in to comment.