From bbacad4bab2f6375a1bf9d841b7f64de17811047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20G=C3=A1bor?= Date: Tue, 10 Dec 2013 18:07:22 +0100 Subject: [PATCH 01/30] no-stop-on-error option added to populate command --- Command/PopulateCommand.php | 1 + Doctrine/AbstractProvider.php | 15 +++++++++++- Tests/Doctrine/AbstractProviderTest.php | 32 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) mode change 100755 => 100644 Command/PopulateCommand.php diff --git a/Command/PopulateCommand.php b/Command/PopulateCommand.php old mode 100755 new mode 100644 index 7297523..661f70d --- a/Command/PopulateCommand.php +++ b/Command/PopulateCommand.php @@ -45,6 +45,7 @@ class PopulateCommand extends ContainerAwareCommand ->addOption('offset', null, InputOption::VALUE_REQUIRED, 'Start indexing at offset', 0) ->addOption('sleep', null, InputOption::VALUE_REQUIRED, 'Sleep time between persisting iterations (microseconds)', 0) ->addOption('batch-size', null, InputOption::VALUE_REQUIRED, 'Index packet size (overrides provider config option)') + ->addOption('no-stop-on-error', null, InputOption::VALUE_NONE, 'Do not stop on errors') ->setDescription('Populates search indexes from providers') ; } diff --git a/Doctrine/AbstractProvider.php b/Doctrine/AbstractProvider.php index 1fb41f5..2346c80 100644 --- a/Doctrine/AbstractProvider.php +++ b/Doctrine/AbstractProvider.php @@ -3,6 +3,7 @@ namespace FOS\ElasticaBundle\Doctrine; use Doctrine\Common\Persistence\ManagerRegistry; +use Elastica\Exception\Bulk\ResponseException as BulkResponseException; use FOS\ElasticaBundle\Persister\ObjectPersisterInterface; use FOS\ElasticaBundle\Provider\AbstractProvider as BaseAbstractProvider; @@ -23,6 +24,7 @@ abstract class AbstractProvider extends BaseAbstractProvider parent::__construct($objectPersister, $objectClass, array_merge(array( 'clear_object_manager' => true, 'query_builder_method' => 'createQueryBuilder', + 'stop_on_error' => true, ), $options)); $this->managerRegistry = $managerRegistry; @@ -38,6 +40,7 @@ abstract class AbstractProvider extends BaseAbstractProvider $offset = isset($options['offset']) ? intval($options['offset']) : 0; $sleep = isset($options['sleep']) ? intval($options['sleep']) : 0; $batchSize = isset($options['batch-size']) ? intval($options['batch-size']) : $this->options['batch_size']; + $stopOnError = isset($options['no-stop-on-error']) ? empty($options['no-stop-on-error']) : $this->options['stop_on_error']; for (; $offset < $nbObjects; $offset += $batchSize) { if ($loggerClosure) { @@ -45,7 +48,17 @@ abstract class AbstractProvider extends BaseAbstractProvider } $objects = $this->fetchSlice($queryBuilder, $batchSize, $offset); - $this->objectPersister->insertMany($objects); + if (!$stopOnError) { + $this->objectPersister->insertMany($objects); + } else { + try { + $this->objectPersister->insertMany($objects); + } catch(BulkResponseException $e) { + if ($loggerClosure) { + $loggerClosure(sprintf('%s',$e->getMessage())); + } + } + } if ($this->options['clear_object_manager']) { $this->managerRegistry->getManagerForClass($this->objectClass)->clear(); diff --git a/Tests/Doctrine/AbstractProviderTest.php b/Tests/Doctrine/AbstractProviderTest.php index 0a9aceb..a3836bd 100644 --- a/Tests/Doctrine/AbstractProviderTest.php +++ b/Tests/Doctrine/AbstractProviderTest.php @@ -135,6 +135,28 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase $this->assertTrue($loggerClosureInvoked); } + public function testPopulateNotStopOnError() + { + $nbObjects = 1; + $objects = array(1); + + $provider = $this->getMockAbstractProvider(); + + $provider->expects($this->any()) + ->method('countObjects') + ->will($this->returnValue($nbObjects)); + + $provider->expects($this->any()) + ->method('fetchSlice') + ->will($this->returnValue($objects)); + + $this->objectPersister->expects($this->any()) + ->method('insertMany') + ->will($this->throwException($this->getMockBulkResponseException())); + + $provider->populate(null, array('no-stop-on-error' => true)); + } + /** * @return \FOS\ElasticaBundle\Doctrine\AbstractProvider|\PHPUnit_Framework_MockObject_MockObject */ @@ -148,6 +170,16 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase )); } + /** + * @return \Elastica\Exception\Bulk\ResponseException + */ + private function getMockBulkResponseException() + { + return $this->getMockBuilder('Elastica\Exception\Bulk\ResponseException') + ->disableOriginalConstructor() + ->getMock(); + } + /** * @return \Doctrine\Common\Persistence\ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject */ From 62dc3aaca04c1dc2fe62e763d8dde20d897d6f0d Mon Sep 17 00:00:00 2001 From: pkraeutli Date: Fri, 24 Jan 2014 14:20:10 +0100 Subject: [PATCH 02/30] Populate command: use isInteractive() instead of option --- Command/PopulateCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Command/PopulateCommand.php b/Command/PopulateCommand.php index 7297523..38bff70 100755 --- a/Command/PopulateCommand.php +++ b/Command/PopulateCommand.php @@ -67,10 +67,9 @@ class PopulateCommand extends ContainerAwareCommand $index = $input->getOption('index'); $type = $input->getOption('type'); $reset = $input->getOption('no-reset') ? false : true; - $noInteraction = $input->getOption('no-interaction'); $options = $input->getOptions(); - if (!$noInteraction && $reset && $input->getOption('offset')) { + if ($input->isInteractive() && $reset && $input->getOption('offset')) { /** @var DialogHelper $dialog */ $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, 'You chose to reset the index and start indexing with an offset. Do you really want to do that?', true)) { From 5e54dcd9558efe686523dae6e0d1cfc0662d429c Mon Sep 17 00:00:00 2001 From: Fabien Somnier Date: Thu, 30 Jan 2014 13:01:13 +0100 Subject: [PATCH 03/30] Add RAM (current & peak) in populate evolution information --- Doctrine/AbstractProvider.php | 5 ++++- Propel/Provider.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Doctrine/AbstractProvider.php b/Doctrine/AbstractProvider.php index 1fb41f5..eebfc79 100644 --- a/Doctrine/AbstractProvider.php +++ b/Doctrine/AbstractProvider.php @@ -54,11 +54,14 @@ abstract class AbstractProvider extends BaseAbstractProvider usleep($sleep); if ($loggerClosure) { + $memory = round(memory_get_usage() / (1024*1024),0); // to get usage in Mo + $memoryMax = round(memory_get_peak_usage() / (1024*1024)); // to get max usage in Mo + $message = '(RAM : current='.$memory.'Mo peak='.$memoryMax.'Mo)'; $stepNbObjects = count($objects); $stepCount = $stepNbObjects + $offset; $percentComplete = 100 * $stepCount / $nbObjects; $objectsPerSecond = $stepNbObjects / (microtime(true) - $stepStartTime); - $loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond)); + $loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s %s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond, $message)); } } } diff --git a/Propel/Provider.php b/Propel/Provider.php index c319691..3eb1c4f 100644 --- a/Propel/Provider.php +++ b/Propel/Provider.php @@ -37,11 +37,14 @@ class Provider extends AbstractProvider usleep($sleep); if ($loggerClosure) { + $memory = round(memory_get_usage() / (1024*1024),0); // to get usage in Mo + $memoryMax = round(memory_get_peak_usage() / (1024*1024)); // to get usage in Mo + $message = '(RAM : current='.$memory.'Mo peak='.$memoryMax.'Mo)'; $stepNbObjects = count($objects); $stepCount = $stepNbObjects + $offset; $percentComplete = 100 * $stepCount / $nbObjects; $objectsPerSecond = $stepNbObjects / (microtime(true) - $stepStartTime); - $loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond)); + $loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s %s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond, $message)); } } } From f348ebd0265aaa1d46e09c8aca5f6d646f27263c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=B6nthal?= Date: Mon, 3 Feb 2014 09:47:16 +0100 Subject: [PATCH 04/30] fixes ignore_missing option and unknown index --- Transformer/ElasticaToModelTransformerCollection.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Transformer/ElasticaToModelTransformerCollection.php b/Transformer/ElasticaToModelTransformerCollection.php index a261e81..f65f8db 100644 --- a/Transformer/ElasticaToModelTransformerCollection.php +++ b/Transformer/ElasticaToModelTransformerCollection.php @@ -67,7 +67,9 @@ class ElasticaToModelTransformerCollection implements ElasticaToModelTransformer $result = array(); foreach ($elasticaObjects as $object) { - $result[] = $transformed[$object->getType()][$object->getId()]; + if (array_key_exists($object->getId(), $transformed[$object->getType()])) { + $result[] = $transformed[$object->getType()][$object->getId()]; + } } return $result; From a121a777743525f46c65dc29d983c8eb92720664 Mon Sep 17 00:00:00 2001 From: Fabien Somnier Date: Mon, 3 Feb 2014 17:50:35 +0100 Subject: [PATCH 05/30] Avoid index reset error in case of unexistant index --- Command/PopulateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/PopulateCommand.php b/Command/PopulateCommand.php index 7297523..9d00db1 100755 --- a/Command/PopulateCommand.php +++ b/Command/PopulateCommand.php @@ -107,7 +107,7 @@ class PopulateCommand extends ContainerAwareCommand */ private function populateIndex(OutputInterface $output, $index, $reset, $options) { - if ($reset) { + if ($reset && $this->indexManager->getIndex($index)->exists()) { $output->writeln(sprintf('Resetting %s', $index)); $this->resetter->resetIndex($index); } From 48b785e8764a887f903cbb81476b4368f5588bd5 Mon Sep 17 00:00:00 2001 From: Fabien Somnier Date: Mon, 3 Feb 2014 18:12:20 +0100 Subject: [PATCH 06/30] New method getMemoryUsage to get RAM information message --- Doctrine/AbstractProvider.php | 5 +---- Propel/Provider.php | 5 +---- Provider/AbstractProvider.php | 12 ++++++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Doctrine/AbstractProvider.php b/Doctrine/AbstractProvider.php index eebfc79..796a5e4 100644 --- a/Doctrine/AbstractProvider.php +++ b/Doctrine/AbstractProvider.php @@ -54,14 +54,11 @@ abstract class AbstractProvider extends BaseAbstractProvider usleep($sleep); if ($loggerClosure) { - $memory = round(memory_get_usage() / (1024*1024),0); // to get usage in Mo - $memoryMax = round(memory_get_peak_usage() / (1024*1024)); // to get max usage in Mo - $message = '(RAM : current='.$memory.'Mo peak='.$memoryMax.'Mo)'; $stepNbObjects = count($objects); $stepCount = $stepNbObjects + $offset; $percentComplete = 100 * $stepCount / $nbObjects; $objectsPerSecond = $stepNbObjects / (microtime(true) - $stepStartTime); - $loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s %s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond, $message)); + $loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s %s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond, $this->getMemoryUsage())); } } } diff --git a/Propel/Provider.php b/Propel/Provider.php index 3eb1c4f..393beba 100644 --- a/Propel/Provider.php +++ b/Propel/Provider.php @@ -37,14 +37,11 @@ class Provider extends AbstractProvider usleep($sleep); if ($loggerClosure) { - $memory = round(memory_get_usage() / (1024*1024),0); // to get usage in Mo - $memoryMax = round(memory_get_peak_usage() / (1024*1024)); // to get usage in Mo - $message = '(RAM : current='.$memory.'Mo peak='.$memoryMax.'Mo)'; $stepNbObjects = count($objects); $stepCount = $stepNbObjects + $offset; $percentComplete = 100 * $stepCount / $nbObjects; $objectsPerSecond = $stepNbObjects / (microtime(true) - $stepStartTime); - $loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s %s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond, $message)); + $loggerClosure(sprintf('%0.1f%% (%d/%d), %d objects/s %s', $percentComplete, $stepCount, $nbObjects, $objectsPerSecond, $this->getMemoryUsage())); } } } diff --git a/Provider/AbstractProvider.php b/Provider/AbstractProvider.php index 06883a3..48da5d7 100644 --- a/Provider/AbstractProvider.php +++ b/Provider/AbstractProvider.php @@ -26,4 +26,16 @@ abstract class AbstractProvider implements ProviderInterface 'batch_size' => 100, ), $options); } + + /** + * Get string with RAM usage information (current and peak) + * + * @return string + */ + protected function getMemoryUsage() { + $memory = round(memory_get_usage() / (1024*1024),0); // to get usage in Mo + $memoryMax = round(memory_get_peak_usage() / (1024*1024)); // to get max usage in Mo + $message = '(RAM : current='.$memory.'Mo peak='.$memoryMax.'Mo)'; + return $message; + } } From 04390b37d1bacb16cce87384e0c33914ace7b967 Mon Sep 17 00:00:00 2001 From: tgallice Date: Tue, 4 Feb 2014 10:07:58 +0100 Subject: [PATCH 07/30] Force slash at the end of the url parameter --- DependencyInjection/Configuration.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 4ed88af..0c6ca82 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -101,7 +101,12 @@ class Configuration implements ConfigurationInterface ->arrayNode('servers') ->prototype('array') ->children() - ->scalarNode('url')->end() + ->scalarNode('url') + ->validate() + ->ifTrue(function($v) { return substr($v['url'], -1) !== '/'; }) + ->then(function($v) { return $v['url'].'/'; }) + ->end() + ->end() ->scalarNode('host')->end() ->scalarNode('port')->end() ->scalarNode('logger') From d04a403f71f82b46c3a3314031595b0c60b9dee9 Mon Sep 17 00:00:00 2001 From: Hung Tran Date: Tue, 4 Feb 2014 19:41:38 -0600 Subject: [PATCH 08/30] added support for setting search options --- Finder/FinderInterface.php | 3 ++- Finder/PaginatedFinderInterface.php | 6 ++++-- Finder/TransformedFinder.php | 23 +++++++++++++---------- Paginator/RawPaginatorAdapter.php | 10 ++++++++-- Paginator/TransformedPaginatorAdapter.php | 4 ++-- Repository.php | 16 ++++++++-------- 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Finder/FinderInterface.php b/Finder/FinderInterface.php index 4805d58..7c257de 100644 --- a/Finder/FinderInterface.php +++ b/Finder/FinderInterface.php @@ -9,7 +9,8 @@ interface FinderInterface * * @param mixed $query Can be a string, an array or an \Elastica\Query object * @param int $limit How many results to get + * @param array $options * @return array results */ - function find($query, $limit = null); + function find($query, $limit = null, $options = array()); } diff --git a/Finder/PaginatedFinderInterface.php b/Finder/PaginatedFinderInterface.php index 3581cda..fa10b70 100644 --- a/Finder/PaginatedFinderInterface.php +++ b/Finder/PaginatedFinderInterface.php @@ -12,15 +12,17 @@ interface PaginatedFinderInterface extends FinderInterface * Searches for query results and returns them wrapped in a paginator * * @param mixed $query Can be a string, an array or an \Elastica\Query object + * @param array $options * @return Pagerfanta paginated results */ - function findPaginated($query); + function findPaginated($query, $options = array()); /** * Creates a paginator adapter for this query * * @param mixed $query + * @param array $options * @return PaginatorAdapterInterface */ - function createPaginatorAdapter($query); + function createPaginatorAdapter($query, $options = array()); } diff --git a/Finder/TransformedFinder.php b/Finder/TransformedFinder.php index 4c8aa98..9080701 100644 --- a/Finder/TransformedFinder.php +++ b/Finder/TransformedFinder.php @@ -29,18 +29,19 @@ class TransformedFinder implements PaginatedFinderInterface * * @param string $query * @param integer $limit + * @param array $options * @return array of model objects **/ - public function find($query, $limit = null) + public function find($query, $limit = null, $options = array()) { - $results = $this->search($query, $limit); + $results = $this->search($query, $limit, $options); return $this->transformer->transform($results); } - public function findHybrid($query, $limit = null) + public function findHybrid($query, $limit = null, $options = array()) { - $results = $this->search($query, $limit); + $results = $this->search($query, $limit, $options); return $this->transformer->hybridTransform($results); } @@ -64,15 +65,16 @@ class TransformedFinder implements PaginatedFinderInterface /** * @param $query * @param null|int $limit + * @param array $options * @return array */ - protected function search($query, $limit = null) + protected function search($query, $limit = null, $options = array()) { $queryObject = Query::create($query); if (null !== $limit) { $queryObject->setSize($limit); } - $results = $this->searchable->search($queryObject)->getResults(); + $results = $this->searchable->search($queryObject, $options)->getResults(); return $results; } @@ -81,12 +83,13 @@ class TransformedFinder implements PaginatedFinderInterface * Gets a paginator wrapping the result of a search * * @param string $query + * @param array $options * @return Pagerfanta */ - public function findPaginated($query) + public function findPaginated($query, $options = array()) { $queryObject = Query::create($query); - $paginatorAdapter = $this->createPaginatorAdapter($queryObject); + $paginatorAdapter = $this->createPaginatorAdapter($queryObject, $options); return new Pagerfanta(new FantaPaginatorAdapter($paginatorAdapter)); } @@ -94,10 +97,10 @@ class TransformedFinder implements PaginatedFinderInterface /** * {@inheritdoc} */ - public function createPaginatorAdapter($query) + public function createPaginatorAdapter($query, $options = array()) { $query = Query::create($query); - return new TransformedPaginatorAdapter($this->searchable, $query, $this->transformer); + return new TransformedPaginatorAdapter($this->searchable, $query, $options, $this->transformer); } } diff --git a/Paginator/RawPaginatorAdapter.php b/Paginator/RawPaginatorAdapter.php index d4b5357..e99746f 100644 --- a/Paginator/RawPaginatorAdapter.php +++ b/Paginator/RawPaginatorAdapter.php @@ -22,6 +22,11 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface */ private $query; + /** + * @var array search options + */ + private $options; + /** * @var integer the number of hits */ @@ -38,10 +43,11 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface * @param SearchableInterface $searchable the object to search in * @param Query $query the query to search */ - public function __construct(SearchableInterface $searchable, Query $query) + public function __construct(SearchableInterface $searchable, Query $query, array $options = array()) { $this->searchable = $searchable; $this->query = $query; + $this->options = $options; } /** @@ -72,7 +78,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface $query->setFrom($offset); $query->setSize($itemCountPerPage); - $resultSet = $this->searchable->search($query); + $resultSet = $this->searchable->search($query, $this->options); $this->totalHits = $resultSet->getTotalHits(); $this->facets = $resultSet->getFacets(); return $resultSet; diff --git a/Paginator/TransformedPaginatorAdapter.php b/Paginator/TransformedPaginatorAdapter.php index 7bc038a..10976f7 100644 --- a/Paginator/TransformedPaginatorAdapter.php +++ b/Paginator/TransformedPaginatorAdapter.php @@ -18,9 +18,9 @@ class TransformedPaginatorAdapter extends RawPaginatorAdapter * @param Query $query the query to search * @param ElasticaToModelTransformerInterface $transformer the transformer for fetching the results */ - public function __construct(SearchableInterface $searchable, Query $query, ElasticaToModelTransformerInterface $transformer) + public function __construct(SearchableInterface $searchable, Query $query, array $options = array(), ElasticaToModelTransformerInterface $transformer) { - parent::__construct($searchable, $query); + parent::__construct($searchable, $query, $options); $this->transformer = $transformer; } diff --git a/Repository.php b/Repository.php index 413f1e4..70b2a21 100644 --- a/Repository.php +++ b/Repository.php @@ -19,23 +19,23 @@ class Repository $this->finder = $finder; } - public function find($query, $limit=null) + public function find($query, $limit = null, $options = array()) { - return $this->finder->find($query, $limit); + return $this->finder->find($query, $limit, $options); } - public function findHybrid($query, $limit=null) + public function findHybrid($query, $limit = null, $options = array()) { - return $this->finder->findHybrid($query, $limit); + return $this->finder->findHybrid($query, $limit, $options); } - public function findPaginated($query) + public function findPaginated($query, $options = array()) { - return $this->finder->findPaginated($query); + return $this->finder->findPaginated($query, $options); } - public function createPaginatorAdapter($query) + public function createPaginatorAdapter($query, $options = array()) { - return $this->finder->createPaginatorAdapter($query); + return $this->finder->createPaginatorAdapter($query, $options); } } From 5be3a8c22ea9577f12200b42b14318899c1260de Mon Sep 17 00:00:00 2001 From: Hung Tran Date: Wed, 5 Feb 2014 11:21:14 -0600 Subject: [PATCH 09/30] added query string to collector and updated tests --- Client.php | 2 +- Logger/ElasticaLogger.php | 6 ++++-- Resources/views/Collector/elastica.html.twig | 3 ++- Tests/ClientTest.php | 1 + Tests/Logger/ElasticaLoggerTest.php | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Client.php b/Client.php index ea0c572..7719095 100644 --- a/Client.php +++ b/Client.php @@ -27,7 +27,7 @@ class Client extends ElasticaClient 'transport' => $connection->getTransport(), ); - $this->_logger->logQuery($path, $method, $data, $time, $connection_array); + $this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query); } return $response; diff --git a/Logger/ElasticaLogger.php b/Logger/ElasticaLogger.php index 7aacac5..60f28db 100644 --- a/Logger/ElasticaLogger.php +++ b/Logger/ElasticaLogger.php @@ -37,10 +37,11 @@ class ElasticaLogger implements LoggerInterface * @param string $path Path to call * @param string $method Rest method to use (GET, POST, DELETE, PUT) * @param array $data arguments + * @param array $query arguments * @param float $time execution time * @param array $connection host, port and transport of the query */ - public function logQuery($path, $method, $data, $time, $connection = array()) + public function logQuery($path, $method, $data, $time, $connection = array(), $query = array()) { if ($this->debug) { $this->queries[] = array( @@ -48,7 +49,8 @@ class ElasticaLogger implements LoggerInterface 'method' => $method, 'data' => $data, 'executionMS' => $time, - 'connection' => $connection + 'connection' => $connection, + 'queryString' => $query, ); } diff --git a/Resources/views/Collector/elastica.html.twig b/Resources/views/Collector/elastica.html.twig index 0eb50a6..637dae7 100644 --- a/Resources/views/Collector/elastica.html.twig +++ b/Resources/views/Collector/elastica.html.twig @@ -44,6 +44,7 @@ {% for key, query in collector.queries %}
  • Path: {{ query.path }}
    + Query: {{ query.queryString|url_encode }}
    Method: {{ query.method }} ({{ query.connection.transport }} on {{ query.connection.host }}:{{ query.connection.port }})
    {{ query.data|json_encode }} @@ -60,7 +61,7 @@ {% endif %}
  • diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index c8509cf..8a9d91a 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -24,6 +24,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase Request::GET, $this->isType('array'), $this->isType('float'), + $this->isType('array'), $this->isType('array') ); diff --git a/Tests/Logger/ElasticaLoggerTest.php b/Tests/Logger/ElasticaLoggerTest.php index 30ce30c..96adf53 100644 --- a/Tests/Logger/ElasticaLoggerTest.php +++ b/Tests/Logger/ElasticaLoggerTest.php @@ -70,6 +70,7 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase $data = array('data'); $time = 12; $connection = array('host' => 'localhost', 'port' => '8999', 'transport' => 'https'); + $query = array('search_type' => 'dfs_query_then_fetch'); $expected = array( 'path' => $path, @@ -77,9 +78,10 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase 'data' => $data, 'executionMS' => $time, 'connection' => $connection, + 'queryString' => $query, ); - $elasticaLogger->logQuery($path, $method, $data, $time, $connection); + $elasticaLogger->logQuery($path, $method, $data, $time, $connection, $query); $returnedQueries = $elasticaLogger->getQueries(); $this->assertEquals($expected, $returnedQueries[0]); } From 1402bdc9e63911510e093d22deb7b8290856719c Mon Sep 17 00:00:00 2001 From: Lea Haensenberger Date: Thu, 13 Feb 2014 09:11:05 +0100 Subject: [PATCH 10/30] Keep all special mapping fields for types when resetting a single type. Field list is according to the current documentation of elasticsearch 0.90 --- Resetter.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Resetter.php b/Resetter.php index 26a6bb5..d0f3014 100644 --- a/Resetter.php +++ b/Resetter.php @@ -74,12 +74,11 @@ class Resetter { $mapping = Mapping::create($indexConfig['properties']); - if (isset($indexConfig['_parent'])) { - $mapping->setParam('_parent', array('type' => $indexConfig['_parent']['type'])); - } - - if (isset($indexConfig['dynamic_templates'])) { - $mapping->setParam('dynamic_templates', $indexConfig['dynamic_templates']); + $mappingSpecialFields = array('_uid', '_id', '_source', '_all', '_analyzer', '_boost', '_parent', '_routing', '_index', '_size', '_timestamp', '_ttl'); + foreach ($mappingSpecialFields as $specialField) { + if (isset($indexConfig[$specialField])) { + $mapping->setParam($specialField, $indexConfig[$specialField]); + } } return $mapping; From ead3c95c88ed11756d0fdfbf11f9c7a8dfe84271 Mon Sep 17 00:00:00 2001 From: Lea Haensenberger Date: Thu, 13 Feb 2014 09:45:27 +0100 Subject: [PATCH 11/30] Keep dynamic templates --- Resetter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resetter.php b/Resetter.php index d0f3014..d193c9d 100644 --- a/Resetter.php +++ b/Resetter.php @@ -74,7 +74,7 @@ class Resetter { $mapping = Mapping::create($indexConfig['properties']); - $mappingSpecialFields = array('_uid', '_id', '_source', '_all', '_analyzer', '_boost', '_parent', '_routing', '_index', '_size', '_timestamp', '_ttl'); + $mappingSpecialFields = array('_uid', '_id', '_source', '_all', '_analyzer', '_boost', '_parent', '_routing', '_index', '_size', '_timestamp', '_ttl', 'dynamic_templates'); foreach ($mappingSpecialFields as $specialField) { if (isset($indexConfig[$specialField])) { $mapping->setParam($specialField, $indexConfig[$specialField]); From 765e400278fff2e59030e47bdead2f8240ef1fef Mon Sep 17 00:00:00 2001 From: Lea Haensenberger Date: Thu, 13 Feb 2014 10:06:10 +0100 Subject: [PATCH 12/30] handle _parent separately --- Resetter.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Resetter.php b/Resetter.php index d193c9d..69620a2 100644 --- a/Resetter.php +++ b/Resetter.php @@ -74,13 +74,17 @@ class Resetter { $mapping = Mapping::create($indexConfig['properties']); - $mappingSpecialFields = array('_uid', '_id', '_source', '_all', '_analyzer', '_boost', '_parent', '_routing', '_index', '_size', '_timestamp', '_ttl', 'dynamic_templates'); + $mappingSpecialFields = array('_uid', '_id', '_source', '_all', '_analyzer', '_boost', '_routing', '_index', '_size', '_timestamp', '_ttl', 'dynamic_templates'); foreach ($mappingSpecialFields as $specialField) { if (isset($indexConfig[$specialField])) { $mapping->setParam($specialField, $indexConfig[$specialField]); } } + if (isset($indexConfig['_parent'])) { + $mapping->setParam('_parent', array('type' => $indexConfig['_parent']['type'])); + } + return $mapping; } From 3065c96a2ca51ec03f5aa32877a75079faa8b413 Mon Sep 17 00:00:00 2001 From: Patrick McAndrew Date: Fri, 14 Feb 2014 17:32:22 +0000 Subject: [PATCH 13/30] Add ability to specify server timeout --- DependencyInjection/Configuration.php | 1 + 1 file changed, 1 insertion(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 79cadf2..b2a1756 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -102,6 +102,7 @@ class Configuration implements ConfigurationInterface ->scalarNode('url')->end() ->scalarNode('host')->end() ->scalarNode('port')->end() + ->scalarNode('timeout')->end() ->end() ->end() ->end() From 7d2776e27aad52dc7808a5db55e795b436790aef Mon Sep 17 00:00:00 2001 From: Hung Tran Date: Tue, 18 Feb 2014 10:12:31 -0600 Subject: [PATCH 14/30] fixed phpdoc --- Logger/ElasticaLogger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Logger/ElasticaLogger.php b/Logger/ElasticaLogger.php index 60f28db..0e0a9c0 100644 --- a/Logger/ElasticaLogger.php +++ b/Logger/ElasticaLogger.php @@ -37,9 +37,9 @@ class ElasticaLogger implements LoggerInterface * @param string $path Path to call * @param string $method Rest method to use (GET, POST, DELETE, PUT) * @param array $data arguments - * @param array $query arguments * @param float $time execution time * @param array $connection host, port and transport of the query + * @param array $query arguments */ public function logQuery($path, $method, $data, $time, $connection = array(), $query = array()) { From b8cc6d758c3fb8a6397184bb423deebbae38208b Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Wed, 19 Feb 2014 09:31:22 +0100 Subject: [PATCH 15/30] CS fix in AbstractProvider --- Provider/AbstractProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Provider/AbstractProvider.php b/Provider/AbstractProvider.php index 48da5d7..8f5ad60 100644 --- a/Provider/AbstractProvider.php +++ b/Provider/AbstractProvider.php @@ -32,10 +32,12 @@ abstract class AbstractProvider implements ProviderInterface * * @return string */ - protected function getMemoryUsage() { + protected function getMemoryUsage() + { $memory = round(memory_get_usage() / (1024*1024),0); // to get usage in Mo $memoryMax = round(memory_get_peak_usage() / (1024*1024)); // to get max usage in Mo $message = '(RAM : current='.$memory.'Mo peak='.$memoryMax.'Mo)'; + return $message; } } From 41bf07ec5995e47d95fb4b01d0434eb04e283680 Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Wed, 19 Feb 2014 11:01:54 +0100 Subject: [PATCH 16/30] Fixed issues in #426 --- Command/PopulateCommand.php | 4 +++- Doctrine/AbstractProvider.php | 6 +++--- Tests/Doctrine/AbstractProviderTest.php | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Command/PopulateCommand.php b/Command/PopulateCommand.php index 07badd7..b13ddc3 100644 --- a/Command/PopulateCommand.php +++ b/Command/PopulateCommand.php @@ -45,7 +45,7 @@ class PopulateCommand extends ContainerAwareCommand ->addOption('offset', null, InputOption::VALUE_REQUIRED, 'Start indexing at offset', 0) ->addOption('sleep', null, InputOption::VALUE_REQUIRED, 'Sleep time between persisting iterations (microseconds)', 0) ->addOption('batch-size', null, InputOption::VALUE_REQUIRED, 'Index packet size (overrides provider config option)') - ->addOption('no-stop-on-error', null, InputOption::VALUE_NONE, 'Do not stop on errors') + ->addOption('ignore-errors', null, InputOption::VALUE_NONE, 'Do not stop on errors') ->setDescription('Populates search indexes from providers') ; } @@ -70,6 +70,8 @@ class PopulateCommand extends ContainerAwareCommand $reset = $input->getOption('no-reset') ? false : true; $options = $input->getOptions(); + $options['ignore-errors'] = $input->hasOption('ignore-errors'); + if ($input->isInteractive() && $reset && $input->getOption('offset')) { /** @var DialogHelper $dialog */ $dialog = $this->getHelperSet()->get('dialog'); diff --git a/Doctrine/AbstractProvider.php b/Doctrine/AbstractProvider.php index 109cfa0..9d1575c 100644 --- a/Doctrine/AbstractProvider.php +++ b/Doctrine/AbstractProvider.php @@ -23,8 +23,8 @@ abstract class AbstractProvider extends BaseAbstractProvider { parent::__construct($objectPersister, $objectClass, array_merge(array( 'clear_object_manager' => true, + 'ignore_errors' => false, 'query_builder_method' => 'createQueryBuilder', - 'stop_on_error' => true, ), $options)); $this->managerRegistry = $managerRegistry; @@ -40,7 +40,7 @@ abstract class AbstractProvider extends BaseAbstractProvider $offset = isset($options['offset']) ? intval($options['offset']) : 0; $sleep = isset($options['sleep']) ? intval($options['sleep']) : 0; $batchSize = isset($options['batch-size']) ? intval($options['batch-size']) : $this->options['batch_size']; - $stopOnError = isset($options['no-stop-on-error']) ? empty($options['no-stop-on-error']) : $this->options['stop_on_error']; + $ignoreErrors = isset($options['ignore-errors']) ? $options['ignore-errors'] : $this->options['ignore_errors']; for (; $offset < $nbObjects; $offset += $batchSize) { if ($loggerClosure) { @@ -48,7 +48,7 @@ abstract class AbstractProvider extends BaseAbstractProvider } $objects = $this->fetchSlice($queryBuilder, $batchSize, $offset); - if (!$stopOnError) { + if (!$ignoreErrors) { $this->objectPersister->insertMany($objects); } else { try { diff --git a/Tests/Doctrine/AbstractProviderTest.php b/Tests/Doctrine/AbstractProviderTest.php index a3836bd..2492eed 100644 --- a/Tests/Doctrine/AbstractProviderTest.php +++ b/Tests/Doctrine/AbstractProviderTest.php @@ -154,7 +154,9 @@ class AbstractProviderTest extends \PHPUnit_Framework_TestCase ->method('insertMany') ->will($this->throwException($this->getMockBulkResponseException())); - $provider->populate(null, array('no-stop-on-error' => true)); + $this->setExpectedException('Elastica\Exception\Bulk\ResponseException'); + + $provider->populate(null, array('ignore-errors' => false)); } /** From 44180793fcef2b15671d2d75364c69154dc6e447 Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Wed, 19 Feb 2014 12:29:51 +0100 Subject: [PATCH 17/30] Add changelog file for 3.0 --- CHANGELOG-3.0.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 CHANGELOG-3.0.md diff --git a/CHANGELOG-3.0.md b/CHANGELOG-3.0.md new file mode 100644 index 0000000..534a25e --- /dev/null +++ b/CHANGELOG-3.0.md @@ -0,0 +1,17 @@ +CHANGELOG for 3.0.x +=================== + +This changelog references the relevant changes (bug and security fixes) done +in 3.0 minor versions. + +To get the diff for a specific change, go to +https://github.com/FriendsOfSymfony/FOSElasticaBundle/commit/XXX where XXX is +the commit hash. To get the diff between two versions, go to +https://github.com/FriendsOfSymfony/FOSElasticaBundle/compare/v3.0.0...v3.0.1 + +To generate a changelog summary since the last version, run +`git log --no-merges --oneline v3.0.0...3.0.x` + +* 3.0.0-ALPHA2 (2014-xx-xx) + + * 41bf07e: Renamed the `no-stop-on-error` option in PopulateCommand to `ignore-errors` From 63cca11a0b0a0a89f368d71a5afcb3944800d2eb Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Wed, 19 Feb 2014 12:43:44 +0100 Subject: [PATCH 18/30] Tweak: use hasOption() in PopulateCommand instead of checking for booleans --- Command/PopulateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/PopulateCommand.php b/Command/PopulateCommand.php index b13ddc3..7d8a46e 100644 --- a/Command/PopulateCommand.php +++ b/Command/PopulateCommand.php @@ -67,7 +67,7 @@ class PopulateCommand extends ContainerAwareCommand { $index = $input->getOption('index'); $type = $input->getOption('type'); - $reset = $input->getOption('no-reset') ? false : true; + $reset = $input->hasOption('no-reset'); $options = $input->getOptions(); $options['ignore-errors'] = $input->hasOption('ignore-errors'); From 891dd51abebcdeaaa7ac4de017a8ef0a5868fa42 Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Wed, 19 Feb 2014 12:50:48 +0100 Subject: [PATCH 19/30] Fixed bug made in #479 --- Command/PopulateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/PopulateCommand.php b/Command/PopulateCommand.php index 7d8a46e..afed5ed 100644 --- a/Command/PopulateCommand.php +++ b/Command/PopulateCommand.php @@ -67,7 +67,7 @@ class PopulateCommand extends ContainerAwareCommand { $index = $input->getOption('index'); $type = $input->getOption('type'); - $reset = $input->hasOption('no-reset'); + $reset = !$input->hasOption('no-reset'); $options = $input->getOptions(); $options['ignore-errors'] = $input->hasOption('ignore-errors'); From 1c74f61b4ef5cf1b2d1c9b83c5814f173d7edddf Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Wed, 19 Feb 2014 12:58:02 +0100 Subject: [PATCH 20/30] AbstractProvider cleanup --- Provider/AbstractProvider.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Provider/AbstractProvider.php b/Provider/AbstractProvider.php index 8f5ad60..2761a25 100644 --- a/Provider/AbstractProvider.php +++ b/Provider/AbstractProvider.php @@ -4,10 +4,24 @@ namespace FOS\ElasticaBundle\Provider; use FOS\ElasticaBundle\Persister\ObjectPersisterInterface; +/** + * AbstractProvider + */ abstract class AbstractProvider implements ProviderInterface { - protected $objectClass; + /** + * @var ObjectPersisterInterface + */ protected $objectPersister; + + /** + * @var string + */ + protected $objectClass; + + /** + * @var array + */ protected $options; /** @@ -34,10 +48,9 @@ abstract class AbstractProvider implements ProviderInterface */ protected function getMemoryUsage() { - $memory = round(memory_get_usage() / (1024*1024),0); // to get usage in Mo - $memoryMax = round(memory_get_peak_usage() / (1024*1024)); // to get max usage in Mo - $message = '(RAM : current='.$memory.'Mo peak='.$memoryMax.'Mo)'; + $memory = round(memory_get_usage() / (1024 * 1024)); // to get usage in Mo + $memoryMax = round(memory_get_peak_usage() / (1024 * 1024)); // to get max usage in Mo - return $message; + return sprintf('(RAM : current=%uMo peak=%uMo)', $memory, $memoryMax); } } From 6f8b3a5a0f028edfb99ad714b0c448c05c36ca00 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 21 Feb 2014 08:58:43 +1100 Subject: [PATCH 21/30] Fix populate command option --- Command/PopulateCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/PopulateCommand.php b/Command/PopulateCommand.php index afed5ed..a67df94 100644 --- a/Command/PopulateCommand.php +++ b/Command/PopulateCommand.php @@ -67,7 +67,7 @@ class PopulateCommand extends ContainerAwareCommand { $index = $input->getOption('index'); $type = $input->getOption('type'); - $reset = !$input->hasOption('no-reset'); + $reset = !$input->getOption('no-reset'); $options = $input->getOptions(); $options['ignore-errors'] = $input->hasOption('ignore-errors'); From eecdd3474a2ddb2b46dc98fffc4b4bb641dfaed6 Mon Sep 17 00:00:00 2001 From: Matteo Galli Date: Fri, 21 Feb 2014 16:47:42 +0100 Subject: [PATCH 22/30] Fixes #459 --- DependencyInjection/FOSElasticaExtension.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DependencyInjection/FOSElasticaExtension.php b/DependencyInjection/FOSElasticaExtension.php index 52070fd..96e1fdf 100644 --- a/DependencyInjection/FOSElasticaExtension.php +++ b/DependencyInjection/FOSElasticaExtension.php @@ -4,6 +4,7 @@ namespace FOS\ElasticaBundle\DependencyInjection; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\DefinitionDecorator; @@ -198,6 +199,10 @@ class FOSElasticaExtension extends Extension if (isset($type['serializer']['version'])) { $callbackDef->addMethodCall('setVersion', array($type['serializer']['version'])); } + $callbackClassImplementedInterfaces = class_implements($this->serializerConfig['callback_class']); // PHP < 5.4 friendly + if (isset($callbackClassImplementedInterfaces['Symfony\Component\DependencyInjection\ContainerAwareInterface'])) { + $callbackDef->addMethodCall('setContainer', array(new Reference('service_container'))); + } $container->setDefinition($callbackId, $callbackDef); From 2b04f6cf34807854226794ff78dd3f4f207f73ed Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Tue, 25 Feb 2014 11:05:26 +0100 Subject: [PATCH 23/30] ElasticaLogger cleanup --- Logger/ElasticaLogger.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Logger/ElasticaLogger.php b/Logger/ElasticaLogger.php index 0e0a9c0..5b1269f 100644 --- a/Logger/ElasticaLogger.php +++ b/Logger/ElasticaLogger.php @@ -14,32 +14,42 @@ use Psr\Log\LoggerInterface; */ class ElasticaLogger implements LoggerInterface { + /** + * @var LoggerInterface + */ protected $logger; - protected $queries; + + /** + * @var array + */ + protected $queries = array(); + + /** + * @var boolean + */ protected $debug; /** * Constructor. * * @param LoggerInterface|null $logger The Symfony logger - * @param bool $debug + * @param boolean $debug */ public function __construct(LoggerInterface $logger = null, $debug = false) { $this->logger = $logger; - $this->queries = array(); $this->debug = $debug; } /** * Logs a query. * - * @param string $path Path to call - * @param string $method Rest method to use (GET, POST, DELETE, PUT) - * @param array $data arguments - * @param float $time execution time - * @param array $connection host, port and transport of the query - * @param array $query arguments + * @param string $path Path to call + * @param string $method Rest method to use (GET, POST, DELETE, PUT) + * @param array $data Arguments + * @param float $time Execution time + * @param array $connection Host, port and transport of the query + * @param array $query Arguments */ public function logQuery($path, $method, $data, $time, $connection = array(), $query = array()) { From 418b9d72cec839d1b5f2dcb73cbd83bdd276bdbe Mon Sep 17 00:00:00 2001 From: tgallice Date: Tue, 4 Mar 2014 17:54:49 +0100 Subject: [PATCH 24/30] Rework configuration validation to fix #461 --- DependencyInjection/Configuration.php | 4 ++-- .../DependencyInjection/ConfigurationTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 107744d..4488bf2 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -103,8 +103,8 @@ class Configuration implements ConfigurationInterface ->children() ->scalarNode('url') ->validate() - ->ifTrue(function($v) { return substr($v['url'], -1) !== '/'; }) - ->then(function($v) { return $v['url'].'/'; }) + ->ifTrue(function($url) { return substr($url, -1) !== '/'; }) + ->then(function($url) { return $url.'/'; }) ->end() ->end() ->scalarNode('host')->end() diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 35b2af3..0f0d374 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -3,6 +3,7 @@ namespace FOS\ElasticaBundle\Tests\Resetter\DependencyInjection; use FOS\ElasticaBundle\DependencyInjection\Configuration; +use Symfony\Component\Config\Definition\Processor; /** * ConfigurationTest @@ -85,4 +86,21 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Symfony\Component\Config\Definition\ScalarNode', $mapping['index']); $this->assertNull($mapping['index']->getDefaultValue()); } + + public function testSlashIsAddedAtTheEndOfServerUrl() + { + $config = array( + 'clients' => array( + 'default' => array( + 'url' => 'http://www.github.com', + ), + ), + ); + + $processor = new Processor(); + + $configuration = $processor->processConfiguration($this->configuration, array($config)); + + $this->assertEquals('http://www.github.com/', $configuration['clients']['default']['servers'][0]['url']); + } } From a1f7449efc7e8190726812f987e6cba98e4bccbe Mon Sep 17 00:00:00 2001 From: Bastien Jaillot Date: Wed, 5 Mar 2014 15:59:38 +0100 Subject: [PATCH 25/30] [doc] inform about the override of Elastica logger Add a documentation related to this change: https://github.com/FriendsOfSymfony/FOSElasticaBundle/pull/395#issuecomment-27729759 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f78c97f..aaaf0a5 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ Most of the time, you will need only one. clients: default: { host: localhost, port: 9200 } +A client configuration can also override the Elastica logger to change the used class ```logger: ``` or to simply disable it ```logger: false```. Disabling the logger should be done on production because it can cause a memory leak. #### Declare a serializer From 7f53badad545a9e1d5b04a9b02c238fb7a5e30b7 Mon Sep 17 00:00:00 2001 From: Berny Cantos Date: Thu, 5 Sep 2013 13:45:36 +0200 Subject: [PATCH 26/30] Add support for include_in_{parent,root} for nested and objects --- DependencyInjection/Configuration.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 4488bf2..adcaf6a 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -415,6 +415,10 @@ class Configuration implements ConfigurationInterface } if (isset($nestings['properties'])) { + $node + ->booleanNode('include_in_parent')->end() + ->booleanNode('include_in_root')->end() + ; $this->addNestedFieldConfig($node, $nestings, 'properties'); } } From fe871c5ac48d2be18a2efef46cd2b14ca001fe1a Mon Sep 17 00:00:00 2001 From: Miha Vrhovnik Date: Tue, 11 Mar 2014 14:50:00 +0100 Subject: [PATCH 27/30] Fix wrong annotation --- Paginator/RawPaginatorAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Paginator/RawPaginatorAdapter.php b/Paginator/RawPaginatorAdapter.php index e99746f..b74a9e4 100644 --- a/Paginator/RawPaginatorAdapter.php +++ b/Paginator/RawPaginatorAdapter.php @@ -33,7 +33,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface private $totalHits; /** - * @array for the facets + * @var array for the facets */ private $facets; From 726892c586949b8cf13ccca7fa7c1f3c3ca43f2d Mon Sep 17 00:00:00 2001 From: Lea Haensenberger Date: Thu, 13 Mar 2014 10:43:35 +0100 Subject: [PATCH 28/30] Ignore TypeMissingException when resetting a single type. This allows to create new types without having to recreate the whole index. --- Resetter.php | 9 ++++++++- Tests/ResetterTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Resetter.php b/Resetter.php index 69620a2..b22f6a1 100644 --- a/Resetter.php +++ b/Resetter.php @@ -2,6 +2,7 @@ namespace FOS\ElasticaBundle; +use Elastica\Exception\ResponseException; use Elastica\Type\Mapping; /** @@ -59,7 +60,13 @@ class Resetter } $type = $indexConfig['index']->getType($typeName); - $type->delete(); + try { + $type->delete(); + } catch (ResponseException $e) { + if (strpos($e->getMessage(), 'TypeMissingException') !== 0) { + throw $e; + } + } $mapping = $this->createMapping($indexConfig['config']['mappings'][$typeName]); $type->setMapping($mapping); } diff --git a/Tests/ResetterTest.php b/Tests/ResetterTest.php index aa0fbcc..b4e5649 100644 --- a/Tests/ResetterTest.php +++ b/Tests/ResetterTest.php @@ -2,6 +2,9 @@ namespace FOS\ElasticaBundle\Tests\Resetter; +use Elastica\Exception\ResponseException; +use Elastica\Request; +use Elastica\Response; use FOS\ElasticaBundle\Resetter; use Elastica\Type\Mapping; @@ -130,6 +133,32 @@ class ResetterTest extends \PHPUnit_Framework_TestCase $resetter->resetIndexType('foo', 'c'); } + public function testResetIndexTypeIgnoreTypeMissingException() + { + $type = $this->getMockElasticaType(); + + $this->indexConfigsByName['foo']['index']->expects($this->once()) + ->method('getType') + ->with('a') + ->will($this->returnValue($type)); + + $type->expects($this->once()) + ->method('delete') + ->will($this->throwException(new ResponseException( + new Request(''), + new Response(array('error' => 'TypeMissingException[[de_20131022] type[bla] missing]', 'status' => 404))) + )); + + $mapping = Mapping::create($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']); + $mapping->setParam('dynamic_templates', $this->indexConfigsByName['foo']['config']['mappings']['a']['dynamic_templates']); + $type->expects($this->once()) + ->method('setMapping') + ->with($mapping); + + $resetter = new Resetter($this->indexConfigsByName); + $resetter->resetIndexType('foo', 'a'); + } + public function testIndexMappingForParent() { $type = $this->getMockElasticaType(); From 2f9896c893063b7142a0ac1d2980e05c9050f2df Mon Sep 17 00:00:00 2001 From: Lea Haensenberger Date: Thu, 13 Mar 2014 10:45:57 +0100 Subject: [PATCH 29/30] Check for TypeMissingException anywhere in exception message --- Resetter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resetter.php b/Resetter.php index b22f6a1..863524b 100644 --- a/Resetter.php +++ b/Resetter.php @@ -63,7 +63,7 @@ class Resetter try { $type->delete(); } catch (ResponseException $e) { - if (strpos($e->getMessage(), 'TypeMissingException') !== 0) { + if (strpos($e->getMessage(), 'TypeMissingException') === false) { throw $e; } } From cdd6e3af45a7fb9f97b53887416e0b3511763452 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 14 Mar 2014 08:59:59 +1100 Subject: [PATCH 30/30] Bump elastica version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 094eba5..e588494 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "symfony/console": "~2.1", "symfony/form": "~2.1", "symfony/property-access": "~2.2", - "ruflin/elastica": "~0.20", + "ruflin/elastica": ">=0.20, <1.1-dev", "psr/log": "~1.0" }, "require-dev":{