Exemple #1
0
 /**
  * Create the document database for a mapped class.
  *
  * @param string $documentName
  * @throws \InvalidArgumentException
  */
 public function createDocumentDatabase($documentName)
 {
     $class = $this->dm->getClassMetadata($documentName);
     if ($class->isMappedSuperclass || $class->isEmbeddedDocument) {
         throw new \InvalidArgumentException('Cannot delete document indexes for mapped super classes or embedded documents.');
     }
     $this->dm->getDocumentDatabase($documentName)->execute("function() { return true; }");
 }
Exemple #2
0
 /**
  * Get Discriminator Values
  *
  * @param \Iterator|array $classNames
  * @return array an array of discriminatorValues (mixed type)
  * @throws \InvalidArgumentException if the number of found collections > 1
  */
 private function getDiscriminatorValues($classNames)
 {
     $discriminatorValues = array();
     $collections = array();
     foreach ($classNames as $className) {
         $class = $this->dm->getClassMetadata($className);
         $discriminatorValues[] = $class->discriminatorValue;
         $key = $this->dm->getDocumentDatabase($className)->getName() . '.' . $class->getCollection();
         $collections[$key] = $key;
     }
     if (count($collections) > 1) {
         throw new \InvalidArgumentException('Documents involved are not all mapped to the same database collection.');
     }
     return $discriminatorValues;
 }
 /** @inheritDoc */
 public function generate(DocumentManager $dm, $document)
 {
     $className = get_class($document);
     $db = $dm->getDocumentDatabase($className);
     $coll = $this->collection ?: 'doctrine_increment_ids';
     $key = $this->key ?: $dm->getDocumentCollection($className)->getName();
     $query = array('_id' => $key);
     $newObj = array('$inc' => array('current_id' => 1));
     $command = array();
     $command['findandmodify'] = $coll;
     $command['query'] = $query;
     $command['update'] = $newObj;
     $command['upsert'] = true;
     $command['new'] = true;
     $result = $db->command($command);
     return $result['value']['current_id'];
 }