getConfiguration() public method

Gets the Configuration used by the DocumentManager.
public getConfiguration ( ) : Configuration
return Configuration
 /**
  * @param  \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
  * @param  string                                               $document
  * @param  array                                                $fields
  * @param  Boolean                                              $withRepository
  * @throws \RuntimeException
  */
 public function generate(BundleInterface $bundle, $document, array $fields, $withRepository)
 {
     $config = $this->documentManager->getConfiguration();
     $config->addDocumentNamespace($bundle->getName(), $bundle->getNamespace() . '\\Document');
     $documentClass = $config->getDocumentNamespace($bundle->getName()) . '\\' . $document;
     $documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
     if (file_exists($documentPath)) {
         throw new \RuntimeException(sprintf('Document "%s" already exists.', $documentClass));
     }
     $class = new ClassMetadataInfo($documentClass);
     if ($withRepository) {
         $class->setCustomRepositoryClass($documentClass . 'Repository');
     }
     $class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     foreach ($fields as $field) {
         $class->mapField($field);
     }
     $documentGenerator = $this->getDocumentGenerator();
     $documentCode = $documentGenerator->generateDocumentClass($class);
     $this->filesystem->mkdir(dirname($documentPath));
     file_put_contents($documentPath, rtrim($documentCode) . PHP_EOL, LOCK_EX);
     if ($withRepository) {
         $path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
         $this->getRepositoryGenerator()->writeDocumentRepositoryClass($class->customRepositoryClassName, $path);
     }
 }
Beispiel #2
0
 /**
  * Create a new MongoCollection instance that wraps a PHP MongoCollection instance
  * for a given ClassMetadata instance.
  *
  * @param MongoCollection $mongoColleciton The MongoCollection instance.
  * @param ClassMetadata $class The ClassMetadata instance.
  * @param DocumentManager $dm The DocumentManager instance.
  */
 public function __construct(\MongoCollection $mongoCollection, ClassMetadata $class, DocumentManager $dm)
 {
     $this->_mongoCollection = $mongoCollection;
     $this->_class = $class;
     $this->_loggerCallable = $dm->getConfiguration()->getLoggerCallable();
     $this->_cmd = $dm->getConfiguration()->getMongoCmd();
     $this->_eventManager = $dm->getEventManager();
 }
 /**
  * {@inheritdoc}
  */
 protected function initDB()
 {
     if (is_null($this->collection)) {
         $databaseName = $this->dm->getConfiguration()->getDefaultDB();
         $collection = $this->dm->getConnection()->selectCollection($databaseName, $this->options['collection']);
         $this->collection = $collection;
     }
     return $this->collection;
 }
 /**
  * {@inheritdoc}
  */
 public function create(DocumentManager $dm, array $mapping, BaseCollection $coll = null)
 {
     if ($coll === null) {
         $coll = !empty($mapping['collectionClass']) ? $this->createCollectionClass($mapping['collectionClass']) : new ArrayCollection();
     }
     if (empty($mapping['collectionClass'])) {
         return new PersistentCollection($coll, $dm, $dm->getUnitOfWork());
     }
     $className = $dm->getConfiguration()->getPersistentCollectionGenerator()->loadClass($mapping['collectionClass'], $dm->getConfiguration()->getAutoGeneratePersistentCollectionClasses());
     return new $className($coll, $dm, $dm->getUnitOfWork());
 }
    public function loadCollection(PersistentCollection $collection)
    {
        $mapping = $collection->getMapping();
        $cmd = $this->dm->getConfiguration()->getMongoCmd();
        $groupedIds = array();
        foreach ($collection->getReferences() as $reference) {
            $className = $this->dm->getClassNameFromDiscriminatorValue($mapping, $reference);
            $id = $reference[$cmd . 'id'];
            $reference = $this->dm->getReference($className, (string) $id);
            $collection->add($reference);
            if ($reference instanceof Proxy && ! $reference->__isInitialized__) {
                if ( ! isset($groupedIds[$className])) {
                    $groupedIds[$className] = array();
                }
                $groupedIds[$className][] = $id;
            }
        }

        foreach ($groupedIds as $className => $ids) {
            $mongoCollection = $this->dm->getDocumentCollection($className);
            $data = $mongoCollection->find(array('_id' => array($cmd . 'in' => $ids)));
            $hints = array(Builder::HINT_REFRESH => true);
            foreach ($data as $id => $documentData) {
                $document = $this->uow->getOrCreateDocument($className, $documentData, $hints);
            }
        }
    }
 public function __construct(DocumentManager $dm, ClassMetadata $class, Collection $coll)
 {
     $this->_coll = $coll;
     $this->_dm = $dm;
     $this->_typeClass = $class;
     $this->_cmd = $dm->getConfiguration()->getMongoCmd();
 }
 public function setup()
 {
     $this->dm = self::createTestDocumentManager();
     $xmlDriver = new XmlDriver(array(realpath(__DIR__ . '/../') . '/Resources/config/doctrine' => 'Avro\\StripeBundle\\Tests\\Fixtures\\Document'), '.mongodb.xml');
     $this->dm->getConfiguration()->setMetadataDriverImpl($xmlDriver);
     $this->planManager = new PlanManager($this->dm, 'Avro\\StripeBundle\\Tests\\Fixtures\\Document\\Plan');
 }
 /**
  * Constructor.
  *
  * @param DocumentManager $dm
  * @param CriteriaMerger  $cm
  */
 public function __construct(DocumentManager $dm, CriteriaMerger $cm = null)
 {
     $this->dm = $dm;
     $this->cm = $cm ?: new CriteriaMerger();
     $this->config = $dm->getConfiguration();
     $this->parseConfiguration();
 }
 public function setup()
 {
     $this->dm = self::createTestDocumentManager();
     $xmlDriver = new XmlDriver(array(realpath(__DIR__ . '/../') . '/Resources/config/doctrine' => 'Vespolina\\PartnerBundle\\Tests\\Fixtures\\Document'), '.mongodb.xml');
     //$xmlDriver->setFileExtension('.mongodb.xml');
     $this->dm->getConfiguration()->setMetadataDriverImpl($xmlDriver);
     $this->partnerMgr = new PartnerManager($this->dm, array('partnerClass' => 'Vespolina\\PartnerBundle\\Tests\\Fixtures\\Document\\Partner', 'partnerAddressClass' => 'Vespolina\\PartnerBundle\\Document\\Address', 'partnerContactClass' => 'Vespolina\\PartnerBundle\\Document\\Contact', 'partnerPersonalDetailsClass' => 'Vespolina\\PartnerBundle\\Document\\PersonalDetails', 'partnerOrganisationDetailsClass' => 'Vespolina\\PartnerBundle\\Document\\OrganisationDetails'), array(Partner::ROLE_CUSTOMER, Partner::ROLE_EMPLOYEE, Partner::ROLE_SUPPLIER));
 }
 public function __construct(Collection $coll, DocumentManager $dm = null)
 {
     $this->coll = $coll;
     if ($dm !== null) {
         $this->dm = $dm;
         $this->cmd = $dm->getConfiguration()->getMongoCmd();
     }
 }
Beispiel #11
0
 /**
  * Wraps the supplied base cursor as an ODM one.
  *
  * @param Doctrine\MongoDB\Cursor $cursor The base cursor
  *
  * @return Cursor An ODM cursor
  */
 private function wrapCursor(BaseCursor $cursor)
 {
     if ($cursor instanceof BaseLoggableCursor) {
         return new LoggableCursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $cursor, $cursor->getQuery(), $cursor->getFields(), $this->dm->getConfiguration()->getRetryQuery(), $cursor->getLoggerCallable());
     } else {
         return new Cursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $cursor, $cursor->getQuery(), $cursor->getFields(), $this->dm->getConfiguration()->getRetryQuery());
     }
 }
 /**
  * {@inheritDoc}
  */
 public function save_run($xhprof_data, $type, $run_id = null)
 {
     if (!class_exists('\\Xhgui_Profiles') || !class_exists('\\Xhgui_Saver_Mongo')) {
         throw new \Exception('composer require perftools/xhgui dev-master');
     }
     $data = $this->prepareForSave($xhprof_data);
     $dbname = $this->documentManager->getConfiguration()->getDefaultDB();
     $mongo = $this->documentManager->getConnection()->getMongoClient()->selectDB($dbname);
     $profiles = new \Xhgui_Profiles($mongo);
     $saver = new \Xhgui_Saver_Mongo($profiles);
     try {
         $saver->save($data);
         $run_id = (string) $data['_id'];
     } catch (\Exception $e) {
         error_log($e->getMessage());
     }
     return $run_id;
 }
 /**
  * @param array $options
  *
  * @return array
  */
 private function getWriteOptions(array $options = array())
 {
     $defaultOptions = $this->dm->getConfiguration()->getDefaultCommitOptions();
     $documentOptions = [];
     if ($this->class->hasWriteConcern()) {
         $documentOptions['w'] = $this->class->getWriteConcern();
     }
     return array_merge($defaultOptions, $documentOptions, $options);
 }
 /**
  * Initializes a new BasicDocumentPersister instance.
  *
  * @param Doctrine\ODM\MongoDB\DocumentManager $dm
  * @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class
  */
 public function __construct(DocumentManager $dm, ClassMetadata $class)
 {
     $this->dm = $dm;
     $this->uow = $dm->getUnitOfWork();
     $this->class = $class;
     $this->documentName = $class->getName();
     $this->collection = $dm->getDocumentCollection($class->name);
     $this->cmd = $this->dm->getConfiguration()->getMongoCmd();
 }
Beispiel #15
0
 /**
  * {@inheritdoc}
  */
 protected function createRepository(DocumentManager $documentManager, $documentName)
 {
     $metadata = $documentManager->getClassMetadata($documentName);
     $repository = $metadata->customRepositoryClassName;
     if ($repository === null) {
         $repository = $documentManager->getConfiguration()->getDefaultRepositoryClassName();
     }
     return $this->createResourceRepository($repository, $documentManager, $metadata, $this->resolveResource($metadata->getName()));
 }
 /**
  * Create a new repository instance for a document class.
  *
  * @param DocumentManager $documentManager The DocumentManager instance.
  * @param string          $documentName    The name of the document.
  *
  * @return \Doctrine\Common\Persistence\ObjectRepository
  */
 protected function createRepository(DocumentManager $documentManager, $documentName)
 {
     $metadata = $documentManager->getClassMetadata($documentName);
     $repositoryClassName = $metadata->customRepositoryClassName;
     if ($repositoryClassName === null) {
         $configuration = $documentManager->getConfiguration();
         $repositoryClassName = $configuration->getDefaultRepositoryClassName();
     }
     return new $repositoryClassName($documentManager, $documentManager->getUnitOfWork(), $metadata);
 }
Beispiel #17
0
 private function wrapCursor(BaseCursor $baseCursor, array $hints)
 {
     if ($baseCursor instanceof BaseLoggableCursor) {
         $cursor = new LoggableCursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $baseCursor, $baseCursor->getQuery(), $baseCursor->getFields(), $this->dm->getConfiguration()->getRetryQuery(), $baseCursor->getLoggerCallable());
     } else {
         $cursor = new Cursor($this->dm->getConnection(), $this->collection, $this->dm->getUnitOfWork(), $this->class, $baseCursor, $baseCursor->getQuery(), $baseCursor->getFields(), $this->dm->getConfiguration()->getRetryQuery());
     }
     $cursor->hydrate($this->hydrate);
     $cursor->setHints($hints);
     return $cursor;
 }
