当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityManagerInterface::commit方法代码示例

本文整理汇总了PHP中Doctrine\ORM\EntityManagerInterface::commit方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::commit方法的具体用法?PHP EntityManagerInterface::commit怎么用?PHP EntityManagerInterface::commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\EntityManagerInterface的用法示例。


在下文中一共展示了EntityManagerInterface::commit方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: urlToShortCode

 /**
  * Creates and persists a unique shortcode generated for provided url
  *
  * @param UriInterface $url
  * @param string[] $tags
  * @return string
  * @throws InvalidUrlException
  * @throws RuntimeException
  */
 public function urlToShortCode(UriInterface $url, array $tags = [])
 {
     // If the url already exists in the database, just return its short code
     $shortUrl = $this->em->getRepository(ShortUrl::class)->findOneBy(['originalUrl' => $url]);
     if (isset($shortUrl)) {
         return $shortUrl->getShortCode();
     }
     // Check that the URL exists
     $this->checkUrlExists($url);
     // Transactionally insert the short url, then generate the short code and finally update the short code
     try {
         $this->em->beginTransaction();
         // First, create the short URL with an empty short code
         $shortUrl = new ShortUrl();
         $shortUrl->setOriginalUrl($url);
         $this->em->persist($shortUrl);
         $this->em->flush();
         // Generate the short code and persist it
         $shortCode = $this->convertAutoincrementIdToShortCode($shortUrl->getId());
         $shortUrl->setShortCode($shortCode)->setTags($this->tagNamesToEntities($this->em, $tags));
         $this->em->flush();
         $this->em->commit();
         return $shortCode;
     } catch (ORMException $e) {
         if ($this->em->getConnection()->isTransactionActive()) {
             $this->em->rollback();
             $this->em->close();
         }
         throw new RuntimeException('An error occurred while persisting the short URL', -1, $e);
     }
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:40,代码来源:UrlShortener.php

示例2: execute

 /**
  * Executes the given command and optionally returns a value
  *
  * @param object $command
  * @param callable $next
  * @return mixed
  * @throws Exception
  */
 public function execute($command, callable $next)
 {
     $this->entityManager->beginTransaction();
     try {
         $returnValue = $next($command);
         $this->entityManager->flush();
         $this->entityManager->commit();
     } catch (Exception $e) {
         $this->entityManager->close();
         $this->entityManager->rollback();
         throw $e;
     }
     return $returnValue;
 }
开发者ID:arnovr,项目名称:tactician-doctrine,代码行数:22,代码来源:TransactionMiddleware.php

示例3: save

 /**
  * @inheritdoc
  */
 public function save(MessageModel $message) : MessageModel
 {
     $this->em->beginTransaction();
     try {
         $this->em->persist($message);
         $this->em->flush();
         $this->em->commit();
         return $message;
     } catch (UniqueConstraintViolationException $ex) {
         $this->em->rollBack();
         throw new InvalidArgumentException('Title is already registered', 409, $ex);
     } catch (Exception $ex) {
         $this->em->rollBack();
         throw new InvalidArgumentException($ex->getMessage(), 500, $ex);
     }
 }
开发者ID:romeumattos,项目名称:twitter-like,代码行数:19,代码来源:Message.php

示例4: batchUpdate

 /**
  * {@inheritdoc}
  */
 public function batchUpdate(MassActionInterface $massAction, IterableResultInterface $results, array $data)
 {
     $this->entityName = $massAction->getOptions()->offsetGet('entityName');
     $this->fieldName = empty($data['mass_edit_field']) ? null : $data['mass_edit_field'];
     if (empty($this->fieldName)) {
         throw new \RuntimeException("Field name was not specified with option 'mass_edit_field'");
     }
     $this->identifierName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($this->entityName);
     $value = $data[$this->fieldName];
     $selectedIds = [];
     $entitiesCount = 0;
     $iteration = 0;
     $this->entityManager = $this->doctrineHelper->getEntityManager($this->entityName);
     $this->entityManager->beginTransaction();
     try {
         set_time_limit(0);
         foreach ($results as $result) {
             /** @var $result ResultRecordInterface */
             $selectedIds[] = $result->getValue($this->identifierName);
             $iteration++;
             if ($iteration % $this->batchSize == 0) {
                 $entitiesCount += $this->finishBatch($selectedIds, $value);
             }
         }
         if ($iteration % $this->batchSize > 0) {
             $entitiesCount += $this->finishBatch($selectedIds, $value);
         }
         $this->entityManager->commit();
     } catch (\Exception $e) {
         $this->entityManager->rollback();
         throw $e;
     }
     return $entitiesCount;
 }
开发者ID:trustify,项目名称:oroplatform-mass-update-bundle,代码行数:37,代码来源:ActionRepository.php

示例5: getIterator

 /**
  * {@inheritDoc}
  */
 public function getIterator()
 {
     $iteration = 0;
     $resultSet = clone $this->resultSet;
     $this->entityManager->beginTransaction();
     try {
         foreach ($resultSet as $key => $value) {
             $iteration += 1;
             if (!is_object($value)) {
                 (yield $key => $value);
                 $this->flushAndClearBatch($iteration);
                 continue;
             }
             (yield $key => $this->reFetchObject($value));
             $this->flushAndClearBatch($iteration);
         }
     } catch (\Exception $exception) {
         $this->entityManager->rollback();
         throw $exception;
     }
     $this->flushAndClearEntityManager();
     $this->entityManager->commit();
 }
开发者ID:Ocramius,项目名称:DoctrineBatchUtils,代码行数:26,代码来源:SimpleBatchIteratorAggregate.php

示例6:

 function it_should_throw_an_exception_if_em_transaction_commit_failed(EntityManagerInterface $entityManager)
 {
     $entityManager->flush()->shouldBeCalledTimes(1);
     $entityManager->commit()->willThrow('\\Exception');
     $this->shouldThrow('\\RemiSan\\TransactionManager\\Exception\\CommitException')->duringCommit();
 }
开发者ID:remi-san,项目名称:transaction-manager,代码行数:6,代码来源:DoctrineEntityManagerSpec.php

示例7: commit

 /**
  * {@inheritdoc}
  */
 public function commit()
 {
     return $this->wrapped->commit();
 }
开发者ID:Dren-x,项目名称:mobitnew,代码行数:7,代码来源:EntityManagerDecorator.php

示例8: commit

 /**
  * @return bool
  */
 public function commit()
 {
     $this->em->flush();
     $this->em->commit();
     return true;
 }
开发者ID:arnaud-23,项目名称:UseCaseBundle,代码行数:9,代码来源:EntityManagerTransactionAdapter.php

示例9: commit

 /**
  * {@inheritDoc}
  */
 public function commit($key = null)
 {
     $this->entityManager->flush();
     $this->entityManager->commit();
 }
开发者ID:fivelab,项目名称:transactional,代码行数:8,代码来源:DoctrineORMTransactional.php

示例10: commit

 /**
  * @return void
  */
 public function commit()
 {
     $this->entityManager->commit();
 }
开发者ID:old-town-gitlab-tools,项目名称:core,代码行数:7,代码来源:TransactionManager.php

示例11: execute

 public function execute()
 {
     $this->entityManager->getConnection()->setTransactionIsolation(Connection::TRANSACTION_SERIALIZABLE);
     $this->entityManager->beginTransaction();
     try {
         $payload = $this->getContent();
         $ext = false;
         echo "processing >> " . $payload['image_src'] . " >> for id >> " . $payload['page_id'] . " >> for ext >> " . $payload['image_ext'] . "\n";
         try {
             $this->httpClient->setUri($payload['image_src']);
             $this->httpClient->getRequest()->setMethod('HEAD');
             $response = $this->httpClient->send();
             if ($response->getHeaders()->get('Content-Type') !== false) {
                 $ext = $this->get_extension($response->getHeaders()->get('Content-Type')->getFieldValue());
             }
         } catch (\Zend\Http\Exception\InvalidArgumentException $e) {
             echo "Exception: while sending HEAD method >> " . $e->getMessage() . "\n";
         }
         echo "declared ext >> " . $payload['image_ext'] . " >> detected ext >> " . $ext . "\n";
         if ($ext === false) {
             echo "Not an image \n";
             $pageEntity = $this->updatePending($payload['page_id']);
             echo "processed >> " . $payload['image_src'] . " >> pendingCnt >> " . $pageEntity->getPendingImagesCnt() . " >> status >> " . $pageEntity->getStatus() . "\n";
             $this->entityManager->flush();
             $this->entityManager->commit();
             return;
         }
         $this->httpClient->getRequest()->setMethod('GET');
         $response = $this->httpClient->send();
         if ($ext == 'svg') {
             $xmlget = simplexml_load_string($response->getBody());
             $xmlattributes = $xmlget->attributes();
             $width = preg_replace('/[^0-9.]/', '', strtolower((string) $xmlattributes->width));
             $height = preg_replace('/[^0-9.]/', '', strtolower((string) $xmlattributes->height));
             $imageInfo = [$width, $height, 'mime' => $response->getHeaders()->get('Content-Type')->getFieldValue()];
             $imageSize = mb_strlen($response->getBody(), '8bit');
         } else {
             $imageInfo = getimagesizefromstring($response->getBody());
             $contentLength = $response->getHeaders()->get('Content-Length');
             if ($contentLength === false) {
                 $imageSize = mb_strlen($response->getBody(), '8bit');
             } else {
                 $imageSize = $contentLength->getFieldValue();
             }
         }
         $url = $this->storageService->store($payload['image_ext'], $response->getBody());
         $imageEntity = new Images();
         $imageEntity->setContentType($imageInfo['mime']);
         $imageEntity->setWidth($imageInfo[0]);
         $imageEntity->setHeight($imageInfo[1]);
         $imageEntity->setSize($imageSize);
         $imageEntity->setLocalPath($url);
         $imageEntity->setRemotePath($payload['image_src']);
         $pageEntity = $this->updatePending($payload['page_id']);
         $imageEntity->setPage($pageEntity);
         $this->entityManager->persist($imageEntity);
         echo "processed >> " . $payload['image_src'] . " >> pendingCnt >> " . $pageEntity->getPendingImagesCnt() . " >> status >> " . $pageEntity->getStatus() . "\n";
         $this->entityManager->flush();
         $this->entityManager->commit();
     } catch (\Exception $e) {
         $this->entityManager->rollback();
         echo "Exception : >>>> " . $e->getMessage() . "\n";
         throw new ReleasableException(array('priority' => 10, 'delay' => 15));
     }
 }
开发者ID:spalax,项目名称:eu-webchalange-download-images-api,代码行数:65,代码来源:GrabImage.php


注:本文中的Doctrine\ORM\EntityManagerInterface::commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。