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


PHP EntityManager::flush方法代碼示例

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


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

示例1: run

 /**
  * @param Todo $entity
  */
 public function run(EntityInterface $entity)
 {
     assert($entity instanceof Todo);
     $entity->setStatus(new TodoStatus());
     $this->repository->add($entity);
     $this->entityManager->flush();
 }
開發者ID:polidog,項目名稱:symfony_sample_todo,代碼行數:10,代碼來源:AddTodo.php

示例2: down

 public function down(Schema $schema)
 {
     $lookingFor = new Profile\LookingFor();
     $lookingFor->setName('Intimate');
     $this->em->persist($lookingFor);
     $this->em->flush();
 }
開發者ID:Joomlamaster,項目名稱:connectionru,代碼行數:7,代碼來源:Version20141209154201.php

示例3: onCoreController

 /**
  * Update the user "lastActivity" on each request
  *
  * @param FilterControllerEvent $event
  */
 public function onCoreController(FilterControllerEvent $event)
 {
     // Here we are checking that the current request is a "MASTER_REQUEST",
     // and ignore any
     // subrequest in the process (for example when
     // doing a render() in a twig template)
     if ($event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
         return;
     }
     // We are checking a token authentification is available before using
     // the User
     if ($this->securityContext->getToken()) {
         $user = $this->securityContext->getToken()->getUser();
         // We are using a delay during wich the user will be considered as
         // still active, in order to
         // avoid too much UPDATE in the
         // database
         // $delay = new \DateTime ();
         // $delay->setTimestamp (strtotime ('2 minutes ago'));
         // We are checking the Admin class in order to be certain we can
         // call "getLastActivity".
         // && $user->getLastActivity() < $delay) {
         if ($user instanceof User) {
             $user->isActiveNow();
             $this->em->persist($user);
             $this->em->flush();
         }
     }
 }
開發者ID:sasedev,項目名稱:alluco,代碼行數:34,代碼來源:Activity.php

示例4: onKernelTerminate

 /**
  * Flush on kernel terminate.
  */
 public function onKernelTerminate()
 {
     if ($this->em->isOpen()) {
         $this->em->flush();
         // That was not so hard... And you need a bundle to do that! Poor guy...
     }
 }
開發者ID:alcalyn,項目名稱:flush-on-kernel-terminate-bundle,代碼行數:10,代碼來源:KernelTerminateListener.php

示例5: save

 /**
  * @param ProviderLocation $providerLocation
  * @param bool             $withFlush
  */
 public function save(ProviderLocation $providerLocation, $withFlush = true)
 {
     $this->entityManager->persist($providerLocation);
     if ($withFlush) {
         $this->entityManager->flush();
     }
 }
開發者ID:Appartin,項目名稱:CoreBundle,代碼行數:11,代碼來源:ProviderLocationManager.php

示例6: schedule

 public function schedule()
 {
     $licenseRepo = $this->em->getRepository('AppBundle:License');
     $drillSchemaEventsRepo = $this->em->getRepository('AppBundle:DrillSchemaEvent');
     $licensesWithoutSchema = $licenseRepo->findWithoutRegisteredSchema();
     foreach ($licensesWithoutSchema as $license) {
         $drillSchemaEvents = $drillSchemaEventsRepo->findByAddonKey($license->getAddonKey());
         if (empty($drillSchemaEvents)) {
             continue;
         }
         $drillRegisteredSchema = new DrillRegisteredSchema();
         $drillRegisteredSchema->setLicenseId($license->getLicenseId());
         $drillRegisteredSchema->setAddonKey($license->getAddonKey());
         $this->em->persist($drillRegisteredSchema);
         foreach ($drillSchemaEvents as $drillSchemaEvent) {
             $sendDate = $this->calculateSendDate($drillSchemaEvent, $license);
             $today = new \DateTime();
             // prevent creating events from past
             if ($sendDate < $today->modify('-2 days')) {
                 continue;
             }
             $drillRegisteredEvent = new DrillRegisteredEvent();
             $drillRegisteredEvent->setDrillRegisteredSchema($drillRegisteredSchema);
             $drillRegisteredEvent->setDrillSchemaEvent($drillSchemaEvent);
             // Calculate
             $drillRegisteredEvent->setSendDate($sendDate);
             $drillRegisteredEvent->setStatus('new');
             $this->em->persist($drillRegisteredEvent);
         }
     }
     $this->em->flush();
 }
開發者ID:rachetfoot,項目名稱:atlassian-vendor-tools,代碼行數:32,代碼來源:Scheduler.php

