Skip to content

Commit

Permalink
Remove requireIndexes and stuff thereto related
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Jul 30, 2016
1 parent c515e77 commit 1d31b01
Show file tree
Hide file tree
Showing 15 changed files with 14 additions and 655 deletions.
1 change: 0 additions & 1 deletion doctrine-mongo-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<xs:attribute name="repository-class" type="xs:string"/>
<xs:attribute name="inheritance-type" type="odm:inheritance-type"/>
<xs:attribute name="change-tracking-policy" type="odm:change-tracking-policy" />
<xs:attribute name="require-indexes" type="xs:boolean" />
<xs:attribute name="slave-okay" type="xs:boolean" />
</xs:complexType>

Expand Down
1 change: 0 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ final class Document extends AbstractDocument
public $collection;
public $repositoryClass;
public $indexes = array();
public $requireIndexes = false;
public $shardKey;
public $slaveOkay;
public $writeConcern;
Expand Down
15 changes: 0 additions & 15 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@ class ClassMetadataInfo implements \Doctrine\Common\Persistence\Mapping\ClassMet
*/
public $shardKey;

/**
* READ-ONLY: Whether or not queries on this document should require indexes.
*/
public $requireIndexes = false;

/**
* READ-ONLY: The name of the document class.
*/
Expand Down Expand Up @@ -803,16 +798,6 @@ public function addIndex($keys, array $options = array())
);
}

/**
* Set whether or not queries on this document should require indexes.
*
* @param bool $requireIndexes
*/
public function setRequireIndexes($requireIndexes)
{
$this->requireIndexes = $requireIndexes;
}

/**
* Returns the array of indexes for this Document.
*
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$this->addIndex($class, $index);
}
}
if (isset($documentAnnot->requireIndexes)) {
$class->setRequireIndexes($documentAnnot->requireIndexes);
}
if (isset($documentAnnot->slaveOkay)) {
$class->setSlaveOkay($documentAnnot->slaveOkay);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ public function loadMetadataForClass($className, ClassMetadata $class)
if (isset($xmlRoot->{'shard-key'})) {
$this->setShardKey($class, $xmlRoot->{'shard-key'}[0]);
}
if (isset($xmlRoot['require-indexes'])) {
$class->setRequireIndexes('true' === (string) $xmlRoot['require-indexes']);
}
if (isset($xmlRoot['slave-okay'])) {
$class->setSlaveOkay('true' === (string) $xmlRoot['slave-okay']);
}
Expand Down
3 changes: 0 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ public function loadMetadataForClass($className, ClassMetadata $class)
if (isset($element['changeTrackingPolicy'])) {
$class->setChangeTrackingPolicy(constant(MappingClassMetadata::class . '::CHANGETRACKING_' . strtoupper($element['changeTrackingPolicy'])));
}
if (isset($element['requireIndexes'])) {
$class->setRequireIndexes($element['requireIndexes']);
}
if (isset($element['slaveOkay'])) {
$class->setSlaveOkay($element['slaveOkay']);
}
Expand Down
13 changes: 0 additions & 13 deletions lib/Doctrine/ODM/MongoDB/MongoDBException.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,6 @@ public static function cannotPersistMappedSuperclass($className)
return new self('Cannot persist an embedded document or mapped superclass ' . $className);
}

/**
* @param string $className
* @param string $unindexedFields
* @return MongoDBException
*/
public static function queryNotIndexed($className, $unindexedFields)
{
return new self(sprintf('Cannot execute unindexed queries on %s. Unindexed fields: %s',
$className,
implode(', ', $unindexedFields)
));
}

/**
* @param string $className
* @return MongoDBException
Expand Down
20 changes: 0 additions & 20 deletions lib/Doctrine/ODM/MongoDB/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ class Builder extends \Doctrine\MongoDB\Query\Builder
*/
private $primers = array();

/**
* Whether or not to require indexes.
*
* @var bool
*/
private $requireIndexes;

/**
* Whether or not to register documents in UnitOfWork.
*
Expand All @@ -102,18 +95,6 @@ public function __construct(DocumentManager $dm, $documentName = null)
}
}

/**
* Set whether or not to require indexes.
*
* @param bool $requireIndexes
* @return $this
*/
public function requireIndexes($requireIndexes = true)
{
$this->requireIndexes = $requireIndexes;
return $this;
}

