This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
236 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Nord\Lumen\Elasticsearch\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Nord\Lumen\Elasticsearch\Contracts\ElasticsearchServiceContract; | ||
|
||
/** | ||
* Class SetIndexSettingsCommand | ||
* @package namespace Nord\Lumen\Elasticsearch\Console | ||
*/ | ||
class UpdateIndexSettingsCommand extends Command | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $signature = 'elastic:index:settings:update | ||
{ index : The name of the index to update } | ||
{--numReplicas= : The value of index.refresh_interval that should be set } | ||
{--refreshInterval= : The value of index.refresh_interval that should be set }'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Updates specified dynamic index settings for the specified index'; | ||
|
||
/** | ||
* @var ElasticsearchServiceContract | ||
*/ | ||
private $elasticsearchService; | ||
|
||
/** | ||
* SetIndexSettingsCommand constructor. | ||
* | ||
* @param ElasticsearchServiceContract $elasticsearchService | ||
*/ | ||
public function __construct(ElasticsearchServiceContract $elasticsearchService) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->elasticsearchService = $elasticsearchService; | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
$index = $this->input->getArgument('index'); | ||
$numReplicas = $this->input->getOption('numReplicas'); | ||
$refreshInterval = $this->input->getOption('refreshInterval'); | ||
|
||
$settings = []; | ||
|
||
if ($numReplicas !== null) { | ||
$settings['number_of_replicas'] = (int)$numReplicas; | ||
} | ||
|
||
if ($refreshInterval !== null) { | ||
$settings['refresh_interval'] = $refreshInterval; | ||
} | ||
|
||
if (!empty($settings)) { | ||
$this->putIndexSettings($index, $settings); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $index | ||
* @param array $settings | ||
*/ | ||
private function putIndexSettings(string $index, array $settings): void | ||
{ | ||
$this->elasticsearchService->indices()->putSettings([ | ||
'index' => $index, | ||
'body' => $settings, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.