Fix populating command setting alias before population
This commit is contained in:
parent
474cbfa979
commit
ad37a28356
|
@ -111,7 +111,7 @@ class PopulateCommand extends ContainerAwareCommand
|
||||||
{
|
{
|
||||||
if ($reset) {
|
if ($reset) {
|
||||||
$output->writeln(sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
|
$output->writeln(sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
|
||||||
$this->resetter->resetIndex($index);
|
$this->resetter->resetIndex($index, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var $providers ProviderInterface[] */
|
/** @var $providers ProviderInterface[] */
|
||||||
|
|
|
@ -39,11 +39,13 @@ class AliasProcessor
|
||||||
*/
|
*/
|
||||||
public function switchIndexAlias(IndexConfig $indexConfig, Index $index)
|
public function switchIndexAlias(IndexConfig $indexConfig, Index $index)
|
||||||
{
|
{
|
||||||
|
$client = $index->getClient();
|
||||||
|
|
||||||
$aliasName = $indexConfig->getElasticSearchName();
|
$aliasName = $indexConfig->getElasticSearchName();
|
||||||
$oldIndexName = false;
|
$oldIndexName = false;
|
||||||
$newIndexName = $index->getName();
|
$newIndexName = $index->getName();
|
||||||
|
|
||||||
$aliasedIndexes = $this->getAliasedIndexes($aliasName);
|
$aliasedIndexes = $this->getAliasedIndexes($client, $aliasName);
|
||||||
|
|
||||||
if (count($aliasedIndexes) > 1) {
|
if (count($aliasedIndexes) > 1) {
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
|
@ -71,7 +73,7 @@ class AliasProcessor
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->client->request('_aliases', 'POST', $aliasUpdateRequest);
|
$client->request('_aliases', 'POST', $aliasUpdateRequest);
|
||||||
} catch (ExceptionInterface $renameAliasException) {
|
} catch (ExceptionInterface $renameAliasException) {
|
||||||
$additionalError = '';
|
$additionalError = '';
|
||||||
// if we failed to move the alias, delete the newly built index
|
// if we failed to move the alias, delete the newly built index
|
||||||
|
@ -96,7 +98,7 @@ class AliasProcessor
|
||||||
|
|
||||||
// Delete the old index after the alias has been switched
|
// Delete the old index after the alias has been switched
|
||||||
if ($oldIndexName) {
|
if ($oldIndexName) {
|
||||||
$oldIndex = new Index($this->client, $oldIndexName);
|
$oldIndex = new Index($client, $oldIndexName);
|
||||||
try {
|
try {
|
||||||
$oldIndex->delete();
|
$oldIndex->delete();
|
||||||
} catch (ExceptionInterface $deleteOldIndexException) {
|
} catch (ExceptionInterface $deleteOldIndexException) {
|
||||||
|
@ -117,9 +119,9 @@ class AliasProcessor
|
||||||
* @param string $aliasName Alias name
|
* @param string $aliasName Alias name
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getAliasedIndexes($aliasName)
|
private function getAliasedIndexes(Client $client, $aliasName)
|
||||||
{
|
{
|
||||||
$aliasesInfo = $this->client->request('_aliases', 'GET')->getData();
|
$aliasesInfo = $client->request('_aliases', 'GET')->getData();
|
||||||
$aliasedIndexes = array();
|
$aliasedIndexes = array();
|
||||||
|
|
||||||
foreach ($aliasesInfo as $indexName => $indexInfo) {
|
foreach ($aliasesInfo as $indexName => $indexInfo) {
|
||||||
|
|
|
@ -45,10 +45,10 @@ class Resetter
|
||||||
/**
|
/**
|
||||||
* Deletes and recreates all indexes
|
* Deletes and recreates all indexes
|
||||||
*/
|
*/
|
||||||
public function resetAllIndexes()
|
public function resetAllIndexes($populating = false)
|
||||||
{
|
{
|
||||||
foreach ($this->configManager->getIndexNames() as $name) {
|
foreach ($this->configManager->getIndexNames() as $name) {
|
||||||
$this->resetIndex($name);
|
$this->resetIndex($name, $populating);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue