Skip to content

Commit

Permalink
improve cleanup & status commands
Browse files Browse the repository at this point in the history
  • Loading branch information
limenet committed Jan 29, 2024
1 parent 04a75f1 commit 3e5a67b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Command/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

class Cleanup extends BaseCommand
{
use NonBundleIndexTrait;
private const OPTION_ALL_IN_CLUSTER = 'all';

public function __construct(
Expand Down Expand Up @@ -54,8 +55,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$indices = $this->getIndices();

foreach ($indices as $index) {
if (!$this->shouldProcessNonBundleIndex($index)) {
continue;
}

$client = $this->esClient->getIndex($index);

if ($client->getSettings()->getBool('hidden')) {
continue;
}

foreach ($client->getAliases() as $alias) {
$client->removeAlias($alias);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Command/NonBundleIndexTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Valantic\ElasticaBridgeBundle\Command;

trait NonBundleIndexTrait
{
protected function shouldProcessNonBundleIndex(string $name): bool
{
return !in_array($name, ['.geoip_databases'], true);
}
}
3 changes: 2 additions & 1 deletion src/Command/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

class Status extends BaseCommand
{
use NonBundleIndexTrait;
/**
* @var array<int,array<int,mixed>>
*/
Expand Down Expand Up @@ -67,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$table->render();

foreach ($this->esClient->getCluster()->getIndexNames() as $indexName) {
if (in_array($indexName, $this->skipOtherIndices, true)) {
if (in_array($indexName, $this->skipOtherIndices, true) || !$this->shouldProcessNonBundleIndex($indexName)) {
continue;
}
$this->processOtherIndex($indexName);
Expand Down

0 comments on commit 3e5a67b

Please sign in to comment.