當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。