/** * 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->orphanRemovals = array(); if ($this->commitOrderCalculator !== null) { $this->commitOrderCalculator->clear(); } }
/** * 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->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)); } }
/** * 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; }
/** * Clears the UnitOfWork. * * @param string $entityName if given, only entities of this type will get detached */ 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->orphanRemovals = array(); if ($this->commitOrderCalculator !== null) { $this->commitOrderCalculator->clear(); } } else { $visited = array(); foreach ($this->identityMap as $className => $entities) { if ($className === $entityName) { foreach ($entities as $entity) { $this->doDetach($entity, $visited, true); } } } } if ($this->evm->hasListeners(Events::onClear)) { $this->evm->dispatchEvent(Events::onClear, new Event\OnClearEventArgs($this->em, $entityName)); } }
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(); }