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) {
|
||||
$output->writeln(sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
|
||||
$this->resetter->resetIndex($index);
|
||||
$this->resetter->resetIndex($index, true);
|
||||
}
|
||||
|
||||
/** @var $providers ProviderInterface[] */
|
||||
|
|
|
@ -39,11 +39,13 @@ class AliasProcessor
|
|||
*/
|
||||
public function switchIndexAlias(IndexConfig $indexConfig, Index $index)
|
||||
{
|
||||
$client = $index->getClient();
|
||||
|
||||
$aliasName = $indexConfig->getElasticSearchName();
|
||||
$oldIndexName = false;
|
||||
$newIndexName = $index->getName();
|
||||
|
||||
$aliasedIndexes = $this->getAliasedIndexes($aliasName);
|
||||
$aliasedIndexes = $this->getAliasedIndexes($client, $aliasName);
|
||||
|
||||
if (count($aliasedIndexes) > 1) {
|
||||
throw new \RuntimeException(
|
||||
|
@ -71,7 +73,7 @@ class AliasProcessor
|
|||
);
|
||||
|
||||
try {
|
||||
$this->client->request('_aliases', 'POST', $aliasUpdateRequest);
|
||||
$client->request('_aliases', 'POST', $aliasUpdateRequest);
|
||||
} catch (ExceptionInterface $renameAliasException) {
|
||||
$additionalError = '';
|
||||
// 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
|
||||
if ($oldIndexName) {
|
||||
$oldIndex = new Index($this->client, $oldIndexName);
|
||||
$oldIndex = new Index($client, $oldIndexName);
|
||||
try {
|
||||
$oldIndex->delete();
|
||||
} catch (ExceptionInterface $deleteOldIndexException) {
|
||||
|
@ -117,9 +119,9 @@ class AliasProcessor
|
|||
* @param string $aliasName Alias name
|
||||
* @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();
|
||||
|
||||
foreach ($aliasesInfo as $indexName => $indexInfo) {
|
||||
|
|
|
@ -45,10 +45,10 @@ class Resetter
|
|||
/**
|
||||
* Deletes and recreates all indexes
|
||||
*/
|
||||
public function resetAllIndexes()
|
||||
public function resetAllIndexes($populating = false)
|
||||
{
|
||||
foreach ($this->configManager->getIndexNames() as $name) {
|
||||
$this->resetIndex($name);
|
||||
$this->resetIndex($name, $populating);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue