/** * Delete the given documents indexes. * * @param string $documentName The document name to delete the indexes for. */ public function deleteDocumentIndexes($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->getDocumentCollection($documentName)->deleteIndexes(); }
/** * Initializes the collection by loading its contents from the database * if the collection is not yet initialized. */ private function _initialize() { if (!$this->_initialized) { $collection = $this->_dm->getDocumentCollection($this->_typeClass->name); $ids = array(); foreach ($this->_coll as $document) { $ids[] = $this->_typeClass->getIdentifierObject($document); } $data = $collection->find(array('_id' => array('$in' => $ids))); $hints = array(Query::HINT_REFRESH => Query::HINT_REFRESH); foreach ($data as $id => $document) { $document = $this->_dm->getUnitOfWork()->getOrCreateDocument($this->_typeClass->name, $document, $hints); if ($document instanceof Proxy) { $document->__isInitialized__ = true; unset($document->__dm); unset($document->__identifier); } } $this->_initialized = true; } }
/** * Executes all document deletions for documents of the specified type. * * @param Doctrine\ODM\MongoDB\Mapping\ClassMetadata $class * @param array $options Array of options to be used with remove() */ private function executeDeletions(ClassMetadata $class, array $options = array()) { $hasLifecycleCallbacks = isset($class->lifecycleCallbacks[Events::postRemove]); $hasListeners = $this->evm->hasListeners(Events::postRemove); $className = $class->name; $persister = $this->getDocumentPersister($className); $collection = $this->dm->getDocumentCollection($className); foreach ($this->documentDeletions as $oid => $document) { if (get_class($document) == $className || $document instanceof Proxy && $document instanceof $className) { if (!$class->isEmbeddedDocument) { $persister->delete($document, $options); } unset($this->documentDeletions[$oid], $this->documentIdentifiers[$oid], $this->originalDocumentData[$oid]); // Clear snapshot information for any referenced PersistentCollection // http://www.doctrine-project.org/jira/browse/MODM-95 foreach ($class->fieldMappings as $fieldMapping) { if (isset($fieldMapping['type']) && $fieldMapping['type'] === 'many') { $value = $class->reflFields[$fieldMapping['fieldName']]->getValue($document); if ($value instanceof PersistentCollection) { $value->clearSnapshot(); } } } // Document with this $oid after deletion treated as NEW, even if the $oid // is obtained by a new document because the old one went out of scope. $this->documentStates[$oid] = self::STATE_NEW; if ($hasLifecycleCallbacks) { $class->invokeLifecycleCallbacks(Events::postRemove, $document); } if ($hasListeners) { $this->evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($document, $this->dm)); } $this->cascadePostRemove($class, $document); } } }