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


PHP EntityManager::flush方法代码示例

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


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

示例1: getOrCreateUser

 /**
  * {@inheritDoc}
  */
 public function getOrCreateUser($email, $googleId)
 {
     if ($this->isConfiguredDomain($email)) {
         $user = $this->userFinder->findUserByGoogleSignInData($email, $googleId);
         if (!$user instanceof $this->userClass) {
             //User not present in database, create new one
             $user = new $this->userClass();
             $user->setUsername($email);
             $user->setEmail($email);
             $user->setPlainPassword($googleId . $email . time());
             $user->setEnabled(true);
             $user->setLocked(false);
             $user->setAdminLocale('en');
             $user->setPasswordChanged(true);
         }
         foreach ($this->getAccessLevels($email) as $accessLevel) {
             $user->addRole($accessLevel);
         }
         $user->setGoogleId($googleId);
         // Persist
         $this->em->persist($user);
         $this->em->flush();
     }
     return isset($user) ? $user : null;
 }
开发者ID:bakie,项目名称:KunstmaanBundlesCMS,代码行数:28,代码来源:OAuthUserCreator.php

示例2: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->em = $this->getEntityManager();
     $this->purgeDatabase();
     $this->setUpTestData();
     $this->em->flush();
     $this->client = $this->createAuthenticatedClient();
 }
开发者ID:sulu,项目名称:SuluPricingBundle,代码行数:11,代码来源:PricingControllerTest.php

示例3: testReverseTransform

 public function testReverseTransform()
 {
     $transformer = $this->createTransformer();
     $tag = new Tag("name");
     $this->em->persist($tag);
     $this->em->flush();
     $this->assertSame($tag, $transformer->reverseTransform(1, null));
 }
开发者ID:notbrain,项目名称:symfony,代码行数:8,代码来源:EntityToIDTransformerTest.php

示例4: persist

 protected function persist(array $entities)
 {
     foreach ($entities as $entity) {
         $this->em->persist($entity);
     }
     $this->em->flush();
     // no clear, because entities managed by the choice field must
     // be managed!
 }
开发者ID:rooster,项目名称:symfony,代码行数:9,代码来源:EntityChoiceFieldTest.php

示例5: insert

 public function insert(Entity\AvaliadorArea $avaliadorArea)
 {
     try {
         $this->em->persist($avaliadorArea);
         $this->em->flush();
     } catch (Exception $ex) {
         $this->CI->log->write_log('error', $ex->getMessage() . ' - avaliador_area_dao::insert ');
     }
 }
开发者ID:jeanlopes,项目名称:mostra-ifrs-poa,代码行数:9,代码来源:avaliador_area_dao.php

示例6: save

 /**
  * Save schema
  *
  * @param SchemaInterface $schema
  *
  * @return SchemaInterface
  */
 public function save(SchemaInterface $schema)
 {
     foreach ($schema->getAttributes() as $attribute) {
         $attribute->setSchema($schema);
         $this->em->persist($attribute);
     }
     $this->em->persist($schema);
     $this->em->flush();
     return $schema;
 }
开发者ID:leonverschuren,项目名称:Cms,代码行数:17,代码来源:SchemaManager.php

示例7: save

 /**
  * Save template
  *
  * @param TemplateInterface $template
  *
  * @return TemplateInterface
  */
 public function save(TemplateInterface $template)
 {
     foreach ($template->getAttributes() as $attribute) {
         $attribute->setTemplate($template);
         $this->em->persist($attribute);
     }
     $this->em->persist($template);
     $this->em->flush();
     return $template;
 }
开发者ID:NickyBeunder,项目名称:EavBundle,代码行数:17,代码来源:TemplateManager.php

示例8: createTagCollection

 public function createTagCollection()
 {
     $tags = new ArrayCollection();
     $tags->add(new Tag("foo"));
     $tags->add(new Tag("bar"));
     foreach ($tags as $tag) {
         $this->em->persist($tag);
     }
     $this->em->flush();
     $this->em->clear();
     return $tags;
 }
开发者ID:notbrain,项目名称:symfony,代码行数:12,代码来源:CollectionToChoiceTransformerTest.php

