Beispiel #1
0
 /**
  * Executes all document deletions for documents of the specified type.
  *
  * @param ClassMetadata $class
  * @param array $documents Array of documents to delete
  * @param array $options Array of options to be used with remove()
  */
 private function executeDeletions(ClassMetadata $class, array $documents, array $options = array())
 {
     $hasPostRemoveLifecycleCallbacks = !empty($class->lifecycleCallbacks[Events::postRemove]);
     $hasPostRemoveListeners = $this->evm->hasListeners(Events::postRemove);
     $persister = $this->getDocumentPersister($class->name);
     foreach ($documents as $oid => $document) {
         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->associationMappings as $fieldMapping) {
             if (isset($fieldMapping['type']) && $fieldMapping['type'] === ClassMetadata::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 ($hasPostRemoveLifecycleCallbacks) {
             $class->invokeLifecycleCallbacks(Events::postRemove, $document);
         }
         if ($hasPostRemoveListeners) {
             $this->evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($document, $this->dm));
         }
     }
 }