Add reseter service and command
This commit is contained in:
parent
02dd4d85cc
commit
15f24fcb59
|
@ -9,7 +9,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Output\Output;
|
use Symfony\Component\Console\Output\Output;
|
||||||
|
|
||||||
class CreateIndexesCommand extends BaseCommand
|
class ResetCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @see Command
|
* @see Command
|
||||||
|
@ -26,10 +26,10 @@ class CreateIndexesCommand extends BaseCommand
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
foreach ($this->container->get('foq_elastica.index_manager')->getAllIndexes() as $name => $index) {
|
$output->writeLn('Reset all indexes');
|
||||||
$output->writeLn(sprintf('Reset index "%s"', $name));
|
|
||||||
$index->delete();
|
$this->container->get('foq_elastica.reseter')->reset();
|
||||||
$index->create();
|
|
||||||
}
|
$output->writeln('Done');
|
||||||
}
|
}
|
||||||
}
|
}
|
29
Reseter.php
Normal file
29
Reseter.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FOQ\ElasticaBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes and recreates indexes
|
||||||
|
**/
|
||||||
|
class Reseter
|
||||||
|
{
|
||||||
|
protected $indexManager;
|
||||||
|
|
||||||
|
public function __construct(IndexManager $indexManager)
|
||||||
|
{
|
||||||
|
$this->indexManager = $indexManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets all indexes
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
**/
|
||||||
|
public function reset()
|
||||||
|
{
|
||||||
|
foreach ($this->indexManager->getAllIndexes() as $index) {
|
||||||
|
$index->delete();
|
||||||
|
$index->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,10 +13,14 @@
|
||||||
<services>
|
<services>
|
||||||
<service id="foq_elastica.index_manager" class="FOQ\ElasticaBundle\IndexManager">
|
<service id="foq_elastica.index_manager" class="FOQ\ElasticaBundle\IndexManager">
|
||||||
<argument /> <!-- indexes -->
|
<argument /> <!-- indexes -->
|
||||||
|
<argument /> <!-- default index -->
|
||||||
</service>
|
</service>
|
||||||
<service id="foq_elastica.populator" class="FOQ\ElasticaBundle\Populator">
|
<service id="foq_elastica.populator" class="FOQ\ElasticaBundle\Populator">
|
||||||
<argument /> <!-- providers -->
|
<argument /> <!-- providers -->
|
||||||
</service>
|
</service>
|
||||||
|
<service id="foq_elastica.reseter" class="FOQ\ElasticaBundle\Reseter">
|
||||||
|
<argument type="service" id="foq_elastica.index_manager" />
|
||||||
|
</service>
|
||||||
</services>
|
</services>
|
||||||
|
|
||||||
</container>
|
</container>
|
||||||
|
|
Loading…
Reference in a new issue