/**
* Set the current field to operate on.
*
Expand Down Expand Up @@ -375,7 +356,6 @@ public function getQuery(array $options = array())
$this->hydrate,
$this->refresh,
$this->primers,
$this->requireIndexes,
$this->readOnly
);
}
Expand Down
94 changes: 0 additions & 94 deletions lib/Doctrine/ODM/MongoDB/Query/FieldExtractor.php

This file was deleted.

72 changes: 1 addition & 71 deletions lib/Doctrine/ODM/MongoDB/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ class Query extends \Doctrine\MongoDB\Query\Query
*/
private $primers = array();

/**
* Whether or not to require indexes.
*
* @var boolean
*/
private $requireIndexes;

/**
* Hints for UnitOfWork behavior.
*
Expand All @@ -95,10 +88,9 @@ class Query extends \Doctrine\MongoDB\Query\Query
* @param boolean $hydrate
* @param boolean $refresh
* @param array $primers
* @param null $requireIndexes
* @param boolean $readOnly
*/
public function __construct(DocumentManager $dm, ClassMetadata $class, Collection $collection, array $query = array(), array $options = array(), $hydrate = true, $refresh = false, array $primers = array(), $requireIndexes = null, $readOnly = false)
public function __construct(DocumentManager $dm, ClassMetadata $class, Collection $collection, array $query = array(), array $options = array(), $hydrate = true, $refresh = false, array $primers = array(), $readOnly = false)
{
$primers = array_filter($primers);

Expand All @@ -115,7 +107,6 @@ public function __construct(DocumentManager $dm, ClassMetadata $class, Collectio
$this->class = $class;
$this->hydrate = $hydrate;
$this->primers = $primers;
$this->requireIndexes = $requireIndexes;

$this->setReadOnly($readOnly);
$this->setRefresh($refresh);
Expand Down Expand Up @@ -186,53 +177,6 @@ public function setRefresh($refresh)
$this->unitOfWorkHints[Query::HINT_REFRESH] = (boolean) $refresh;
}

/**
* Gets the fields involved in this query.
*
* @return array $fields An array of fields names used in this query.
*/
public function getFieldsInQuery()
{
$query = isset($this->query['query']) ? $this->query['query'] : array();
$sort = isset($this->query['sort']) ? $this->query['sort'] : array();

$extractor = new FieldExtractor($query, $sort);
return $extractor->getFields();
}

/**
* Check if this query is indexed.
*
* @return bool
*/
public function isIndexed()
{
$fields = $this->getFieldsInQuery();
foreach ($fields as $field) {
if ( ! $this->collection->isFieldIndexed($field)) {
return false;
}
}
return true;
}

/**
* Gets an array of the unindexed fields in this query.
*
* @return array
*/
public function getUnindexedFields()
{
$unindexedFields = array();
$fields = $this->getFieldsInQuery();
foreach ($fields as $field) {
if ( ! $this->collection->isFieldIndexed($field)) {
$unindexedFields[] = $field;
}
}
return $unindexedFields;
}

/**
* Execute the query and returns the results.
*
Expand All @@ -241,10 +185,6 @@ public function getUnindexedFields()
*/
public function execute()
{
if ($this->isIndexRequired() && ! $this->isIndexed()) {
throw MongoDBException::queryNotIndexed($this->class->name, $this->getUnindexedFields());
}

$results = parent::execute();

if ( ! $this->hydrate) {
Expand Down Expand Up @@ -322,14 +262,4 @@ protected function prepareCursor(BaseCursor $cursor)

return $cursor;
}

/**
* Return whether queries on this document should require indexes.
*
* @return boolean
*/
private function isIndexRequired()
{
return $this->requireIndexes !== null ? $this->requireIndexes : $this->class->requireIndexes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ public function testQueries()
), $qb->getQueryArray());
}

public function testGetFieldsInCoordinatesQuery()
{
$qb = $this->dm->createQueryBuilder(__NAMESPACE__.'\City');
$qb->field('coordinates')->withinBox(41, 41, 72, 72);
$query = $qb->getQuery();
$this->assertEquals(array('coordinates'), $query->getFieldsInQuery());
}

public function testGeoSpatial1()
{
$this->dm->getSchemaManager()->ensureDocumentIndexes(__NAMESPACE__.'\City');
Expand Down
Loading

0 comments on commit 1d31b01

Please sign in to comment.