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


PHP EntityManagerInterface::flush方法代码示例

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


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

示例1: encode

 /**
  * @param Url $url
  * @return Url|object
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  */
 public function encode(Url $url)
 {
     $this->em->beginTransaction();
     try {
         $urlRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\Url');
         $entity = $urlRepository->findOneBy(['url' => $url->getUrl()]);
         if ($entity) {
             /** @var Url $url */
             $url = $entity;
         } else {
             $url->setNew(true);
             $this->em->persist($url);
             $this->em->flush();
             $url->setCode($this->encoder->encode($url->getId()));
             $params = ['code' => $url->getCode()];
             if (!$url->isDefaultSequence()) {
                 $params['index'] = $url->getSequence();
             }
             $url->setShortUrl($this->router->generate(UrlShortenerBundle::URL_GO, $params, UrlGeneratorInterface::ABSOLUTE_URL));
             $this->em->persist($url);
             $this->em->flush();
         }
         $this->em->getConnection()->commit();
         return $url;
     } catch (\Exception $e) {
         $this->em->getConnection()->rollBack();
         throw $e;
     }
 }
开发者ID:RuslanZavacky,项目名称:url-shortener-api,代码行数:35,代码来源:Shortener.php

示例2: write

 /**
  * Writes the record down to the log of the implementing handler
  *
  * @param  array $record
  *
  * @return void
  */
 protected function write(array $record)
 {
     // Ensure the doctrine channel is ignored (unless its greater than a warning error), otherwise you will create an infinite loop, as doctrine like to log.. a lot..
     if ('doctrine' == $record['channel']) {
         if ((int) $record['level'] >= Logger::WARNING) {
             error_log($record['message']);
         }
         return;
     }
     // Only log errors greater than a warning
     //@todo - you could ideally add this into configuration variable
     if ((int) $record['level'] >= Logger::INFO && (string) $record['channel'] == 'backtrace') {
         try {
             // Create entity and fill with data
             $entity = new SystemLog();
             $entity->setChannel($record['channel'])->setLevel($record['level'])->setLog($record['message'])->setFormattedMsg($record['formatted'])->setCreatedAt(new \DateTime());
             $this->em->persist($entity);
             $this->em->flush();
         } catch (\Exception $e) {
             // Fallback to just writing to php error logs if something really bad happens
             error_log($record['message']);
             error_log($e->getMessage());
         }
     }
 }
开发者ID:alvarezpongo,项目名称:Kod3rLogBundle,代码行数:32,代码来源:DatabaseHandler.php

示例3: persist

 /**
  * Persists and flushes all provided models to the database storage.
  *
  * @param ...$models
  */
 protected function persist(...$models)
 {
     foreach ($models as $model) {
         $this->entityManager->persist($model);
     }
     $this->entityManager->flush();
 }
开发者ID:Zn4rK,项目名称:laravel-template,代码行数:12,代码来源:TestCase.php

