Skip to content

Commit

Permalink
doctrine#6118 removing UnitOfWork#commit\($entity\) signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius authored and lcobucci committed Jul 28, 2017
1 parent 2098b9e commit b55a484
Showing 1 changed file with 2 additions and 61 deletions.
63 changes: 2 additions & 61 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,29 +318,18 @@ public function __construct(EntityManagerInterface $em)
* 4) All collection updates
* 5) All entity deletions
*
* @param null|object|array $entity
*
* @return void
*
* @throws \Exception
*/
public function commit($entity = null)
public function commit()
{
// Raise preFlush
if ($this->eventManager->hasListeners(Events::preFlush)) {
$this->eventManager->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->em));
}

// Compute changes done since last commit.
if ($entity === null) {
$this->computeChangeSets();
} elseif (is_object($entity)) {
$this->computeSingleEntityChangeSet($entity);
} elseif (is_array($entity)) {
foreach ($entity as $object) {
$this->computeSingleEntityChangeSet($object);
}
}
$this->computeChangeSets();

if ( ! ($this->entityInsertions ||
$this->entityDeletions ||
Expand Down Expand Up @@ -449,54 +438,6 @@ private function computeScheduleInsertsChangeSets()
}
}

/**
* Only flushes the given entity according to a ruleset that keeps the UoW consistent.
*
* 1. All entities scheduled for insertion, (orphan) removals and changes in collections are processed as well!
* 2. Read Only entities are skipped.
* 3. Proxies are skipped.
* 4. Only if entity is properly managed.
*
* @param object $entity
*
* @return void
*
* @throws \InvalidArgumentException
*/
private function computeSingleEntityChangeSet($entity)
{
$state = $this->getEntityState($entity);

if ($state !== self::STATE_MANAGED && $state !== self::STATE_REMOVED) {
throw new \InvalidArgumentException("Entity has to be managed or scheduled for removal for single computation " . self::objToStr($entity));
}

$class = $this->em->getClassMetadata(get_class($entity));

if ($state === self::STATE_MANAGED && $class->changeTrackingPolicy === ChangeTrackingPolicy::DEFERRED_IMPLICIT) {
$this->persist($entity);
}

// Compute changes for INSERTed entities first. This must always happen even in this case.
$this->computeScheduleInsertsChangeSets();

if ($class->isReadOnly()) {
return;
}

// Ignore uninitialized proxy objects
if ($entity instanceof Proxy && ! $entity->__isInitialized()) {
return;
}

// Only MANAGED entities that are NOT SCHEDULED FOR INSERTION OR DELETION are processed here.
$oid = spl_object_hash($entity);

if ( ! isset($this->entityInsertions[$oid]) && ! isset($this->entityDeletions[$oid]) && isset($this->entityStates[$oid])) {
$this->computeChangeSet($class, $entity);
}
}

/**
* Executes any extra updates that have been scheduled.
*/
Expand Down

0 comments on commit b55a484

Please sign in to comment.