本文整理汇总了PHP中EntityManager::persist方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::persist方法的具体用法?PHP EntityManager::persist怎么用?PHP EntityManager::persist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::persist方法的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: 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));
}
示例3: 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 ');
}
}
示例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: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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();
}
}
示例9: 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>');
}
示例10: 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");
}
示例11: 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();
}
示例12: save
/**
* @param BlockInterface $block
*
* @return BlockManager
*/
public function save(BlockInterface $block)
{
$block->setRootVersion($this->getNewVersion($block));
$this->em->persist($block);
$this->em->flush($block);
return $this;
}
示例13: saveThread
/**
* Saves a thread
*
* @param ThreadInterface $thread
* @param Boolean $andFlush Whether to flush the changes (default true)
*/
public function saveThread(ThreadInterface $thread, $andFlush = true)
{
$this->denormalize($thread);
$this->em->persist($thread);
if ($andFlush) {
$this->em->flush();
}
}
示例14: 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();
}
}
示例15: testActivityUniqueness
/**
* Make sure activities cannot have the same activityId per spec
*/
public function testActivityUniqueness()
{
$activity = $this->activityService->denormalize(json_encode($this->getActivityData()));
$this->em->persist($activity);
$this->em->flush();
$newActivity = clone $activity;
$constraintViolationList = $this->validator->validate($newActivity);
$this->assertEquals($constraintViolationList->count(), 1);
$this->assertEquals($constraintViolationList->get(0)->getInvalidValue(), $activity->getActivityId());
}