Beispiel #18
0
 /**
  * Executes a merge operation on a document.
  *
  * @param object      $document
  * @param array       $visited
  * @param object|null $prevManagedCopy
  * @param array|null  $assoc
  *
  * @return object The managed copy of the document.
  *
  * @throws InvalidArgumentException If the entity instance is NEW.
  * @throws LockException If the document uses optimistic locking through a
  *                       version attribute and the version check against the
  *                       managed copy fails.
  */
 private function doMerge($document, array &$visited, $prevManagedCopy = null, $assoc = null)
 {
     $oid = spl_object_hash($document);
     if (isset($visited[$oid])) {
         return $visited[$oid];
         // Prevent infinite recursion
     }
     $visited[$oid] = $document;
     // mark visited
     $class = $this->dm->getClassMetadata(get_class($document));
     /* First we assume DETACHED, although it can still be NEW but we can
      * avoid an extra DB round trip this way. If it is not MANAGED but has
      * an identity, we need to fetch it from the DB anyway in order to
      * merge. MANAGED documents are ignored by the merge operation.
      */
     $managedCopy = $document;
     if ($this->getDocumentState($document, self::STATE_DETACHED) !== self::STATE_MANAGED) {
         if ($document instanceof Proxy && !$document->__isInitialized()) {
             $document->__load();
         }
         $identifier = $class->getIdentifier();
         // We always have one element in the identifier array but it might be null
         $id = $identifier[0] !== null ? $class->getIdentifierObject($document) : null;
         $managedCopy = null;
         // Try to fetch document from the database
         if (!$class->isEmbeddedDocument && $id !== null) {
             $managedCopy = $this->dm->find($class->name, $id);
             // Managed copy may be removed in which case we can't merge
             if ($managedCopy && $this->getDocumentState($managedCopy) === self::STATE_REMOVED) {
                 throw new \InvalidArgumentException('Removed entity detected during merge. Cannot merge with a removed entity.');
             }
             if ($managedCopy instanceof Proxy && !$managedCopy->__isInitialized__) {
                 $managedCopy->__load();
             }
         }
         if ($managedCopy === null) {
             // Create a new managed instance
             $managedCopy = $class->newInstance();
             if ($id !== null) {
                 $class->setIdentifierValue($managedCopy, $id);
             }
             $this->persistNew($class, $managedCopy);
         }
         if ($class->isVersioned) {
             $managedCopyVersion = $class->reflFields[$class->versionField]->getValue($managedCopy);
             $documentVersion = $class->reflFields[$class->versionField]->getValue($document);
             // Throw exception if versions don't match
             if ($managedCopyVersion != $documentVersion) {
                 throw LockException::lockFailedVersionMissmatch($document, $documentVersion, $managedCopyVersion);
             }
         }
         // Merge state of $document into existing (managed) document
         foreach ($class->reflClass->getProperties() as $prop) {
             $name = $prop->name;
             $prop->setAccessible(true);
             if (!isset($class->associationMappings[$name])) {
                 if (!$class->isIdentifier($name)) {
                     $prop->setValue($managedCopy, $prop->getValue($document));
                 }
             } else {
                 $assoc2 = $class->associationMappings[$name];
                 if ($assoc2['type'] === 'one') {
                     $other = $prop->getValue($document);
                     if ($other === null) {
                         $prop->setValue($managedCopy, null);
                     } elseif ($other instanceof Proxy && !$other->__isInitialized__) {
                         // Do not merge fields marked lazy that have not been fetched
                         continue;
                     } elseif (!$assoc2['isCascadeMerge']) {
                         if ($this->getDocumentState($other) === self::STATE_DETACHED) {
                             $targetDocument = isset($assoc2['targetDocument']) ? $assoc2['targetDocument'] : get_class($other);
                             /* @var $targetClass \Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo */
                             $targetClass = $this->dm->getClassMetadata($targetDocument);
                             $relatedId = $targetClass->getIdentifierObject($other);
                             if ($targetClass->subClasses) {
                                 $other = $this->dm->find($targetClass->name, $relatedId);
                             } else {
                                 $other = $this->dm->getProxyFactory()->getProxy($assoc2['targetDocument'], array($targetClass->identifier => $relatedId));
                                 $this->registerManaged($other, $relatedId, array());
                             }
                         }
                         $prop->setValue($managedCopy, $other);
                     }
                 } else {
                     $mergeCol = $prop->getValue($document);
                     if ($mergeCol instanceof PersistentCollectionInterface && !$mergeCol->isInitialized() && !$assoc2['isCascadeMerge']) {
                         /* Do not merge fields marked lazy that have not
                          * been fetched. Keep the lazy persistent collection
                          * of the managed copy.
                          */
                         continue;
                     }
                     $managedCol = $prop->getValue($managedCopy);
                     if (!$managedCol) {
                         $managedCol = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $assoc2, null);
                         $managedCol->setOwner($managedCopy, $assoc2);
                         $prop->setValue($managedCopy, $managedCol);
                         $this->originalDocumentData[$oid][$name] = $managedCol;
                     }
                     /* Note: do not process association's target documents.
                      * They will be handled during the cascade. Initialize
                      * and, if necessary, clear $managedCol for now.
                      */
                     if ($assoc2['isCascadeMerge']) {
                         $managedCol->initialize();
                         // If $managedCol differs from the merged collection, clear and set dirty
                         if (!$managedCol->isEmpty() && $managedCol !== $mergeCol) {
                             $managedCol->unwrap()->clear();
                             $managedCol->setDirty(true);
                             if ($assoc2['isOwningSide'] && $class->isChangeTrackingNotify()) {
                                 $this->scheduleForDirtyCheck($managedCopy);
                             }
                         }
                     }
                 }
             }
             if ($class->isChangeTrackingNotify()) {
                 // Just treat all properties as changed, there is no other choice.
                 $this->propertyChanged($managedCopy, $name, null, $prop->getValue($managedCopy));
             }
         }
         if ($class->isChangeTrackingDeferredExplicit()) {
             $this->scheduleForDirtyCheck($document);
         }
     }
     if ($prevManagedCopy !== null) {
         $assocField = $assoc['fieldName'];
         $prevClass = $this->dm->getClassMetadata(get_class($prevManagedCopy));
         if ($assoc['type'] === 'one') {
             $prevClass->reflFields[$assocField]->setValue($prevManagedCopy, $managedCopy);
         } else {
             $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->add($managedCopy);
             if ($assoc['type'] === 'many' && isset($assoc['mappedBy'])) {
                 $class->reflFields[$assoc['mappedBy']]->setValue($managedCopy, $prevManagedCopy);
             }
         }
     }
     // Mark the managed copy visited as well
     $visited[spl_object_hash($managedCopy)] = true;
     $this->cascadeMerge($document, $managedCopy, $visited);
     return $managedCopy;
 }
 /**
  * Commits the UnitOfWork, executing all operations that have been postponed
  * up to this point. The state of all managed documents will be synchronized with
  * the database.
  *
  * The operations are executed in the following order:
  *
  * 1) All document insertions
  * 2) All document updates
  * 3) All document deletions
  *
  * @param object $document
  * @param array $options Array of options to be used with batchInsert(), update() and remove()
  */
 public function commit($document = null, array $options = array())
 {
     // Raise preFlush
     if ($this->evm->hasListeners(Events::preFlush)) {
         $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm));
     }
     $defaultOptions = $this->dm->getConfiguration()->getDefaultCommitOptions();
     if ($options) {
         $options = array_merge($defaultOptions, $options);
     } else {
         $options = $defaultOptions;
     }
     // Compute changes done since last commit.
     if ($document === null) {
         $this->computeChangeSets();
     } elseif (is_object($document)) {
         $this->computeSingleDocumentChangeSet($document);
     } elseif (is_array($document)) {
         foreach ($document as $object) {
             $this->computeSingleDocumentChangeSet($object);
         }
     }
     if (!($this->documentInsertions || $this->documentUpserts || $this->documentDeletions || $this->documentUpdates || $this->collectionUpdates || $this->collectionDeletions || $this->orphanRemovals)) {
         return;
         // Nothing to do.
     }
     if ($this->orphanRemovals) {
         foreach ($this->orphanRemovals as $removal) {
             $this->remove($removal);
         }
     }
     // Raise onFlush
     if ($this->evm->hasListeners(Events::onFlush)) {
         $this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm));
     }
     // Now we need a commit order to maintain referential integrity
     $commitOrder = $this->getCommitOrder();
     if ($this->documentUpserts) {
         foreach ($commitOrder as $class) {
             if ($class->isEmbeddedDocument) {
                 continue;
             }
             $this->executeUpserts($class, $options);
         }
     }
     if ($this->documentInsertions) {
         foreach ($commitOrder as $class) {
             if ($class->isEmbeddedDocument) {
                 continue;
             }
             $this->executeInserts($class, $options);
         }
     }
     if ($this->documentUpdates) {
         foreach ($commitOrder as $class) {
             $this->executeUpdates($class, $options);
         }
     }
     // Extra updates that were requested by persisters.
     if ($this->extraUpdates) {
         $this->executeExtraUpdates($options);
     }
     // Collection deletions (deletions of complete collections)
     foreach ($this->collectionDeletions as $collectionToDelete) {
         $this->getCollectionPersister()->delete($collectionToDelete, $options);
     }
     // Collection updates (deleteRows, updateRows, insertRows)
     foreach ($this->collectionUpdates as $collectionToUpdate) {
         $this->getCollectionPersister()->update($collectionToUpdate, $options);
     }
     // Document deletions come last and need to be in reverse commit order
     if ($this->documentDeletions) {
         for ($count = count($commitOrder), $i = $count - 1; $i >= 0; --$i) {
             $this->executeDeletions($commitOrder[$i], $options);
         }
     }
     // Take new snapshots from visited collections
     foreach ($this->visitedCollections as $coll) {
         $coll->takeSnapshot();
     }
     // Raise postFlush
     if ($this->evm->hasListeners(Events::postFlush)) {
         $this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm));
     }
     // Clear up
     $this->documentInsertions = $this->documentUpserts = $this->documentUpdates = $this->documentDeletions = $this->extraUpdates = $this->documentChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = $this->scheduledForDirtyCheck = $this->orphanRemovals = $this->hasScheduledCollections = array();
 }