示例9: onKernelRequest

 /**
  * Method actually invoked upon dispatching an event "kernel.response"
  *
  * @param FilterResponseEvent $event
  *
  * @return void
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $token = $this->securityContext->getToken();
     if ($token instanceof UsernamePasswordToken and $token->isAuthenticated()) {
         $user = $token->getUser();
         $user->setLastActive(new \DateTime(date('Y-m-d H:i:s', time())));
         $this->entityManager->persist($user);
         $this->entityManager->flush();
     }
 }
开发者ID:thebuggl-org,项目名称:tests-buggl,代码行数:20,代码来源:LastActiveFilterListener.php

示例10: updateFreeSearchField

 /**
  * method invoked everytime an event is dispatched(guide updates)
  * @param  EguideEvent $event
  */
 public function updateFreeSearchField(EguideEvent $event)
 {
     $eguide = $event->getEguide();
     $keywords = array();
     /**
      * needs improvement
      * @var string
      */
     $categories = $eguide->getCategories();
     foreach ($categories as $category) {
         $categoryName = strtolower($category->getName());
         $keywords[] = 'activity:' . $categoryName;
     }
     $country = strtolower($eguide->getCountry()->getName());
     $locations = $eguide->getLocations();
     foreach ($locations as $location) {
         $address = 'location:' . $location->getAddress();
         $keywords[] = $address;
     }
     $keywords[] = $country;
     $keywords = implode(" ", $keywords);
     $eguide->setFreeSearch($keywords);
     $this->entityManager->persist($eguide);
     $this->entityManager->flush();
 }
开发者ID:thebuggl-org,项目名称:tests-buggl,代码行数:29,代码来源:FreeSearchEventListener.php