示例4: setUp

 public function setUp()
 {
     $this->em = $this->prophesize(EntityManagerInterface::class);
     $this->em->persist(Argument::any())->willReturn(null);
     $this->em->flush()->willReturn(null);
     $this->service = new ShortUrlService($this->em->reveal());
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:7,代码来源:ShortUrlServiceTest.php

示例5: delete

 public function delete(BaseEntityInterface $entity)
 {
     $this->entityManager->remove($entity);
     if ($this->autoFlush) {
         $this->entityManager->flush();
     }
 }
开发者ID:phpcommerce,项目名称:phpcommerce,代码行数:7,代码来源:DoctrineBaseDao.php

示例6: 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

示例7: persist

 /**
  * Persists an entity via the EntityManager
  *
  * @param mixed $built A built entity
  */
 public function persist($built)
 {
     $this->entityManager->persist($built);
     if ($this->flushAfterPersist) {
         $this->entityManager->flush();
     }
 }
开发者ID:matthewpatterson,项目名称:carpenter,代码行数:12,代码来源:DoctrineAdapter.php

示例8: updateEntity

 /**
  * @param $configKey
  * @param $objectId
  * @param $value
  * @param null|string $dataField
  * @throws ContentEditableException
  */
 public function updateEntity($configKey, $objectId, $value, $dataField = null)
 {
     if (!array_key_exists($configKey, $this->configuration['configurations'])) {
         throw new ContentEditableException('Missing configuration "' . $configKey . '"');
     }
     $config = $this->configuration['configurations'][$configKey];
     if ($dataField == null) {
         if (!array_key_exists('data_field', $config)) {
             throw new ContentEditableException('Missing data_field');
         }
         $dataField = $config['data_field'];
     }
     $idField = 'id';
     if (array_key_exists('id_field', $config)) {
         $idField = $config['id_field'];
     }
     $repository = $this->entityManager->getRepository($config['repository_class']);
     $entity = $repository->findOneBy([$idField => $objectId]);
     $setter = 'set' . ucfirst($dataField);
     if (!method_exists($entity, $setter)) {
         throw new ContentEditableException('No setter "' . $setter . '" found for "' . get_class($entity) . '"');
     }
     $entity->{$setter}(trim($value));
     $this->entityManager->persist($entity);
     $this->entityManager->flush();
 }
开发者ID:janoist1,项目名称:ContentEditableBundle,代码行数:33,代码来源:ContentEditableService.php

示例9: saveAll

 /**
  * @param array|Student[] $students
  */
 public function saveAll(array $students)
 {
     foreach ($students as $student) {
         $this->em->persist($student);
     }
     $this->em->flush();
 }
开发者ID:Bebras-2015,项目名称:API,代码行数:10,代码来源:StudentSaver.php

示例10: saveList

 /**
  * @param MailingList $list
  */
 public function saveList(MailingList $list)
 {
     if (!$list->getId()) {
         $this->em->persist($list);
     }
     $this->em->flush($list);
 }
开发者ID:Opifer,项目名称:Cms,代码行数:10,代码来源:SubscriptionManager.php

示例11: createLink

 /**
  * @param $type
  * @param $id
  * @param $loader
  * @return Link
  */
 protected function createLink($type, $id, $loader)
 {
     $link = new Link($type, $id, $loader);
     $this->entityManager->persist($link);
     $this->entityManager->flush($link);
     return $link;
 }
开发者ID:vesax,项目名称:relation-bundle,代码行数:13,代码来源:Factory.php

示例12: __invoke

 public function __invoke()
 {
     if (null === ($renderer = $this->_renderer)) {
         return '';
     }
     if (null === ($page = $renderer->getCurrentPage())) {
         return '';
     }
     $metadata = $page->getMetadata();
     if (null === $metadata || $metadata->count() === 0) {
         //            @todo gvf
         $metadata = new MetaDataBag($this->metadataConfig, $page);
         $page->setMetaData($metadata);
         if ($this->entityManager->contains($page)) {
             $this->entityManager->flush($page);
         }
     }
     $result = '';
     foreach ($metadata as $meta) {
         if (0 < $meta->count() && 'title' !== $meta->getName()) {
             $result .= '<meta ';
             foreach ($meta as $attribute => $value) {
                 if (false !== strpos($meta->getName(), 'keyword') && 'content' === $attribute) {
                     $keywords = explode(',', $value);
                     foreach ($this->getKeywordObjects($keywords) as $object) {
                         $value = trim(str_replace($object->getUid(), $object->getKeyWord(), $value), ',');
                     }
                 }
                 $result .= $attribute . '="' . html_entity_decode($value, ENT_COMPAT, 'UTF-8') . '" ';
             }
             $result .= '/>' . PHP_EOL;
         }
     }
     return $result;
 }
开发者ID:ReissClothing,项目名称:BackBee,代码行数:35,代码来源:metadata.php

示例13: execute

 public function execute()
 {
     $criteria = new Criteria(['owner' => $this->user], null, null, null);
     $items = $this->basketRepository->findByCriteria($criteria);
     $order = $this->orderRepository->findActive();
     $connection = $this->entityManager->getConnection();
     $connection->beginTransaction();
     try {
         $orderItems = [];
         foreach ($items as $item) {
             /** @var Basket $item */
             $previousOrderItem = $this->orderItemRepository->findOneByCriteria(new Criteria(['owner' => $item->getOwner(), 'product' => $item->getProduct()]));
             if ($previousOrderItem) {
                 /** @var OrderItem $orderItem */
                 $orderItem = $previousOrderItem;
                 $orderItem->increaseQuantityBy($item->getQuantity());
             } else {
                 $orderItem = OrderItem::createFromBasket($item, $order);
             }
             $this->entityManager->persist($orderItem);
             $this->entityManager->remove($item);
             $orderItems[] = $orderItem;
         }
         $this->entityManager->flush();
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         return $e->getMessage();
     }
 }
开发者ID:drymek,项目名称:fcs-backend,代码行数:30,代码来源:BasketItemOrderAction.php

示例14: notify

 public function notify(UrlEvent $event)
 {
     if (!$this->isEnabled() || !$event->getUrl() || $event->getType() !== Shortener::NOTIFY_TYPE_REDIRECT) {
         return false;
     }
     $additional = $event->getAdditional();
     $ip = !empty($additional['ip']) ? $additional['ip'] : null;
     if (!$ip) {
         return false;
     }
     $urlRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\Url');
     $urlStatRepository = $this->em->getRepository('Rz\\Bundle\\UrlShortenerBundle\\Entity\\UrlStat');
     /** @var Url $url */
     $url = $urlRepository->find($event->getUrl()->getId());
     $url->incrementRedirectCount();
     $url->setLastRedirectOn(new \DateTime());
     $urlStat = $urlStatRepository->findOneBy(['Url' => $url, 'ip' => $ip]);
     if (!$urlStat) {
         $url->incrementUniqueRedirectCount();
         $urlStat = new UrlStat();
         $urlStat->setUrl($url);
         $urlStat->setCreated(new \DateTime());
         $urlStat->setIp($ip);
         if (!empty($additional['user-agent'])) {
             $urlStat->setUserAgent($additional['user-agent']);
         }
         $this->em->persist($urlStat);
     }
     $this->em->persist($url);
     $this->em->flush();
     return true;
 }
开发者ID:RuslanZavacky,项目名称:url-shortener-api,代码行数:32,代码来源:StatsListener.php

示例15: updateLastLogin

 /**
  * Update the users last login.
  *
  * @param UserInterface $user
  */
 protected function updateLastLogin($user)
 {
     if ($user instanceof BaseUser) {
         $user->setLastLogin(new \DateTime());
         $this->entityManager->flush();
     }
 }
开发者ID:sulu,项目名称:sulu,代码行数:12,代码来源:LastLoginListener.php


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