Beispiel #20
0
 /**
  * Create a new MongoDB Query.
  *
  * @param DocumentManager $dm
  * @param string $className
  */
 public function __construct(DocumentManager $dm, $className = null)
 {
     $this->dm = $dm;
     $this->hydrator = $dm->getHydrator();
     $this->cmd = $dm->getConfiguration()->getMongoCmd();
     if ($className !== null) {
         $this->find($className);
     }
 }
 /**
  * Returns whether Doctrine 2 metadata exists for that class
  *
  * @param string $class
  * @return Boolean
  */
 protected function isMappedClass($class)
 {
     return !$this->documentManager->getConfiguration()->getMetadataDriverImpl()->isTransient($class);
 }
 function let(DocumentManager $dm, Configuration $configuration)
 {
     $dm->getConfiguration()->willReturn($configuration);
 }
Beispiel #23
0
 /**
  * Commits the UnitOfWork, executing all operations that have been postponed
  * up to this point. The state of all managed documents will be synchronized with
  * the database.
  *
  * The operations are executed in the following order:
  *
  * 1) All document insertions
  * 2) All document updates
  * 3) All document deletions
  *
  * @param object $document
  * @param array $options Array of options to be used with batchInsert(), update() and remove()
  */
 public function commit($document = null, array $options = array())
 {
     // Raise preFlush
     if ($this->evm->hasListeners(Events::preFlush)) {
         $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm));
     }
     $defaultOptions = $this->dm->getConfiguration()->getDefaultCommitOptions();
     if ($options) {
         $options = array_merge($defaultOptions, $options);
     } else {
         $options = $defaultOptions;
     }
     // Compute changes done since last commit.
     if ($document === null) {
         $this->computeChangeSets();
     } elseif (is_object($document)) {
         $this->computeSingleDocumentChangeSet($document);
     } elseif (is_array($document)) {
         foreach ($document as $object) {
             $this->computeSingleDocumentChangeSet($object);
         }
     }
     if (!($this->documentInsertions || $this->documentUpserts || $this->documentDeletions || $this->documentUpdates || $this->collectionUpdates || $this->collectionDeletions || $this->orphanRemovals)) {
         return;
         // Nothing to do.
     }
     if ($this->orphanRemovals) {
         foreach ($this->orphanRemovals as $removal) {
             $this->remove($removal);
         }
     }
     // Raise onFlush
     if ($this->evm->hasListeners(Events::onFlush)) {
         $this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm));
     }
     foreach ($this->getClassesForCommitAction($this->documentUpserts) as $class) {
         if (!$class->isEmbeddedDocument) {
             $this->executeUpserts($class, $options);
         }
     }
     foreach ($this->getClassesForCommitAction($this->documentInsertions) as $class) {
         if (!$class->isEmbeddedDocument) {
             $this->executeInserts($class, $options);
         }
     }
     foreach ($this->getClassesForCommitAction($this->documentUpdates) as $class) {
         $this->executeUpdates($class, $options);
     }
     // Collection deletions (deletions of complete collections)
     foreach ($this->collectionDeletions as $collectionToDelete) {
         $this->getCollectionPersister()->delete($collectionToDelete, $options);
     }
     // Collection updates (deleteRows, updateRows, insertRows)
     foreach ($this->collectionUpdates as $collectionToUpdate) {
         $this->getCollectionPersister()->update($collectionToUpdate, $options);
     }
     foreach ($this->getClassesForCommitAction($this->documentDeletions) as $class) {
         $this->executeDeletions($class, $options);
     }
     // Take new snapshots from visited collections
     foreach ($this->visitedCollections as $coll) {
         $coll->takeSnapshot();
     }
     // Raise postFlush
     if ($this->evm->hasListeners(Events::postFlush)) {
         $this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm));
     }
     // Clear up
     $this->documentInsertions = $this->documentUpserts = $this->documentUpdates = $this->documentDeletions = $this->documentChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = $this->scheduledForDirtyCheck = $this->orphanRemovals = $this->hasScheduledCollections = array();
 }
 /**
  * @param $logger
  *
  * @return DocumentManager
  */
 private function getNewDmWithLogger($logger)
 {
     $this->dm->getConfiguration()->setLoggerCallable($logger);
     $dm = DocumentManager::create($this->dm->getConnection(), $this->dm->getConfiguration());
     return $dm;
 }
