2011-04-13 00:14:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FOQ\ElasticaBundle;
|
|
|
|
|
2011-04-15 23:28:51 +02:00
|
|
|
use Elastica_Exception_Response;
|
|
|
|
|
2011-04-13 00:14:00 +02:00
|
|
|
/**
|
|
|
|
* 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) {
|
2011-04-15 23:28:51 +02:00
|
|
|
try {
|
|
|
|
$index->delete();
|
|
|
|
} catch (Elastica_Exception_Response $e) {
|
|
|
|
// The index does not exist
|
|
|
|
}
|
2011-04-13 00:14:00 +02:00
|
|
|
$index->create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|