Merge branch '3.0.x'

This commit is contained in:
Tim Nagel 2014-09-21 21:09:33 +10:00
commit 5cdeac9b45
20 changed files with 132 additions and 45 deletions

View file

@ -77,6 +77,9 @@ class TypeConfig
return $this->getConfig('search_analyzer');
}
/**
* @param string $key
*/
private function getConfig($key)
{
return isset($this->config[$key]) ?

View file

@ -30,7 +30,7 @@ class Configuration implements ConfigurationInterface
/**
* Generates the configuration tree.
*
* @return \Symfony\Component\Config\Definition\NodeInterface
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{

View file

@ -82,7 +82,7 @@ class FOSElasticaExtension extends Extension
/**
* @param array $config
* @param ContainerBuilder $container
* @return Configuration|null|\Symfony\Component\Config\Definition\ConfigurationInterface
* @return Configuration
*/
public function getConfiguration(array $config, ContainerBuilder $container)
{
@ -523,7 +523,7 @@ class FOSElasticaExtension extends Extension
*
* @param array $typeConfig
* @param ContainerBuilder $container
* @param $elasticaToModelId
* @param string $elasticaToModelId
* @param Reference $typeRef
* @param string $indexName
* @param string $typeName

View file

@ -174,27 +174,30 @@ class Listener implements EventSubscriber
}
/**
* Iterate through scheduled actions before flushing to emulate 2.x behavior. Note that the ElasticSearch index
* will fall out of sync with the source data in the event of a crash during flush.
* Iterate through scheduled actions before flushing to emulate 2.x behavior.
* Note that the ElasticSearch index will fall out of sync with the source
* data in the event of a crash during flush.
*
* This method is only called in legacy configurations of the listener.
*/
public function preFlush(EventArgs $eventArgs)
public function preFlush()
{
$this->persistScheduled();
}
/**
* Iterating through scheduled actions *after* flushing ensures that the ElasticSearch index will be affected
* only if the query is successful
* Iterating through scheduled actions *after* flushing ensures that the
* ElasticSearch index will be affected only if the query is successful.
*/
public function postFlush(EventArgs $eventArgs)
public function postFlush()
{
$this->persistScheduled();
}
/**
* Record the specified identifier to delete. Do not need to entire object.
* @param mixed $object
* @return mixed
*
* @param object $object
*/
protected function scheduleForDeletion($object)
{

View file

@ -3,7 +3,6 @@
namespace FOS\ElasticaBundle\Doctrine\ORM;
use Doctrine\ORM\QueryBuilder;
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
use FOS\ElasticaBundle\Doctrine\AbstractProvider;
use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException;

View file

@ -30,7 +30,11 @@ class Client extends BaseClient
private $stopwatch;
/**
* {@inheritdoc}
* @param string $path
* @param string $method
* @param array $data
* @param array $query
* @return \Elastica\Response
*/
public function request($path, $method = Request::GET, $data = array(), array $query = array())
{
@ -41,20 +45,7 @@ class Client extends BaseClient
$start = microtime(true);
$response = parent::request($path, $method, $data, $query);
if ($this->_logger and $this->_logger instanceof ElasticaLogger) {
$time = microtime(true) - $start;
$connection = $this->getLastRequest()->getConnection();
$connection_array = array(
'host' => $connection->getHost(),
'port' => $connection->getPort(),
'transport' => $connection->getTransport(),
'headers' => $connection->hasConfig('headers') ? $connection->getConfig('headers') : array(),
);
$this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query);
}
$this->logQuery($path, $method, $data, $query, $start);
if ($this->stopwatch) {
$this->stopwatch->stop('es_request');
@ -81,4 +72,32 @@ class Client extends BaseClient
{
$this->stopwatch = $stopwatch;
}
/**
* Log the query if we have an instance of ElasticaLogger.
*
* @param string $path
* @param string $method
* @param array $data
* @param array $query
* @param int $start
*/
private function logQuery($path, $method, $data, array $query, $start)
{
if (!$this->_logger or !$this->_logger instanceof ElasticaLogger) {
return;
}
$time = microtime(true) - $start;
$connection = $this->getLastRequest()->getConnection();
$connection_array = array(
'host' => $connection->getHost(),
'port' => $connection->getPort(),
'transport' => $connection->getTransport(),
'headers' => $connection->hasConfig('headers') ? $connection->getConfig('headers') : array(),
);
$this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query);
}
}

View file

@ -3,7 +3,6 @@
namespace FOS\ElasticaBundle\Elastica;
use Elastica\Index as BaseIndex;
use Elastica\Type;
/**
* Overridden Elastica Index class that provides dynamic index name changes.
@ -32,6 +31,9 @@ class Index extends BaseIndex
return $this->originalName ?: $this->_name;
}
/**
* @param string $type
*/
public function getType($type)
{
if (isset($this->typeCache[$type])) {

View file

@ -5,9 +5,7 @@ namespace FOS\ElasticaBundle\Index;
use Elastica\Index;
use Elastica\Exception\ResponseException;
use Elastica\Type\Mapping;
use FOS\ElasticaBundle\Configuration\IndexConfig;
use FOS\ElasticaBundle\Configuration\ConfigManager;
use FOS\ElasticaBundle\Elastica\Client;
/**
* Deletes and recreates indexes
@ -110,7 +108,7 @@ class Resetter
/**
* A command run when a population has finished.
*
* @param $indexName
* @param string $indexName
*/
public function postPopulate($indexName)
{

View file

@ -69,6 +69,9 @@ class RepositoryManager implements RepositoryManagerInterface
return 'FOS\ElasticaBundle\Repository';
}
/**
* @param string $entityName
*/
private function createRepository($entityName)
{
if (!class_exists($repositoryName = $this->getRepositoryName($entityName))) {

View file

@ -54,8 +54,8 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
/**
* Returns the paginated results.
*
* @param $offset
* @param $itemCountPerPage
* @param integer $offset
* @param integer $itemCountPerPage
* @throws \InvalidArgumentException
* @return ResultSet
*/

View file

@ -4,7 +4,6 @@ namespace FOS\ElasticaBundle\Persister;
use Psr\Log\LoggerInterface;
use Elastica\Exception\BulkException;
use Elastica\Exception\NotFoundException;
use FOS\ElasticaBundle\Transformer\ModelToElasticaTransformerInterface;
use Elastica\Type;
use Elastica\Document;

View file

@ -17,6 +17,9 @@ class ObjectSerializerPersister extends ObjectPersister
{
protected $serializer;
/**
* @param string $objectClass
*/
public function __construct(Type $type, ModelToElasticaTransformerInterface $transformer, $objectClass, $serializer)
{
parent::__construct($type, $transformer, $objectClass, array());

View file

@ -170,6 +170,7 @@ class ElasticaToModelTransformer implements ElasticaToModelTransformerInterface
/**
* @see https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Util/Inflector.php
* @param string $str
*/
private function camelize($str)
{

View file

@ -19,21 +19,43 @@ class Repository
$this->finder = $finder;
}
/**
* @param mixed $query
* @param integer $limit
* @param array $options
* @return array
*/
public function find($query, $limit = null, $options = array())
{
return $this->finder->find($query, $limit, $options);
}
/**
* @param mixed $query
* @param integer $limit
* @param array $options
* @return mixed
*/
public function findHybrid($query, $limit = null, $options = array())
{
return $this->finder->findHybrid($query, $limit, $options);
}
/**
* @param mixed $query
* @param array $options
* @return \Pagerfanta\Pagerfanta
*/
public function findPaginated($query, $options = array())
{
return $this->finder->findPaginated($query, $options);
}
/**
* @param string $query
* @param array $options
* @return Paginator\PaginatorAdapterInterface
*/
public function createPaginatorAdapter($query, $options = array())
{
return $this->finder->createPaginatorAdapter($query, $options);

View file

@ -4,8 +4,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="fos_elastica.provider.prototype.mongodb.class">FOS\ElasticaBundle\Doctrine\MongoDB\Provider</parameter>
<parameter key="fos_elastica.listener.prototype.mongodb.class">FOS\ElasticaBundle\Doctrine\Listener</parameter>
<parameter key="fos_elastica.elastica_to_model_transformer.prototype.mongodb.class">FOS\ElasticaBundle\Doctrine\MongoDB\ElasticaToModelTransformer</parameter>
<parameter key="fos_elastica.manager.mongodb.class">FOS\ElasticaBundle\Doctrine\RepositoryManager</parameter>
</parameters>
<services>
<service id="fos_elastica.provider.prototype.mongodb" class="FOS\ElasticaBundle\Doctrine\MongoDB\Provider" public="true" abstract="true">
<service id="fos_elastica.provider.prototype.mongodb" class="%fos_elastica.provider.prototype.mongodb.class%" public="true" abstract="true">
<argument /> <!-- object persister -->
<argument type="service" id="fos_elastica.indexable" />
<argument /> <!-- model -->
@ -13,7 +21,7 @@
<argument type="service" id="doctrine_mongodb" />
</service>
<service id="fos_elastica.listener.prototype.mongodb" class="FOS\ElasticaBundle\Doctrine\Listener" public="false" abstract="true">
<service id="fos_elastica.listener.prototype.mongodb" class="%fos_elastica.listener.prototype.mongodb.class%" public="false" abstract="true">
<argument /> <!-- object persister -->
<argument type="collection" /> <!-- events -->
<argument type="service" id="fos_elastica.indexable" />
@ -21,7 +29,7 @@
<argument /> <!-- logger -->
</service>
<service id="fos_elastica.elastica_to_model_transformer.prototype.mongodb" class="FOS\ElasticaBundle\Doctrine\MongoDB\ElasticaToModelTransformer" public="false" abstract="true">
<service id="fos_elastica.elastica_to_model_transformer.prototype.mongodb" class="%fos_elastica.elastica_to_model_transformer.prototype.mongodb.class%" public="false" abstract="true">
<argument type="service" id="doctrine_mongodb" />
<argument /> <!-- model -->
<argument type="collection" /> <!-- options -->
@ -30,7 +38,7 @@
</call>
</service>
<service id="fos_elastica.manager.mongodb" class="FOS\ElasticaBundle\Doctrine\RepositoryManager">
<service id="fos_elastica.manager.mongodb" class="%fos_elastica.manager.mongodb.class%">
<argument type="service" id="doctrine_mongodb"/>
<argument type="service" id="annotation_reader"/>
</service>

View file

@ -4,8 +4,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="fos_elastica.provider.prototype.orm.class">FOS\ElasticaBundle\Doctrine\ORM\Provider</parameter>
<parameter key="fos_elastica.listener.prototype.orm.class">FOS\ElasticaBundle\Doctrine\Listener</parameter>
<parameter key="fos_elastica.elastica_to_model_transformer.prototype.orm.class">FOS\ElasticaBundle\Doctrine\ORM\ElasticaToModelTransformer</parameter>
<parameter key="fos_elastica.manager.orm.class">FOS\ElasticaBundle\Doctrine\RepositoryManager</parameter>
</parameters>
<services>
<service id="fos_elastica.provider.prototype.orm" class="FOS\ElasticaBundle\Doctrine\ORM\Provider" public="true" abstract="true">
<service id="fos_elastica.provider.prototype.orm" class="%fos_elastica.provider.prototype.orm.class%" public="true" abstract="true">
<argument /> <!-- object persister -->
<argument type="service" id="fos_elastica.indexable" />
<argument /> <!-- model -->
@ -13,7 +20,7 @@
<argument type="service" id="doctrine" />
</service>
<service id="fos_elastica.listener.prototype.orm" class="FOS\ElasticaBundle\Doctrine\Listener" public="false" abstract="true">
<service id="fos_elastica.listener.prototype.orm" class="%fos_elastica.listener.prototype.orm.class%" public="false" abstract="true">
<argument /> <!-- object persister -->
<argument type="collection" /> <!-- events -->
<argument type="service" id="fos_elastica.indexable" />
@ -21,7 +28,7 @@
<argument on-invalid="ignore" /> <!-- logger -->
</service>
<service id="fos_elastica.elastica_to_model_transformer.prototype.orm" class="FOS\ElasticaBundle\Doctrine\ORM\ElasticaToModelTransformer" public="false" abstract="true">
<service id="fos_elastica.elastica_to_model_transformer.prototype.orm" class="%fos_elastica.elastica_to_model_transformer.prototype.orm.class%" public="false" abstract="true">
<argument type="service" id="doctrine" />
<argument /> <!-- model -->
<argument type="collection" /> <!-- options -->
@ -30,7 +37,7 @@
</call>
</service>
<service id="fos_elastica.manager.orm" class="FOS\ElasticaBundle\Doctrine\RepositoryManager">
<service id="fos_elastica.manager.orm" class="%fos_elastica.manager.orm.class%">
<argument type="service" id="doctrine" />
<argument type="service" id="annotation_reader" />
</service>

View file

@ -173,8 +173,14 @@ abstract class ListenerTest extends \PHPUnit_Framework_TestCase
abstract protected function getListenerClass();
/**
* @return string
*/
abstract protected function getObjectManagerClass();
/**
* @return string
*/
abstract protected function getClassMetadataClass();
private function createLifecycleEventArgs()
@ -205,6 +211,11 @@ abstract class ListenerTest extends \PHPUnit_Framework_TestCase
->getMock();
}
/**
* @param Listener\Entity $object
* @param string $indexName
* @param string $typeName
*/
private function getMockPersister($object, $indexName, $typeName)
{
$mock = $this->getMockBuilder('FOS\ElasticaBundle\Persister\ObjectPersister')
@ -235,6 +246,12 @@ abstract class ListenerTest extends \PHPUnit_Framework_TestCase
return $mock;
}
/**
* @param string $indexName
* @param string $typeName
* @param Listener\Entity $object
* @param boolean $return
*/
private function getMockIndexable($indexName, $typeName, $object, $return = null)
{
$mock = $this->getMock('FOS\ElasticaBundle\Provider\IndexableInterface');
@ -256,6 +273,9 @@ class Entity
{
private $id;
/**
* @param integer $id
*/
public function __construct($id)
{
$this->id = $id;

View file

@ -3,7 +3,6 @@
namespace FOS\ElasticaBundle\Tests\Resetter;
use FOS\ElasticaBundle\FOSElasticaBundle;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
class FOSElasticaBundleTest extends \PHPUnit_Framework_TestCase
{

View file

@ -2,9 +2,7 @@
namespace FOS\ElasticaBundle\Tests\ObjectSerializerPersister;
use FOS\ElasticaBundle\Persister\ObjectPersister;
use FOS\ElasticaBundle\Persister\ObjectSerializerPersister;
use FOS\ElasticaBundle\Transformer\ModelToElasticaAutoTransformer;
use FOS\ElasticaBundle\Transformer\ModelToElasticaIdentifierTransformer;
use Symfony\Component\PropertyAccess\PropertyAccess;

View file

@ -157,6 +157,9 @@ class POPO
public $id;
public $data;
/**
* @param integer $id
*/
public function __construct($id, $data)
{
$this->data = $data;