Exemple #1
0
 /**
  * Gets the commit order.
  *
  * @return array
  */
 private function _getCommitOrder(array $entityChangeSet = null)
 {
     if ($entityChangeSet === null) {
         $entityChangeSet = array_merge($this->_entityInsertions, $this->_entityUpdates, $this->_entityDeletions);
     }
     // TODO: We can cache computed commit orders in the metadata cache!
     // Check cache at this point here!
     // See if there are any new classes in the changeset, that are not in the
     // commit order graph yet (dont have a node).
     $newNodes = array();
     foreach ($entityChangeSet as $entity) {
         $className = get_class($entity);
         if (!$this->_commitOrderCalculator->hasNodeWithKey($className)) {
             $this->_commitOrderCalculator->addNodeWithItem($className, $this->_em->getClassMetadata($className));
             $newNodes[] = $this->_commitOrderCalculator->getNodeForKey($className);
         }
     }
     // Calculate dependencies for new nodes
     foreach ($newNodes as $node) {
         $class = $node->getClass();
         foreach ($class->associationMappings as $assocMapping) {
             //TODO: should skip target classes that are not in the changeset.
             if ($assocMapping->isOwningSide) {
                 $targetClass = $this->_em->getClassMetadata($assocMapping->targetEntityName);
                 $targetClassName = $targetClass->name;
                 // If the target class does not yet have a node, create it
                 if (!$this->_commitOrderCalculator->hasNodeWithKey($targetClassName)) {
                     $this->_commitOrderCalculator->addNodeWithItem($targetClassName, $targetClass);
                 }
                 // add dependency
                 $otherNode = $this->_commitOrderCalculator->getNodeForKey($targetClassName);
                 $otherNode->before($node);
             }
         }
     }
     return $this->_commitOrderCalculator->getCommitOrder();
 }