Add DoctrineMongoDBProvider and DoctrineORMProvider to deal with count inconsistency

This commit is contained in:
ornicar 2011-05-09 09:48:25 -07:00
commit aed89aa8dc
5 changed files with 42 additions and 3 deletions

View file

@ -8,7 +8,7 @@ use Elastica_Document;
use Closure;
use InvalidArgumentException;
class DoctrineProvider implements ProviderInterface
abstract class AbstractDoctrineProvider implements ProviderInterface
{
protected $type;
protected $objectManager;
@ -66,6 +66,13 @@ class DoctrineProvider implements ProviderInterface
}
}
/**
* Counts the objects of a query builder
*
* @return int
**/
protected abstract function countObjects($queryBuilder);
/**
* Creates the query buider used to fetch the documents to index
*

View file

@ -0,0 +1,16 @@
<?php
namespace FOQ\ElasticaBundle\Provider;
class DoctrineMongoDBProvider extends AbstractDoctrineProvider
{
/**
* Counts the objects of a query builder
*
* @return int
**/
protected function countObjects($queryBuilder)
{
return $queryBuilder->getQuery()->count();
}
}

View file

@ -0,0 +1,16 @@
<?php
namespace FOQ\ElasticaBundle\Provider;
class DoctrineORMProvider extends AbstractDoctrineProvider
{
/**
* Counts the objects of a query builder
*
* @return int
**/
protected function countObjects($queryBuilder)
{
return $queryBuilder->count()->getQuery()->execute();
}
}

View file

@ -6,7 +6,7 @@
<services>
<service id="foq_elastica.provider.prototype.mongodb" class="FOQ\ElasticaBundle\Provider\DoctrineProvider" public="false" abstract="true">
<service id="foq_elastica.provider.prototype.mongodb" class="FOQ\ElasticaBundle\Provider\DoctrineMongoDBProvider" public="false" abstract="true">
<argument /> <!-- index -->
<argument type="service" id="doctrine.odm.mongodb.document_manager" />
<argument /> <!-- transformer -->

View file

@ -6,7 +6,7 @@
<services>
<service id="foq_elastica.provider.prototype.orm" class="FOQ\ElasticaBundle\Provider\DoctrineProvider" public="false" abstract="true">
<service id="foq_elastica.provider.prototype.orm" class="FOQ\ElasticaBundle\Provider\DoctrineORMProvider" public="false" abstract="true">
<argument /> <!-- index -->
<argument type="service" id="doctrine.orm.entity_manager" />
<argument /> <!-- transformer -->