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.

@return void
978260
public function computeChangeSets()
    {
        // Compute changes for INSERTed entities first. This must always happen.
        $this->computeScheduleInsertsChangeSets();

        // 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.
            switch (true) {
                case ($class->isChangeTrackingDeferredImplicit()):
                    $entitiesToProcess = $entities;
                    break;

                case (isset($this->scheduledForSynchronization[$className])):
                    $entitiesToProcess = $this->scheduledForSynchronization[$className];
                    break;

                default:
                    $entitiesToProcess = array();

            }

            foreach ($entitiesToProcess as $entity) {
                // Ignore uninitialized proxy objects
                if ($entity instanceof Proxy && ! $entity->__isInitialized__) {
                    continue;
                }

                // 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);
                }
            }
        }
    }
1273442
public function postSave()
    {

        // check if the model already exists
        if ((!isset($this->revisionEnabled) || $this->revisionEnabled) && $this->updating) {
            // if it does, it means we're updating

            $changes_to_record = $this->changedRevisionableFields();

            $revisions = array();

            foreach ($changes_to_record as $key => $change) {
                $revisions[] = array(
                    'revisionable_type'     => $this->getMorphClass(),
                    'revisionable_id'       => $this->getKey(),
                    'key'                   => $key,
                    'old_value'             => array_get($this->originalData, $key),
                    'new_value'             => $this->updatedData[$key],
                    'user_id'               => $this->getSystemUserId(),
                    'created_at'            => new \DateTime(),
                    'updated_at'            => new \DateTime(),
                );
            }

            if (count($revisions) > 0) {
                $revision = static::newModel();
                \DB::table($revision->getTable())->insert($revisions);
            }
        }
    }
901552
public function commit() : void
    {
        $this->eventDispatcher->dispatchPreFlush();

        if ($this->objectsToPersist === [] &&
            $this->objectsToUpdate === [] &&
            $this->objectsToRemove === []
        ) {
            return; // Nothing to do.
        }

        $objects = array_merge(
            $this->objectsToPersist,
            $this->objectsToUpdate,
            $this->objectsToRemove
        );
        $this->eventDispatcher->dispatchPreFlushLifecycleCallbacks($objects);

        $this->eventDispatcher->dispatchOnFlush();

        $this->persister->executePersists();
        $this->persister->executeUpdates();
        $this->persister->executeRemoves();

        $this->eventDispatcher->dispatchPostFlush();

        $this->objectsToPersist = [];
        $this->objectsToUpdate  = [];
        $this->objectsToRemove  = [];
        $this->objectChangeSets = new ChangeSets();
    }
605844
public function saveToAndGetClonedEntities()
    {
        $data = $this->transformFromFormData($this->data);

        $cloned_entities = array();
        foreach ($this->entities as $entity) {
            $entity['entity'] = clone $entity['entity'];
            $cloned_entities[] = $entity;

            if ($entity['entity'] instanceof EntityInterface) {
                $entity['entity']->setFormData($data, $entity['fields']);
            } else {
                $this->entityProcessor->saveToEntity($entity['entity'], $data, $entity['fields']);
            }
        }

        return $cloned_entities;
    }
1079351
private function changed()
    {
        if ($this->isDirty) {
            return;
        }

        $this->isDirty = true;

        if ($this->association !== null &&
            $this->association['isOwningSide'] &&
            $this->association['type'] === ClassMetadata::MANY_TO_MANY &&
            $this->owner &&
            $this->em->getClassMetadata(get_class($this->owner))->isChangeTrackingNotify()) {
            $this->em->getUnitOfWork()->scheduleForDirtyCheck($this->owner);
        }
    }
1086891
protected function syncAttendees(): void
    {
        //sync all the attendees from users.
        $users = $this->usersTable->find()->all();
        $result = [];

        /** @var \Cake\Shell\Helper\ProgressHelper $progress */
        $progress = $this->helper('Progress');
        $progress->init();
        $this->out(null);
        $this->info('Syncing attendees...');

        $count = 1;
        /** @var \Cake\Datasource\EntityInterface $user */
        foreach ($users as $k => $user) {
            if (empty($user->email)) {
                continue;
            }

            $existing = $this->attendeesTable->exists(['contact_details' => $user->email]);

            if (!$existing) {
                $entity = $this->attendeesTable->newEntity();

                $entity->set('display_name', $user->get('name'));
                $entity->set('contact_details', $user->get('email'));

                $saved = $this->attendeesTable->save($entity);
                if ($saved) {
                    array_push($result, $saved);
                }
            }

            $progress->increment(100 / ++$count);
            $progress->draw();
        }

        $this->out(null);

        if (!empty($result)) {
            $this->out('<success> [' . count($result) . ']Attendees synchronized!</success>');
        }

        $this->out(null);
    }
