Fix populating command setting alias before population

This commit is contained in:
Tim Nagel 2014-06-27 15:08:08 +10:00
parent 474cbfa979
commit ad37a28356
3 changed files with 10 additions and 8 deletions

View file

@ -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[] */

View file

@ -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) {

View file

@ -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);
}
}