Exemple #1
0
 /**
  * Detect truncate table names by class metadatas
  *
  * @param array $metadatas Class metadata list
  *
  * @return array
  */
 protected function detectTruncateTables(array $metadatas)
 {
     $calc = new \Doctrine\ORM\Internal\CommitOrderCalculator();
     foreach ($metadatas as $class) {
         $calc->addClass($class);
         foreach ($class->associationMappings as $assoc) {
             if ($assoc['isOwningSide']) {
                 $targetClass = static::$em->getClassMetadata($assoc['targetEntity']);
                 if (!$calc->hasClass($targetClass->name)) {
                     $calc->addClass($targetClass);
                 }
                 // add dependency ($targetClass before $class)
                 $calc->addDependency($targetClass, $class);
             }
         }
     }
     $commitOrder = $calc->getCommitOrder();
     $associationTables = array();
     foreach ($commitOrder as $class) {
         foreach ($class->associationMappings as $assoc) {
             if ($assoc['isOwningSide'] && $assoc['type'] == \Doctrine\ORM\Mapping\ClassMetadata::MANY_TO_MANY) {
                 $associationTables[] = $assoc['joinTable']['name'];
             }
         }
     }
     $orderedTables = array_unique($associationTables);
     // Truncate tables in reverse commit order
     foreach (array_reverse($commitOrder) as $class) {
         if ((!$class->isInheritanceTypeSingleTable() || $class->name == $class->rootEntityName) && !$class->isMappedSuperclass && !in_array($class->getTableName(), $orderedTables)) {
             $orderedTables[] = $class->getTableName();
         }
     }
     return $orderedTables;
 }
 protected function getCommitOrder(\Doctrine\ORM\EntityManager $em, array $classes)
 {
     $calc = new Doctrine\ORM\Internal\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();
 }