944748
public function upgradeCoreData()
    {
        $entity = $this->getPackageEntity();
        if ($entity !== null) {
            $em = $this->app->make(EntityManagerInterface::class);
            $entity->setPackageName($this->getPackageName());
            $entity->setPackageDescription($this->getPackageDescription());
            $entity->setPackageVersion($this->getPackageVersion());
            $em->persist($entity);
            $em->flush();
        }
    }
230226
private function commitPersisted()
    {
        $sortedDocuments = $this->sortObjects($this->scheduledForPersist);
        $client = $this->sm->getClient();

        foreach ($sortedDocuments as $entityName => $documents) {
            $classMetadata = $this->sm->getClassMetadata($entityName);
            $this->updatedIndexes[] = $classMetadata->index;
            $client->addDocuments($classMetadata, $documents);
        }
    }
33723
public function commit(): void
    {
        $this->committedSequence = $this->lastSequence();
        $this->eventRecords = SortedSet::comparable(EventRecord::class);
    }
941289
public function beforeUpdate()
    {
        foreach ($this->models as $relationName => $config) {
            $this->markFilesAsPermanent($this->getRelationValues($relationName));
        }
    }
1256757
public function persistEntities()
    {
        foreach ($this->entityManager->getUnitOfWork()->getIdentityMap() as $className => $entities) {
            if ($className === $this->entityClassName) {
                $this->entityManager->flush($entities);
                return;
            }
        }
    }
1230710
public function commit()
    {
        try {
            $this->connection->commit();
        } catch (DBALException $e) {
            throw new OrmException("Unable to commit changes.\n" . $e->getMessage(), 0, $e);
        }
    }
791943
private function commitRemoved()
    {
        $documents = $this->sortObjects($this->scheduledForDelete, false);
        $client = $this->sm->getClient();

        foreach ($documents as $entityName => $documents) {
            $classMetadata = $this->sm->getClassMetadata($entityName);
            $this->updatedIndexes[] = $classMetadata->index;
            $client->removeDocuments($classMetadata, $documents);
        }
    }
1213341
public function saveHandler()
    {
        if ($this->changed) {
            $class = $this->getRemoteClass();
            (new $class)->entity->updateRelatedThroughTable($this->table, $this->remoteAttributeName, $this->relatedAttributeName, $this->getIds(), $this->model, $this->filterList);
        }
    }
1138076
public function commit()
    {
        list($old, $new) = $this->generateRollback();
        $updates = $this->generateUpdates();
        $updates = $this->combineUpdates($updates);
        usort($updates, array($this, 'sortUpdates'));

        foreach ($updates as $update) {
            // apply update to cache & receive a simple bool to indicate
            // success (true) or failure (false)
            $success = call_user_func_array($update[1], $update[2]);
            if ($success === false) {
                $this->rollback($old, $new);

                return false;
            }
        }

        $this->clear();

        return true;
    }
216233
protected function updateDependantObjects()
    {
        // Skip live stage
        if (class_exists(Versioned::class) && Versioned::get_stage() === Versioned::LIVE) {
            return;
        }

        // Need to flush cache to avoid outdated versionnumber references
        $this->flushCache();

        // Trigger update of all parent owners on change
        /** @var DataObject|FileLinkTracking $object */
        foreach ($this->BackLinkTracking() as $object) {
            // Update sync link tracking
            $object->syncLinkTracking();
            if ($object->isChanged()) {
                $object->write();
            }
        }
    }
693192
public function commit()
    {
        if ($this->evm->hasListeners(Events::preFlush)) {
            $this->evm->dispatchEvent(Events::preFlush, new PreFlushEventArgs($this->manager));
        }

        $this->computeChangeSets();

        if (! (
            $this->documentInsertions ||
            $this->documentDeletions ||
            $this->documentUpdates ||
            $this->documentChangeSets
        )) {
            // Nothing to do.
            $this->dispatchOnFlush();
            $this->dispatchPostFlush();

            return;
        }

        $classOrder = $this->getCommitOrder();

        $this->dispatchOnFlush();

        foreach ($classOrder as $className) {
            $this->executeInserts($className);
            $this->executeUpdates($className);
            $this->executeDeletions($className);

            $this->getDocumentPersister($className)->refreshCollection();
        }

        $this->dispatchPostFlush();
        $this->postCommitCleanup();
    }