示例11: migrateData

 /**
  * Migrate data to plugin database from core table
  *
  * @param EntityManager   $em
  * @param OutputInterface $output
  *
  * @return void
  */
 public function migrateData($em, $output)
 {
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('Newscoop\\CommunityTickerBundle\\Entity\\CommunityTickerEvent', 'e');
     $rsm->addFieldResult('e', 'id', 'id');
     $rsm->addFieldResult('e', 'event', 'event');
     $rsm->addFieldResult('e', 'params', 'params');
     $rsm->addFieldResult('e', 'created', 'created');
     $rsm->addJoinedEntityResult('Newscoop\\Entity\\User', 'u', 'e', 'user');
     $rsm->addFieldResult('u', 'Id', 'id');
     $query = $em->createNativeQuery('SELECT e.id, e.event, e.params, e.created, u.Id FROM community_ticker_event e ' . 'LEFT JOIN liveuser_users u ON u.id = e.user_id', $rsm);
     $events = $query->getArrayResult();
     foreach ($events as $key => $event) {
         $user = $em->getRepository('Newscoop\\Entity\\User')->findOneBy(array('id' => $event['user']['id']));
         $existingEvent = $em->getRepository('Newscoop\\CommunityTickerBundle\\Entity\\CommunityTickerEvent')->findOneBy(array('created' => $event['created'], 'params' => $event['params']));
         if (!$existingEvent) {
             $newEvent = new CommunityTickerEvent();
             $newEvent->setEvent($event['event']);
             $newEvent->setParams($event['params'] != '[]' ? json_decode($event['params'], true) : array());
             $newEvent->setCreated($event['created']);
             $newEvent->setIsActive(true);
             if ($user) {
                 $newEvent->setUser($user);
             }
             $em->persist($newEvent);
         }
     }
     $em->flush();
     $output->writeln('<info>Data migrated to plugin table!</info>');
     $output->writeln('<info>Removing old table...</info>');
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:39,代码来源:MigrateTablesCommand.php

示例12: duplicate

 /**
  * Duplicate a content item
  *
  * @param ContentInterface $content
  * @param NestedValue $nestedIn
  */
 public function duplicate(ContentInterface $content, NestedValue $nestedIn = null)
 {
     //get valueset to clone
     $valueset = $content->getValueSet();
     //clone valueset
     $duplicatedValueset = clone $valueset;
     $this->detachAndPersist($duplicatedValueset);
     //duplicate content
     $duplicatedContent = clone $content;
     $duplicatedContent->setSlug(null);
     $duplicatedContent->setValueSet($duplicatedValueset);
     if (!is_null($nestedIn)) {
         $duplicatedContent->setNestedIn($nestedIn);
     }
     $this->detachAndPersist($duplicatedContent);
     //iterate values, clone each and assign duplicate valueset to it
     foreach ($valueset->getValues() as $value) {
         //skip empty attributes
         if (is_null($value->getId())) {
             continue;
         }
         $duplicatedValue = clone $value;
         $duplicatedValue->setValueSet($duplicatedValueset);
         $this->detachAndPersist($duplicatedValue);
         //if type nested, find content that has nested_in value same as id of value
         if ($value instanceof \Opifer\EavBundle\Entity\NestedValue) {
             $nestedContents = $this->getRepository()->findby(['nestedIn' => $value->getId()]);
             foreach ($nestedContents as $nestedContent) {
                 $this->duplicate($nestedContent, $duplicatedValue);
             }
         }
     }
     $this->em->flush();
     return $duplicatedContent->getId();
 }
开发者ID:NickyBeunder,项目名称:ContentBundle,代码行数:41,代码来源:ContentManager.php

示例13: testPaginator

 public function testPaginator()
 {
     $reader = $this->getAuditReader();
     $query = $reader->paginateRevisionsQuery();
     $paginatorAdapter = new \ZF2EntityAudit\Paginator\DbalAdapter($query);
     $paginator = new \Zend\Paginator\Paginator($paginatorAdapter);
     for ($i = 0; $i < 20; $i++) {
         $writer = new Writer("tawfek" . rand());
         $article = new Article("title", "text", $writer);
         $this->em->persist($writer);
         $this->em->persist($article);
     }
     $this->em->flush();
     $this->assertEquals($reader->countRevisions(), "1");
     $this->assertEquals($paginator->count(), "1");
     for ($i = 0; $i < 20; $i++) {
         $writer = new Writer("tawfek" . rand());
         $article = new Article("title", "text", $writer);
         $this->em->persist($writer);
         $this->em->persist($article);
         $this->em->flush();
     }
     // its 21 because (20 flushes + 1 flush as bluk flush in line 330 )
     $this->assertEquals($reader->countRevisions(), "21");
     $this->assertEquals($paginator->getAdapter()->count(), "21");
     $this->assertEquals(count($paginator->getAdapter()->getItems(1, 12)), "12");
 }
开发者ID:tawfekov,项目名称:zf2entityaudit,代码行数:27,代码来源:AuditTest.php

示例14: setUp

 public function setUp()
 {
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setProxyDir(__DIR__ . '/_files');
     $config->setProxyNamespace('DoctrineExtensions\\LargeCollections\\Proxies');
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     #$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $this->em = \Doctrine\ORM\EntityManager::create($conn, $config);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->createSchema(array($this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Article'), $this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Tag'), $this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Comment')));
     $article = new Article();
     $tag1 = new Tag();
     $tag2 = new Tag();
     $comment1 = new Comment();
     $comment2 = new Comment();
     $article->addComment($comment1);
     $article->addComment($comment2);
     $article->addTag($tag1);
     $article->addTag($tag2);
     $this->em->persist($article);
     $this->em->persist($tag1);
     $this->em->persist($tag2);
     $this->em->persist($comment1);
     $this->em->persist($comment2);
     $this->em->flush();
     $this->articleId = $article->id();
     $this->em->clear();
 }
开发者ID:Credit-Jeeves,项目名称:DoctrineExtensions,代码行数:31,代码来源:LargeCollectionTest.php

示例15: saveMessage

 /**
  * Saves a message
  *
  * @param MessageInterface $message
  * @param Boolean $andFlush Whether to flush the changes (default true)
  */
 public function saveMessage(MessageInterface $message, $andFlush = true)
 {
     $this->denormalize($message);
     $this->em->persist($message);
     if ($andFlush) {
         $this->em->flush();
     }
 }
开发者ID:sketchmedia,项目名称:FOSMessageBundle,代码行数:14,代码来源:MessageManager.php


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