Doctrine\ORM\UnitOfWork::computeChangeSets PHP Method

computeChangeSets() public method

Computes all the changes that have been done to entities and collections since the last commit and stores these changes in the _entityChangeSet map temporarily for access by the persisters, until the UoW commit is finished.
public computeChangeSets ( )
    public function computeChangeSets()
    {
        // Compute changes for INSERTed entities first. This must always happen.
        foreach ($this->entityInsertions as $entity) {
            $class = $this->em->getClassMetadata(get_class($entity));
            $this->computeChangeSet($class, $entity);
        }

        // Compute changes for other MANAGED entities. Change tracking policies take effect here.
        foreach ($this->identityMap as $className => $entities) {
            $class = $this->em->getClassMetadata($className);

            // Skip class if instances are read-only
            //if ($class->isReadOnly) {
            //    continue;
            //}

            // If change tracking is explicit or happens through notification, then only compute
            // changes on entities of that type that are explicitly marked for synchronization.
            $entitiesToProcess = ! $class->isChangeTrackingDeferredImplicit() ?
                    (isset($this->scheduledForDirtyCheck[$className]) ?
                        $this->scheduledForDirtyCheck[$className] : array())
                    : $entities;

            foreach ($entitiesToProcess as $entity) {
                // Ignore uninitialized proxy objects
                if (/* $entity is readOnly || */ $entity instanceof Proxy && ! $entity->__isInitialized__) {
                    continue;
                }
                // Only MANAGED entities that are NOT SCHEDULED FOR INSERTION are processed here.
                $oid = spl_object_hash($entity);
                if ( ! isset($this->entityInsertions[$oid]) && isset($this->entityStates[$oid])) {
                    $this->computeChangeSet($class, $entity);
                }
            }
        }
    }

Usage Example

 /**
  * @param \Doctrine\ORM\Event\PreFlushEventArgs $eventArgs
  *
  * @author Andreas Glaser
  */
 public function preFlush(PreFlushEventArgs $eventArgs)
 {
     $this->entityManager = $eventArgs->getEntityManager();
     $this->unitOfWork = $this->entityManager->getUnitOfWork();
     if ($this->config['common_entity_event_handler']) {
         if (class_exists($this->config['common_entity_event_handler'])) {
             $this->commonEntityEventHandler = new $this->config['common_entity_event_handler']($this->container, $this, $this->entityManager);
         } else {
             throw new \InvalidArgumentException(strtr('":class" does not exist', [':class' => $this->config['common_entity_event_handler']]));
         }
     }
     $this->unitOfWork->computeChangeSets();
     $max = 50;
     $current = 0;
     do {
         $runAgain = $this->executeEvents();
         $current++;
     } while ($runAgain === true && $current <= $max);
     if ($current >= $max) {
         throw new \RuntimeException('Too many iterations... something must have gone wrong.');
     }
 }
All Usage Examples Of Doctrine\ORM\UnitOfWork::computeChangeSets