本文整理汇总了PHP中Doctrine\ORM\EntityManagerInterface::refresh方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::refresh方法的具体用法?PHP EntityManagerInterface::refresh怎么用?PHP EntityManagerInterface::refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::refresh方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: refreshEntityField
/**
* @param $entity
* @param $field
* @return null|object
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
*/
protected function refreshEntityField($entity, $field)
{
$accessor = PropertyAccess::createPropertyAccessor();
if ($accessor->isReadable($entity, $field)) {
$field = $accessor->getValue($entity, $field);
if (empty($field) && $this->entityManager->contains($entity)) {
$this->entityManager->refresh($entity);
}
// if
}
// if
return $this;
}
示例2: refresh
/**
* Refresh an entity
*
* @param object $entity
* @return $this
*/
public function refresh($entity)
{
if ($this->supports($entity)) {
$this->entityManager->refresh($entity);
}
return $this;
}
示例3: postFormSubmit
public function postFormSubmit(FormSubmitEvent $event)
{
$post = $event->getPost();
$values = $post->getValueSet()->getValues();
$this->entityManager->refresh($post);
foreach ($values as $value) {
if ($value instanceof AttachmentValue) {
$media = $this->mediaManager->createMedia();
$media->setFile($value->getFile());
$media->setProvider('file');
$value->setAttachment($media);
}
}
$this->entityManager->persist($post);
$this->entityManager->flush();
}
示例4: leave
public function leave($id, UserInterface $user, $farewellMessage = 'Elvis has left the building.')
{
$channel = $this->find($id);
$repo = $this->em->getRepository('SiciarekChatBundle:ChatChannelAssignee');
$qb = $repo->createQueryBuilder('a')->leftJoin('a.channel', 'c')->andWhere('c.id = :channel')->andWhere('a.assigneeId = :id')->andWhere('a.assigneeClass = :class')->setParameters(['channel' => $id, 'id' => $user->getId(), 'class' => get_class($user)]);
$query = $qb->getQuery();
$assignee = $query->getSingleResult();
$channel->removeAssignee($assignee);
$this->em->remove($assignee);
$this->em->flush();
$this->em->refresh($channel);
if ($channel->getAssignees()->count() === 0) {
$this->em->remove($channel);
$this->em->flush();
}
$this->getContainer()->get('chat.message')->send($farewellMessage, $id);
return true;
}
示例5: content
/**
* @param string $name
* @param string $default
* @return string
*/
public function content($name, $default = 'no content')
{
/** @var Content $content */
$content = $this->entityManager->getRepository('Ist1ContentBundle:Content')->findOneBy(['name' => $name]);
if (!$content) {
$content = new Content($name, $default);
}
/** @var \Gedmo\Translatable\Entity\Repository\TranslationRepository $translationRepo */
$translationRepo = $this->entityManager->getRepository('Gedmo\\Translatable\\Entity\\Translation');
$translations = $translationRepo->findTranslations($content);
$locale = $this->requestStack->getCurrentRequest()->getLocale();
if (!array_key_exists($locale, $translations)) {
$content->setTranslatableLocale($locale);
$this->entityManager->persist($content);
$this->entityManager->flush();
}
$content->setTranslatableLocale($locale);
$this->entityManager->refresh($content);
return $content->getContent();
}
示例6: postFormSubmit
/**
* @param FormSubmitEvent $event
*/
public function postFormSubmit(FormSubmitEvent $event)
{
$post = $event->getPost();
$values = $post->getValueSet()->getValues();
$this->entityManager->refresh($post);
foreach ($values as $value) {
if ($value instanceof AttachmentValue) {
// Avoid saving the attachment when it's empty and not required
if (null === $value->getFile() && !$value->getAttribute()->getRequired()) {
continue;
}
$media = $this->mediaManager->createMedia();
$media->setFile($value->getFile());
$media->setProvider('file');
$value->setAttachment($media);
}
}
$this->entityManager->persist($post);
$this->entityManager->flush();
}
示例7: handleDetach
/**
* Detach given and create new keyword entity.
*
* @param CategoryInterface $category
* @param Keyword $keyword
*
* @return Keyword
*/
private function handleDetach(KeywordInterface $keyword, CategoryInterface $category)
{
$keywordString = $keyword->getKeyword();
$keywordLocale = $keyword->getLocale();
// if keyword wont be deleted (because of multiple references)
// refresh it to be sure hat changes wont be written to
// database.
$this->entityManager->refresh($keyword);
// delete old keyword from category
$this->delete($keyword, $category);
// create new keyword
$newEntity = $this->keywordRepository->createNew();
$newEntity->setKeyword($keywordString);
$newEntity->setLocale($keywordLocale);
// add new keyword to category
return $this->save($newEntity, $category);
}