Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of index template support #916
� Conflicts: � tests/Unit/DependencyInjection/ConfigurationTest.php � tests/Unit/Elastica/ClientTest.php
- Loading branch information
Showing
36 changed files
with
1,529 additions
and
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSElasticaBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\ElasticaBundle\Command; | ||
|
||
use FOS\ElasticaBundle\Index\TemplateResetter; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
|
||
/** | ||
* Reset search indexes templates. | ||
*/ | ||
final class ResetTemplatesCommand extends Command | ||
{ | ||
protected static $defaultName = 'fos:elastica:reset-templates'; | ||
|
||
/** | ||
* Resetter | ||
* | ||
* @var TemplateResetter | ||
*/ | ||
private $resetter; | ||
|
||
public function __construct( | ||
TemplateResetter $resetter | ||
) { | ||
parent::__construct(); | ||
|
||
$this->resetter = $resetter; | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setName('fos:elastica:reset-templates') | ||
->addOption( | ||
'index', | ||
null, | ||
InputOption::VALUE_OPTIONAL, | ||
'The index template to reset. If no index template name specified than all templates will be reset', | ||
true | ||
) | ||
->addOption( | ||
'force-delete', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Delete all indexes that matches index templates patterns. ' . | ||
'Aware that pattern may match various indexes.' | ||
) | ||
->setDescription('Reset search indexes templates') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$indexTemplate = $input->hasParameterOption('--index') ? $input->getOption('index') : null; | ||
$deleteByPattern = (bool) $input->getOption('force-delete'); | ||
|
||
if ($deleteByPattern) { | ||
$helper = $this->getHelper('question'); | ||
$question = new ConfirmationQuestion('You are going to remove all template indexes. Are you sure?', false); | ||
if (!$helper->ask($input, $output, $question)) { | ||
return; | ||
} | ||
} | ||
|
||
if (is_string($indexTemplate)) { | ||
$output->writeln(sprintf('<info>Resetting template</info> <comment>%s</comment>', $indexTemplate)); | ||
$this->resetter->resetIndex($indexTemplate, $deleteByPattern); | ||
} else { | ||
$output->writeln('<info>Resetting all templates</info>'); | ||
$this->resetter->resetAllIndexes($deleteByPattern); | ||
} | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace FOS\ElasticaBundle\Configuration; | ||
|
||
/** | ||
* Interface Index config interface | ||
* | ||
* @author Dmitry Balabka <dmitry.balabka@intexsys.lv> | ||
*/ | ||
interface IndexConfigInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getElasticSearchName(); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getSettings(); | ||
|
||
/** | ||
* @param string $typeName | ||
* | ||
* @return TypeConfig | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function getType($typeName); | ||
|
||
/** | ||
* @return \FOS\ElasticaBundle\Configuration\TypeConfig[] | ||
*/ | ||
public function getTypes(); | ||
} |
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,96 @@ | ||
<?php | ||
/* | ||
* This file is part of the OpCart software. | ||
* | ||
* (c) 2015, OpticsPlanet, Inc | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\ElasticaBundle\Configuration; | ||
|
||
/** | ||
* Index configuration trait class | ||
* | ||
* @author Dmitry Balabka <dmitry.balabka@intexsys.lv> | ||
*/ | ||
trait IndexConfigTrait | ||
{ | ||
/** | ||
* The name of the index for ElasticSearch. | ||
* | ||
* @var string | ||
*/ | ||
protected $elasticSearchName; | ||
|
||
/** | ||
* The internal name of the index. May not be the same as the name used in ElasticSearch, | ||
* especially if aliases are enabled. | ||
* | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* An array of settings sent to ElasticSearch when creating the index. | ||
* | ||
* @var array | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* All types that belong to this index. | ||
* | ||
* @var TypeConfig[] | ||
*/ | ||
protected $types; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getElasticSearchName() | ||
{ | ||
return $this->elasticSearchName; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getSettings() | ||
{ | ||
return $this->settings; | ||
} | ||
|
||
/** | ||
* @param string $typeName | ||
* | ||
* @return TypeConfig | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function getType($typeName) | ||
{ | ||
if (!array_key_exists($typeName, $this->types)) { | ||
throw new \InvalidArgumentException(sprintf('Type "%s" does not exist on index "%s"', $typeName, $this->name)); | ||
} | ||
|
||
return $this->types[$typeName]; | ||
} | ||
|
||
/** | ||
* @return \FOS\ElasticaBundle\Configuration\TypeConfig[] | ||
*/ | ||
public function getTypes() | ||
{ | ||
return $this->types; | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace FOS\ElasticaBundle\Configuration; | ||
|
||
/** | ||
* Index template configuration class | ||
* | ||
* @author Dmitry Balabka <dmitry.balabka@intexsys.lv> | ||
*/ | ||
class IndexTemplateConfig implements IndexConfigInterface | ||
{ | ||
use IndexConfigTrait; | ||
|
||
/** | ||
* Index name pattern | ||
* | ||
* @var string | ||
*/ | ||
private $template; | ||
|
||
/** | ||
* Constructor expects an array as generated by the Container Configuration builder. | ||
* | ||
* @param string $name | ||
* @param TypeConfig[] $types | ||
* @param array $config | ||
*/ | ||
public function __construct($name, array $types, array $config) | ||
{ | ||
$this->elasticSearchName = isset($config['elasticSearchName']) ? $config['elasticSearchName'] : $name; | ||
$this->name = $name; | ||
$this->settings = isset($config['settings']) ? $config['settings'] : array(); | ||
if (!isset($config['template'])) { | ||
throw new \InvalidArgumentException('Index template value must be set'); | ||
} | ||
$this->template = $config['template']; | ||
$this->types = $types; | ||
} | ||
|
||
/** | ||
* Gets index name pattern | ||
* | ||
* @return string | ||
*/ | ||
public function getTemplate() | ||
{ | ||
return $this->template; | ||
} | ||
} |
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.