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

The order is important to avoid conflicts 1. operationsLog 2. commit any other changes If transactions are enabled but we are not currently inside a transaction, the session is responsible to start a transaction to make sure the backend state does not get messed up in case of error.
public save ( )
Пример #1
0
 /**
  * {@inheritDoc}
  *
  * Wraps the save operation into a transaction if transactions are enabled
  * but we are not currently inside a transaction and rolls back on error.
  *
  * If transactions are disabled, errors on save can lead to partial saves
  * and inconsistent data.
  *
  * @api
  */
 public function save()
 {
     if ($this->getTransport() instanceof TransactionInterface) {
         try {
             $utx = $this->workspace->getTransactionManager();
         } catch (UnsupportedRepositoryOperationException $e) {
             // user transactions where disabled for this session, do no automatic transaction.
         }
     }
     if (isset($utx) && !$utx->inTransaction()) {
         // do the operation in a short transaction
         $utx->begin();
         try {
             $this->objectManager->save();
             $utx->commit();
         } catch (Exception $e) {
             // if anything goes wrong, rollback this mess
             try {
                 $utx->rollback();
             } catch (Exception $rollbackException) {
                 // ignore this exception
             }
             // but do not eat this exception
             throw $e;
         }
     } else {
         $this->objectManager->save();
     }
 }
Пример #2
0
 /**
  * {@inheritDoc}
  *
  * Wraps the save operation into a transaction if transactions are enabled
  * but we are not currently inside a transaction and rolls back on error.
  *
  * If transactions are disabled, errors on save can lead to partial saves
  * and inconsistent data.
  *
  * @api
  */
 public function save()
 {
     if ($this->getTransport() instanceof TransactionInterface) {
         $utx = $this->workspace->getTransactionManager();
     }
     if (isset($utx) && !$utx->inTransaction()) {
         // do the operation in a short transaction
         $utx->begin();
         try {
             $this->objectManager->save();
             $utx->commit();
         } catch (Exception $e) {
             // if anything goes wrong, rollback this mess
             $utx->rollback();
             // but do not eat the exception
             throw $e;
         }
     } else {
         $this->objectManager->save();
     }
 }