示例7: onKernelTerminate

 public function onKernelTerminate(PostResponseEvent $event)
 {
     /** @var Request $request */
     $request = $event->getRequest();
     if (!$this->isEnable || !$this->isLoggableRequest($request)) {
         return;
     }
     try {
         /** @var Response $response */
         $response = $event->getResponse();
         $route = $request->get('_route');
         $content = $this->cleanSensitiveContent($route, $request->getContent());
         $token = $this->tokenStorage->getToken();
         $user = !is_null($token) ? $token->getUser() : null;
         $logRequest = new LogRequest();
         $logRequest->setRoute($route)->setPath($request->getPathInfo())->setMethod($request->getMethod())->setQuery(urldecode($request->getQueryString()))->setContent($content)->setStatus($response->getStatusCode())->setIp($request->getClientIp())->setUser(!is_string($user) ? $user : null);
         if ($this->logResponse($response)) {
             $logRequest->setResponse($response->getContent());
         }
         $this->em->persist($logRequest);
         $this->em->flush();
     } catch (\Exception $e) {
         $this->logger->error(sprintf("LogRequest couldn't be persist : %s", $e->getMessage()));
     }
 }
開發者ID:Eraac,項目名稱:rest-project,代碼行數:25,代碼來源:LogRequestListener.php

示例8: get

 public function get($name)
 {
     $uppername = strtoupper($name);
     /*
             //create unique key for kind and uppercased name
             $key = md5('kind.' . $uppername);
             //cache has value return this one
             $cached = Cache::get($key);
             if ($cached) {
                 return $cached;
             }*/
     //find or create in store
     $kind = $this->em->getRepository($this->class)->findOneBy(['name' => $uppername]);
     if (!$kind) {
         $kind = new Kind(new Name($uppername));
         $this->em->persist($kind);
         $this->em->flush();
     }
     /*
             //cache it for next request
             Cache::forever($key, $kind);
             return Cache::get($key);
     */
     return $kind;
 }
開發者ID:bakgat,項目名稱:notos,代碼行數:25,代碼來源:KindCacheRepository.php

示例9: onResponse

 /**
  * Process onReslonse event, updates user history information
  *
  * @param  FilterResponseEvent $event
  * @return bool|void
  */
 public function onResponse(FilterResponseEvent $event)
 {
     if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
         // Do not do anything
         return;
     }
     $request = $event->getRequest();
     $response = $event->getResponse();
     // do not process requests other than in html format
     // with 200 OK status using GET method and not _internal and _wdt
     if (!$this->matchRequest($response, $request)) {
         return false;
     }
     $postArray = ['url' => $request->getRequestUri(), 'user' => $this->user];
     /** @var $historyItem  NavigationHistoryItem */
     $historyItem = $this->em->getRepository('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationHistoryItem')->findOneBy($postArray);
     if (!$historyItem) {
         /** @var $historyItem \Oro\Bundle\NavigationBundle\Entity\NavigationItemInterface */
         $historyItem = $this->navItemFactory->createItem(NavigationHistoryItem::NAVIGATION_HISTORY_ITEM_TYPE, $postArray);
     }
     $historyItem->setTitle($this->titleService->getSerialized());
     // force update
     $historyItem->doUpdate();
     $this->em->persist($historyItem);
     $this->em->flush($historyItem);
     return true;
 }
開發者ID:abdeldayem,項目名稱:pim-community-dev,代碼行數:33,代碼來源:ResponseHistoryListener.php

示例10: testRemovePage

 public function testRemovePage()
 {
     $page = new Page();
     $page->setTitle('Test')->setContent('<p>test</p>')->setCurrentSlugUrl('/remove');
     $this->entityManager->persist($page);
     $childPage1 = new Page();
     $childPage1->setTitle('Test child Page 1')->setContent('<p>test child page</p>')->setCurrentSlugUrl('/child1');
     $this->entityManager->persist($childPage1);
     $childPage2 = new Page();
     $childPage2->setTitle('Test child Page 2')->setContent('<p>test child page</p>')->setCurrentSlugUrl('/child2');
     $this->entityManager->persist($childPage2);
     $page->addChildPage($childPage1);
     $page->addChildPage($childPage2);
     $this->entityManager->flush($page);
     $pageSlugId = $page->getCurrentSlug()->getId();
     $childPage1SlugId = $childPage1->getCurrentSlug()->getId();
     $childPage2SlugId = $childPage2->getCurrentSlug()->getId();
     $this->entityManager->remove($page);
     $this->entityManager->flush();
     // make sure data updated correctly
     $this->entityManager->clear();
     $this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $pageSlugId));
     $this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $childPage1SlugId));
     $this->assertNull($this->entityManager->find('OroB2BRedirectBundle:Slug', $childPage2SlugId));
 }
