/** * {@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(); } }
/** * {@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(); } }