當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityManager::flush方法代碼示例

本文整理匯總了PHP中Kdyby\Doctrine\EntityManager::flush方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::flush方法的具體用法?PHP EntityManager::flush怎麽用?PHP EntityManager::flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Kdyby\Doctrine\EntityManager的用法示例。


在下文中一共展示了EntityManager::flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: save

 /**
  * @param array $values
  * @return Comment
  * @throws ActionFailedException
  */
 public function save(array $values)
 {
     $numberOfComments = $this->getNumberOfComments($values['page']);
     $repliesReferences = $this->findRepliesReferences($values['text']);
     try {
         $this->em->beginTransaction();
         // no replies references found
         if (empty($repliesReferences)) {
             $comment = new Comment($values['author'], $this->texy->process($values['text']), $values['page'], $numberOfComments + 1, $this->request->getRemoteAddress());
             $this->em->persist($comment)->flush();
             $this->em->commit();
             return $comment;
         }
         $commentsToReply = $this->findCommentsToReply($values['page'], $repliesReferences);
         $values['text'] = $this->replaceReplyReferencesByAuthors($values['text'], $commentsToReply);
         $comment = new Comment($values['author'], $this->texy->process($values['text']), $values['page'], $numberOfComments + 1);
         $this->em->persist($comment);
         /** @var Comment $comment */
         foreach ($commentsToReply as $commentToReply) {
             $commentToReply->addReaction($comment);
             $this->em->persist($commentToReply);
         }
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw new ActionFailedException();
     }
     return $comment;
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:36,代碼來源:CommentPersister.php

示例2: linkUrls

 /**
  * @param Url $oldUrl
  * @param Url $newUrl
  * @return void
  * @throws \Exception
  */
 public function linkUrls(Url $oldUrl, Url $newUrl)
 {
     if ($oldUrl->getId() === null or $newUrl->getId() === null) {
         throw new UrlNotPersistedException();
     }
     try {
         $this->em->beginTransaction();
         $alreadyRedirectedUrls = $this->findByActualUrl($oldUrl->getId());
         /** @var Url $url */
         foreach ($alreadyRedirectedUrls as $url) {
             $url->setRedirectTo($newUrl);
             $this->em->persist($url);
             $this->cache->clean([Cache::TAGS => [$url->getCacheKey()]]);
         }
         $oldUrl->setRedirectTo($newUrl);
         $this->em->persist($oldUrl);
         $this->cache->clean([Cache::TAGS => [$oldUrl->getCacheKey()]]);
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw $e;
     }
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:31,代碼來源:UrlLinker.php

示例3: sendMessage

 /**
  * @param SentMessage $message
  * @param array $recipients
  * @return ReceivedMessage[]
  * @throws \Exception
  */
 public function sendMessage(SentMessage $message, array $recipients)
 {
     $receivedMessages = [];
     try {
         $this->em->beginTransaction();
         $this->em->persist($message);
         foreach ($recipients as $recipient) {
             if (!$recipient instanceof User) {
                 throw new InvalidArgumentException('Argument $recipients can only contains instances of ' . User::class);
             }
             $m = $receivedMessages[$recipient->getId()] = new ReceivedMessage($message, $recipient);
             $this->em->persist($m);
             //if (count($receivedMessages) % 5 === 0) { // todo
             //    $this->em->flush();
             //    $this->em->clear();
             //}
         }
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         $this->onError('Message sending failed.', $e, self::class);
         throw $e;
     }
     return $receivedMessages;
 }
開發者ID:blitzik,項目名稱:vycetky-doctrine,代碼行數:33,代碼來源:MessagesWriter.php

示例4: switchEntities

 /**
  * @param $entity1
  * @param $entity2
  */
 private function switchEntities($entity1, $entity2)
 {
     $x = $entity1->priority;
     $entity1->priority = $entity2->priority;
     $entity2->priority = $x;
     $this->entityManager->persist($entity1, $entity2);
     $this->entityManager->flush();
 }
開發者ID:Kotys,項目名稱:eventor.io,代碼行數:12,代碼來源:Sorter.php

示例5: addGenre

 public function addGenre(string $name)
 {
     if ($this->genreExists($name)) {
         return;
     }
     $genre = new Genre($name);
     $this->entityManager->persist($genre);
     $this->entityManager->flush($genre);
 }
開發者ID:ParalelniPolis,項目名稱:bitcoinJukebox,代碼行數:9,代碼來源:GenresManager.php

示例6: logDb

 private function logDb($message, $status = NULL, $consumerTitle = NULL)
 {
     $log = new RmqLogConsumer();
     $log->consumerTitle = $consumerTitle;
     $log->message = $message;
     $log->status = $status;
     $this->em->persist($log);
     $this->em->flush();
 }
開發者ID:miloshavlicek,項目名稱:rabbit-mq-consumer,代碼行數:9,代碼來源:Log.php

示例7: delete

 /**
  * @param $albumId
  */
 public function delete($albumId)
 {
     /**
      * @var Album $album
      */
     $album = $this->albumDao->find($albumId);
     $album->delete();
     $this->em->persist($album);
     $this->em->flush();
 }
開發者ID:peterkrejci,項目名稱:music-collection,代碼行數:13,代碼來源:AlbumModel.php

示例8: saveSearch

 /**
  * @param string $searchString
  * @return Search
  */
 public function saveSearch($searchString)
 {
     if ($search = $this->search(Strings::webalize($searchString))) {
         return $search;
     }
     $search = new Search($searchString);
     $this->entityManager->persist($search);
     $this->entityManager->flush($search);
     return $search;
 }
開發者ID:stekycz,項目名稱:dwarf-search,代碼行數:14,代碼來源:SearchManager.php

示例9: update

 public function update($entityClass, array $items)
 {
     $position = 1;
     foreach ($items as $id) {
         $entity = $this->em->find($entityClass, $id);
         $entity->setPosition($position * 10);
         $this->em->persist($entity);
         $position++;
     }
     $this->em->flush();
 }
開發者ID:lexinek,項目名稱:doctrine-behaviors,代碼行數:11,代碼來源:Organiser.php

示例10: saveEntity

 /**
  * Save entity into DB
  *
  * @param BaseEntity $baseEntity
  * @return BaseEntity
  * @throws \Exception
  */
 protected function saveEntity(BaseEntity $baseEntity)
 {
     $isPersisted = UnitOfWork::STATE_MANAGED === $this->entityManager->getUnitOfWork()->getEntityState($baseEntity);
     if ($isPersisted) {
         $this->entityManager->merge($baseEntity);
     } else {
         $this->entityManager->persist($baseEntity);
     }
     $this->entityManager->flush();
     return $baseEntity;
 }
開發者ID:pecinaon,項目名稱:sandbox,代碼行數:18,代碼來源:BaseFacade.php

示例11: deleteTag

 /**
  * Odstraneni konkretniho tagu
  * @param \App\Model\Entities\Tag $tag
  * @return boolean
  */
 public function deleteTag(Entities\Tag $tag)
 {
     try {
         $this->em->remove($tag);
         $result = $this->em->flush();
     } catch (\Doctrine\ORM\ORMException $e) {
         Debugger::log($e, Debugger::INFO);
         $result = FALSE;
     }
     return $result;
 }
開發者ID:krupaj,項目名稱:my-blog,代碼行數:16,代碼來源:TagRepository.php

示例12: delete

 /**
  * @param Entity\Event $event
  */
 public function delete(Entity\Event $event)
 {
     foreach ($event->performances as $performance) {
         foreach ($performance->children as $child) {
             $this->em->remove($child);
         }
         $this->em->remove($performance);
     }
     $this->em->remove($event);
     $this->em->flush();
 }
開發者ID:Kotys,項目名稱:eventor.io,代碼行數:14,代碼來源:Event.php

示例13: remove

 /**
  * @param Role $role
  * @throws ForeignKeyConstraintViolationException
  */
 public function remove(Role $role)
 {
     try {
         $roleID = $role->getId();
         $this->em->remove($role);
         $this->em->flush();
         $this->onSuccessRoleRemoval($role, $roleID);
     } catch (ForeignKeyConstraintViolationException $e) {
         throw $e;
     }
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:15,代碼來源:RoleRemover.php

示例14: removeFile

 /**
  * @param FileEntityInterface $entity
  */
 public function removeFile(FileEntityInterface $entity)
 {
     --$entity->joints;
     if ($entity->joints === 0) {
         $this->em->remove($entity);
         $this->em->flush();
         $this->unlinkFile($this->uploadDir . '/' . $entity->year . '/' . $entity->month . '/' . $entity->name . '.' . $entity->extension);
     } else {
         $this->em->persist($entity);
         $this->em->flush();
     }
 }
開發者ID:CSHH,項目名稱:website,代碼行數:15,代碼來源:FileManager.php

示例15: orderGenre

 public function orderGenre(string $genreId, float $price, Address $address)
 {
     $songEntities = [];
     //genre order is order of random song from given genre and setting of given genre as genre to be played when queue is empty
     //current genre is saved as genreId in file, because it is simple and fast
     $genre = $this->genresManager->getGenre($genreId);
     $order = new Order($price, $address, $genre);
     $this->entityManager->persist($order);
     $songEntities[] = $order;
     $song = $this->songsManager->getRandomSong($genre);
     $songEntities[] = $this->orderSong($song, $order);
     $this->entityManager->flush($songEntities);
 }
開發者ID:ParalelniPolis,項目名稱:bitcoinJukebox,代碼行數:13,代碼來源:QueueManager.php


注:本文中的Kdyby\Doctrine\EntityManager::flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。