/**
  * {@inheritdoc}
  */
 protected function getCommitOrder(EntityManager $em, array $classes)
 {
     $calc = new CommitOrderCalculator();
     foreach ($classes as $class) {
         $calc->addClass($class);
         // $class before its parents
         foreach ($class->parentClasses as $parentClass) {
             $parentClass = $em->getClassMetadata($parentClass);
             if (!$calc->hasClass($parentClass->name)) {
                 $calc->addClass($parentClass);
             }
             $calc->addDependency($class, $parentClass);
         }
         foreach ($class->associationMappings as $assoc) {
             if ($assoc['isOwningSide']) {
                 $targetClass = $em->getClassMetadata($assoc['targetEntity']);
                 if (!$calc->hasClass($targetClass->name)) {
                     $calc->addClass($targetClass);
                 }
                 // add dependency ($targetClass before $class)
                 $calc->addDependency($targetClass, $class);
                 // parents of $targetClass before $class, too
                 foreach ($targetClass->parentClasses as $parentClass) {
                     $parentClass = $em->getClassMetadata($parentClass);
                     if (!$calc->hasClass($parentClass->name)) {
                         $calc->addClass($parentClass);
                     }
                     $calc->addDependency($parentClass, $class);
                 }
             }
         }
     }
     return $calc->getCommitOrder();
 }
 protected function getCommitOrder(EntityManager $em, array $classes)
 {
     $calc = new CommitOrderCalculator();
     foreach ($classes as $class) {
         $calc->addClass($class);
         foreach ($class->associationMappings as $assoc) {
             if ($assoc->isOwningSide) {
                 $targetClass = $em->getClassMetadata($assoc->targetEntityName);
                 if (!$calc->hasClass($targetClass->name)) {
                     $calc->addClass($targetClass);
                 }
                 // add dependency ($targetClass before $class)
                 $calc->addDependency($targetClass, $class);
             }
         }
     }
     return $calc->getCommitOrder();
 }
Esempio n. 3
0
 /**
  * Clears the UnitOfWork.
  *
  * @param string|null $entityName if given, only entities of this type will get detached.
  *
  * @return void
  */
 public function clear($entityName = null)
 {
     if ($entityName === null) {
         $this->identityMap = $this->entityIdentifiers = $this->originalEntityData = $this->entityChangeSets = $this->entityStates = $this->scheduledForDirtyCheck = $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = $this->collectionDeletions = $this->collectionUpdates = $this->extraUpdates = $this->readOnlyObjects = $this->visitedCollections = $this->orphanRemovals = array();
         if ($this->commitOrderCalculator !== null) {
             $this->commitOrderCalculator->clear();
         }
     } else {
         $visited = array();
         foreach ($this->identityMap as $className => $entities) {
             if ($className !== $entityName) {
                 continue;
             }
             foreach ($entities as $entity) {
                 $this->doDetach($entity, $visited, false);
             }
         }
     }
     if ($this->evm->hasListeners(Events::onClear)) {
         $this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em, $entityName));
     }
 }
Esempio n. 4
0
 /**
  * Returns the reverse commit order for the given classes
  *
  * @param  array $classes An array of ClassMetadata instances
  *
  * @return array
  */
 private function getReverseCommitOrder(array $classes)
 {
     $calculator = new CommitOrderCalculator();
     foreach ($classes as $class) {
         $calculator->addClass($class);
     }
     return array_reverse($calculator->getCommitOrder());
 }
Esempio n. 5
0
 private function _getCommitOrder(array $classes)
 {
     $calc = new CommitOrderCalculator();
     // Calculate dependencies
     foreach ($classes as $class) {
         $calc->addClass($class);
         foreach ($class->associationMappings as $assoc) {
             if ($assoc->isOwningSide) {
                 $targetClass = $this->_em->getClassMetadata($assoc->targetEntityName);
                 if (!$calc->hasClass($targetClass->name)) {
                     $calc->addClass($targetClass);
                 }
                 // add dependency ($targetClass before $class)
                 $calc->addDependency($targetClass, $class);
             }
         }
     }
     return $calc->getCommitOrder();
 }
 /**
  * Clears the UnitOfWork.
  */
 public function clear()
 {
     $this->identityMap = $this->entityIdentifiers = $this->originalEntityData = $this->entityChangeSets = $this->entityStates = $this->scheduledForDirtyCheck = $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = $this->collectionDeletions = $this->collectionUpdates = $this->extraUpdates = $this->readOnlyObjects = $this->orphanRemovals = array();
     if ($this->commitOrderCalculator !== null) {
         $this->commitOrderCalculator->clear();
     }
     if ($this->evm->hasListeners(Events::onClear)) {
         $this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em));
     }
 }
Esempio n. 7
0
 /**
  * Clears the UnitOfWork.
  */
 public function clear()
 {
     $this->_identityMap = array();
     $this->_entityIdentifiers = array();
     $this->_originalEntityData = array();
     $this->_entityChangeSets = array();
     $this->_entityStates = array();
     $this->_scheduledForDirtyCheck = array();
     $this->_entityInsertions = array();
     $this->_entityUpdates = array();
     $this->_entityDeletions = array();
     $this->_collectionDeletions = array();
     $this->_collectionCreations = array();
     $this->_collectionUpdates = array();
     $this->_commitOrderCalculator->clear();
 }
Esempio n. 8
0
 /**
  * Clears the UnitOfWork.
  *
  * @param string|null $entityName if given, only entities of this type will get detached.
  *
  * @return void
  */
 public function clear($entityName = null)
 {
     if ($entityName === null) {
         $this->identityMap = $this->entityIdentifiers = $this->originalEntityData = $this->entityChangeSets = $this->entityStates = $this->scheduledForSynchronization = $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = $this->collectionDeletions = $this->collectionUpdates = $this->extraUpdates = $this->readOnlyObjects = $this->visitedCollections = $this->orphanRemovals = array();
         if ($this->commitOrderCalculator !== null) {
             $this->commitOrderCalculator->clear();
         }
     } else {
         $this->clearIdentityMapForEntityName($entityName);
         $this->clearEntityInsertionsForEntityName($entityName);
     }
     if ($this->evm->hasListeners(Events::onClear)) {
         $this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em, $entityName));
     }
 }
Esempio n. 9
0
 protected function getDumpOrder(array $classes)
 {
     $calc = new CommitOrderCalculator();
     foreach ($classes as $class) {
         if (!$class->getReflectionClass()->isInstantiable() || $class->isMappedSuperclass) {
             continue;
         }
         $calc->addClass($class);
         // $class before its parents
         foreach ($class->parentClasses as $parentClass) {
             $parentClass = $this->objectManager->getClassMetadata($parentClass);
             if (!$calc->hasClass($parentClass->name)) {
                 $calc->addClass($parentClass);
             }
             $calc->addDependency($class, $parentClass);
         }
         foreach ($class->associationMappings as $assoc) {
             if ($assoc['isOwningSide']) {
                 $targetClass = $this->objectManager->getClassMetadata($assoc['targetEntity']);
                 if (!$calc->hasClass($targetClass->name)) {
                     $calc->addClass($targetClass);
                 }
                 // add dependency ($targetClass before $class)
                 $calc->addDependency($targetClass, $class);
                 // parents of $targetClass before $class, too
                 foreach ($targetClass->parentClasses as $parentClass) {
                     $parentClass = $this->objectManager->getClassMetadata($parentClass);
                     if (!$calc->hasClass($parentClass->name)) {
                         $calc->addClass($parentClass);
                     }
                     $calc->addDependency($parentClass, $class);
                 }
             }
         }
     }
     return $calc->getCommitOrder();
 }