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\Output;
|
||||
|
||||
class CreateIndexesCommand extends BaseCommand
|
||||
class ResetCommand extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* @see Command
|
||||
|
@ -26,10 +26,10 @@ class CreateIndexesCommand extends BaseCommand
|
|||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
foreach ($this->container->get('foq_elastica.index_manager')->getAllIndexes() as $name => $index) {
|
||||
$output->writeLn(sprintf('Reset index "%s"', $name));
|
||||
$index->delete();
|
||||
$index->create();
|
||||
}
|
||||
$output->writeLn('Reset all indexes');
|
||||
|
||||
$this->container->get('foq_elastica.reseter')->reset();
|
||||
|
||||
$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>
|
||||
<service id="foq_elastica.index_manager" class="FOQ\ElasticaBundle\IndexManager">
|
||||
<argument /> <!-- indexes -->
|
||||
<argument /> <!-- default index -->
|
||||
</service>
|
||||
<service id="foq_elastica.populator" class="FOQ\ElasticaBundle\Populator">
|
||||
<argument /> <!-- providers -->
|
||||
</service>
|
||||
<service id="foq_elastica.reseter" class="FOQ\ElasticaBundle\Reseter">
|
||||
<argument type="service" id="foq_elastica.index_manager" />
|
||||
</service>
|
||||
</services>
|
||||
|
||||
</container>
|
||||
|
|
Loading…
Reference in a new issue