本文整理汇总了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;
}
示例2: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->em = $this->getEntityManager();
$this->purgeDatabase();
$this->setUpTestData();
$this->em->flush();
$this->client = $this->createAuthenticatedClient();
}
示例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));
}
示例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!
}
示例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 ');
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
示例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>');
}
示例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();
}
示例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");
}
示例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();
}
示例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();
}
}