Beispiel #25
0
 /**
  * Constructor.
  *
  * @param DocumentManager $dm
  */
 public function __construct(DocumentManager $dm)
 {
     $this->dm = $dm;
     $this->config = $dm->getConfiguration();
 }
Beispiel #26
0
 /**
  * Create a new Hydrator instance
  *
  * @param Doctrine\ODM\MongoDB\DocumentManager $dm
  */
 public function __construct(DocumentManager $dm)
 {
     $this->_dm = $dm;
     $this->_cmd = $dm->getConfiguration()->getMongoCmd();
 }
Beispiel #27
0
 /**
  * Commits the UnitOfWork, executing all operations that have been postponed
  * up to this point. The state of all managed documents will be synchronized with
  * the database.
  *
  * The operations are executed in the following order:
  *
  * 1) All document insertions
  * 2) All document updates
  * 3) All document deletions
  *
  * @param object $document
  * @param array $options Array of options to be used with batchInsert(), update() and remove()
  */
 public function commit($document = null, array $options = array())
 {
     // Raise preFlush
     if ($this->evm->hasListeners(Events::preFlush)) {
         $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm));
     }
     $defaultOptions = $this->dm->getConfiguration()->getDefaultCommitOptions();
     if ($options) {
         $options = array_merge($defaultOptions, $options);
     } else {
         $options = $defaultOptions;
     }
     // Compute changes done since last commit.
     if ($document === null) {
         $this->computeChangeSets();
     } elseif (is_object($document)) {
         $this->computeSingleDocumentChangeSet($document);
     } elseif (is_array($document)) {
         foreach ($document as $object) {
             $this->computeSingleDocumentChangeSet($object);
         }
     }
     if (!($this->documentInsertions || $this->documentUpserts || $this->documentDeletions || $this->documentUpdates || $this->collectionUpdates || $this->collectionDeletions || $this->orphanRemovals)) {
         return;
         // Nothing to do.
     }
     if ($this->orphanRemovals) {
         foreach ($this->orphanRemovals as $removal) {
             $this->remove($removal);
         }
     }
     // Raise onFlush
     if ($this->evm->hasListeners(Events::onFlush)) {
         $this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm));
     }
     foreach ($this->getClassesForCommitAction($this->documentUpserts) as $classAndDocuments) {
         list($class, $documents) = $classAndDocuments;
         $this->executeUpserts($class, $documents, $options);
     }
     foreach ($this->getClassesForCommitAction($this->documentInsertions) as $classAndDocuments) {
         list($class, $documents) = $classAndDocuments;
         $this->executeInserts($class, $documents, $options);
     }
     foreach ($this->getClassesForCommitAction($this->documentUpdates) as $classAndDocuments) {
         list($class, $documents) = $classAndDocuments;
         $this->executeUpdates($class, $documents, $options);
     }
     foreach ($this->getClassesForCommitAction($this->documentDeletions, true) as $classAndDocuments) {
         list($class, $documents) = $classAndDocuments;
         $this->executeDeletions($class, $documents, $options);
     }
     // Raise postFlush
     if ($this->evm->hasListeners(Events::postFlush)) {
         $this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm));
     }
     // Clear up
     $this->documentInsertions = $this->documentUpserts = $this->documentUpdates = $this->documentDeletions = $this->documentChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = $this->scheduledForDirtyCheck = $this->orphanRemovals = $this->hasScheduledCollections = array();
 }
Beispiel #28
0
 /**
  * Create a new MongoDB Query.
  *
  * @param DocumentManager $dm
  * @param string $className
  */
 public function __construct(DocumentManager $dm, $className = null)
 {
     $this->_dm = $dm;
     $this->_hydrator = $dm->getHydrator();
     if ($className !== null) {
         $this->_className = $className;
         $this->_class = $this->_dm->getClassMetadata($className);
     }
     $this->_cmd = $dm->getConfiguration()->getMongoCmd();
 }