開發者ID:hafeez3000,項目名稱:orocommerce,代碼行數:25,代碼來源:PageSlugListenerTest.php

示例11: finishBatch

 /**
  * Finish processed batch
  */
 protected function finishBatch()
 {
     $this->entityManager->flush();
     if ($this->entityManager->getConnection()->getTransactionNestingLevel() == 1) {
         $this->entityManager->clear();
     }
 }
開發者ID:ramunasd,項目名稱:platform,代碼行數:10,代碼來源:DeleteMassActionHandler.php

示例12: duplicate

 /**
  * Duplicate Jam entities
  *
  * For details see
  * {@link http://stackoverflow.com/questions/9071094/how-to-re-save-the-entity-as-another-row-in-doctrine-2}
  *
  * @param Jam $entity
  * @param integer $count
  */
 public function duplicate(Jam $entity, $count = 0)
 {
     for ($i = 0; $i < $count; $i++) {
         $this->em->persist($this->cloneService->cloneObject($entity));
     }
     $this->em->flush();
 }
開發者ID:e-moe,項目名稱:sonata,代碼行數:16,代碼來源:JamService.php

示例13: formSucceeded

 /**
  * Callback method, that is called once form is successfully submitted, without validation errors.
  *
  * @param Form $form
  * @param Nette\Utils\ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if (!($user = $this->userRepository->findOneBy(['email' => $values->email]))) {
         $form['email']->addError("User with given email doesn't exist");
         return;
     }
     // this is not a very secure way of getting new password
     // but it's the same way the symfony app is doing it...
     $newPassword = $user->generateRandomPassword();
     $this->em->flush();
     try {
         $message = new Nette\Mail\Message();
         $message->setSubject('Notejam password');
         $message->setFrom('noreply@notejamapp.com');
         $message->addTo($user->getEmail());
         // !!! Never send passwords through email !!!
         // This is only for demonstration purposes of Notejam.
         // Ideally, you can create a unique link where user can change his password
         // himself for limited amount of time, and then send the link.
         $message->setBody("Your new password is {$newPassword}");
         $this->mailer->send($message);
     } catch (Nette\Mail\SendException $e) {
         Debugger::log($e, 'email');
         $form->addError('Could not send email with new password');
     }
     $this->onSuccess($this);
 }
開發者ID:martinmayer,項目名稱:notejam,代碼行數:33,代碼來源:ForgottenPasswordControl.php

示例14: publish

 /**
  * Publishes a gif and posts a link on social networks
  * @param Gif $gif
  * @return bool
  */
 public function publish(Gif $gif)
 {
     if (!$gif) {
         return false;
     }
     if (!$gif->getGifStatus() == GifState::ACCEPTED) {
         return false;
     }
     $gif->setPublishDate(new DateTime());
     $gif->setGifStatus(GifState::PUBLISHED);
     $gif->generateUrlReadyPermalink();
     // Check if permalink is unique
     /** @var GifRepository $gifsRepo */
     $gifsRepo = $this->em->getRepository('LjdsBundle:Gif');
     $permalink = $gif->getPermalink();
     $i = 1;
     while (!empty($gifsRepo->findBy(['permalink' => $gif->getPermalink(), 'gifStatus' => GifState::PUBLISHED]))) {
         // Generate a new permalink
         $gif->setPermalink($permalink . $i);
         $i++;
     }
     $this->em->flush();
     if ($this->facebookAutopost) {
         $this->facebookService->postGif($gif);
     }
     if ($this->twitterAutopost) {
         $this->twitterService->postGif($gif);
     }
     return true;
 }
開發者ID:MrMitch,項目名稱:Les-Joies-de-Supinfo,代碼行數:35,代碼來源:GifService.php

示例15: makeDrawForNextRound

 /**
  * @param Tournament $tournament
  * @return void
  */
 public function makeDrawForNextRound(Tournament $tournament)
 {
     $nextRound = $tournament->getCurrentRound() + 1;
     $this->makeDraw($tournament, $nextRound);
     $tournament->setCurrentRound($nextRound);
     $this->manager->flush($tournament);
 }
開發者ID:StasPiv,項目名稱:playzone,代碼行數:11,代碼來源:SwissService.php


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