Doctrine\ODM\PHPCR\UnitOfWork::commit PHP Метод

commit() публичный Метод

Commits the UnitOfWork
public commit ( object | array | null $document = null )
$document object | array | null optionally limit to a specific document or an array of documents
    public function commit($document = null)
    {
        $this->invokeGlobalEvent(Event::preFlush, new ManagerEventArgs($this->dm));
        if ($document === null) {
            $this->computeChangeSets();
        } elseif (is_object($document)) {
            $this->computeSingleDocumentChangeSet($document);
        } elseif (is_array($document)) {
            foreach ($document as $object) {
                $this->computeSingleDocumentChangeSet($object);
            }
        }
        $this->invokeGlobalEvent(Event::onFlush, new ManagerEventArgs($this->dm));
        if (empty($this->scheduledInserts) && empty($this->scheduledUpdates) && empty($this->scheduledRemovals) && empty($this->scheduledReorders) && empty($this->documentTranslations) && empty($this->scheduledMoves)) {
            $this->invokeGlobalEvent(Event::postFlush, new ManagerEventArgs($this->dm));
            $this->changesetComputed = array();
            // @deprecated This is to maintain BC with the old behavior, where users may call
            //             flush instead of PHPCR\SessionInterface#save
            $this->session->save();
            return;
            // Nothing to do.
        }
        try {
            $utx = $this->session->getWorkspace()->getTransactionManager();
            if ($utx->inTransaction()) {
                $utx = null;
            } else {
                $utx->begin();
            }
        } catch (UnsupportedRepositoryOperationException $e) {
            $utx = null;
        }
        try {
            $this->executeInserts($this->scheduledInserts);
            $this->executeUpdates($this->scheduledUpdates);
            $this->executeRemovals($this->scheduledRemovals);
            $this->executeReorders($this->scheduledReorders);
            $this->executeMoves($this->scheduledMoves);
            $this->session->save();
            if ($utx) {
                $utx->commit();
            }
        } catch (\Exception $e) {
            try {
                $this->dm->close();
                if ($utx) {
                    $utx->rollback();
                }
            } catch (\Exception $innerException) {
                //TODO: log error while closing dm after error: $innerException->getMessage
            }
            throw $e;
        }
        foreach ($this->visitedCollections as $col) {
            $col->takeSnapshot();
        }
        $this->invokeGlobalEvent(Event::postFlush, new ManagerEventArgs($this->dm));
        if (null === $document) {
            foreach ($this->documentLocales as $oid => $locales) {
                $this->documentLocales[$oid]['original'] = $locales['current'];
            }
        } else {
            $documents = is_array($document) ? $document : array($document);
            foreach ($documents as $doc) {
                $oid = spl_object_hash($doc);
                if (isset($this->documentLocales[$oid])) {
                    $this->documentLocales[$oid]['original'] = $this->documentLocales[$oid]['current'];
                }
            }
        }
        $this->scheduledUpdates = $this->scheduledRemovals = $this->scheduledMoves = $this->scheduledReorders = $this->scheduledInserts = $this->visitedCollections = $this->documentChangesets = $this->changesetComputed = array();
        $this->invokeGlobalEvent(Event::endFlush, new ManagerEventArgs($this->dm));
    }

Usage Example

Пример #1
0
 /**
  * {@inheritDoc}
  *
  * Flush all current changes, that is save them within the phpcr session
  * and commit that session to permanent storage.
  *
  * @param object|array|null $document optionally limit to a specific
  *      document or an array of documents
  *
  * @throws InvalidArgumentException if $document is neither null nor a
  *      document or an array of documents
  */
 public function flush($document = null)
 {
     if (null !== $document && !is_object($document) && !is_array($document)) {
         throw new InvalidArgumentException('Parameter $document needs to be an object, ' . gettype($document) . ' given');
     }
     $this->errorIfClosed();
     $this->unitOfWork->commit($document);
 }
All Usage Examples Of Doctrine\ODM\PHPCR\UnitOfWork::commit
UnitOfWork