本文整理汇总了PHP中Doctrine\ORM\EntityManager::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::merge方法的具体用法?PHP EntityManager::merge怎么用?PHP EntityManager::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onIndexUpdate
/**
* The actual listener, will store the objects in the database
*
* @param IndexUpdateEvent $event
*/
public function onIndexUpdate(IndexUpdateEvent $event)
{
$objects = $event->getObjects();
foreach ($objects as $indexItem) {
$this->em->merge($indexItem);
}
$this->em->flush();
}
示例2: merge
/**
* @param string $id
* @param string|int|float $value
* @return void
*/
public function merge($id, $value)
{
$entity = $this->createEntity();
$entity->setId($id);
$entity->setContent(is_array($value) ? serialize($value) : $value);
$entity->setIsSerialized(is_array($value));
$this->em->merge($entity);
}
示例3: addWatcher
/**
* @param Ticket $ticket
* @param User $user
*/
public function addWatcher(Ticket $ticket, User $user)
{
$watcher = $this->watcherListRepository->findOne($ticket, $user);
if (!$watcher) {
$ticket = $this->em->merge($ticket);
$watcher = new WatcherList($ticket, $user);
$this->watcherListRepository->store($watcher);
}
}
示例4: getUser
/**
* Get the currently logged in user
*
* @throws AccessDeniedHttpException When no currently logged in user exists in the session
*
* @return User
*/
public function getUser()
{
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof User) {
$this->session->getFlashBag()->add(self::ERROR_TYPE, self::ERROR_MESSAGE);
throw new AccessDeniedHttpException(self::ERROR_MESSAGE);
}
return $this->entityManager->merge($user);
}
示例5: set
/**
* @param string $key
* @param mixed $value
*/
public function set($key, $value)
{
$config = $this->getConfig($key);
$object = new \stdClass();
$object->Value = $value;
$config->setValue($object);
$this->em->merge($config);
$this->em->flush();
}
示例6: update
/**
*
* @param Hanking $entity
* @return boolean|Hanking
*/
public function update(Hanking $entity)
{
try {
$this->manager->merge($entity);
$this->manager->flush();
return $entity;
} catch (Exception $ex) {
return false;
}
}
示例7: get
/**
* @return Comunidad|mixed|null|object
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
*/
public function get()
{
if ($this->comunidad instanceof Comunidad) {
return $this->comunidad;
}
if ($this->session->has('comunidad')) {
$comunidad = $this->session->get('comunidad');
$this->comunidad = $this->em->merge($comunidad);
return $this->comunidad;
}
return null;
}
示例8: detailAction
/**
* @Template
*
* @param Request $request
* @param Question $question
* @param string $answer
* @return array
*/
public function detailAction(Request $request, Question $question, $answer = null)
{
/** @var User $currentUser */
$currentUser = $this->entityManager->merge($this->loginUser->getUser());
if ($answer) {
$correct = $answer == $question->getCorrectAnswer();
$consumption = new QuestionAnswer($currentUser, $question, $correct);
$this->entityManager->persist($consumption);
$this->entityManager->flush();
return new RedirectResponse($this->urlGenerator->generate('home'));
}
return ['question' => $question];
}
示例9: consumptionAction
/**
* @Template
*
* @param Request $request
* @return array
*/
public function consumptionAction(Request $request)
{
/** @var User $currentUser */
$currentUser = $this->entityManager->merge($this->loginUser->getUser());
$users = $this->userRepository->findAllExceptUser($currentUser);
$receiverId = $request->query->get('receiver_id');
$receiver = $this->userRepository->findOneById($receiverId);
if ($receiver) {
$consumption = new Consumption($currentUser, $receiver);
$this->entityManager->persist($consumption);
$this->entityManager->flush();
return new RedirectResponse($this->urlGenerator->generate('question_detail', ['id' => $this->questionRepository->findOneRandom()->getId()]));
}
return ['users' => $users];
}
示例10: loadAndMergeEntity
/**
* @param \Scribe\Doctrine\ORM\Mapping\Entity|mixed $entity
* @param mixed $index
*
* @throws \Exception
*
* @return $this
*/
protected function loadAndMergeEntity($index, $entity)
{
try {
$entityMetadata = $this->getClassMetadata($this->getEntityFQCN());
$this->identLog[] = $identity = $entityMetadata->getIdentifierValues($entity);
if (count($identity) > 0) {
$identity = [key($identity) => current($identity)];
} elseif (!$entity->hasIdentity()) {
OutBuffer::stat('+y/b-preload +y/i-[warns]+w/- import could not begin for "%s:%d"', basename($this->metadata->getName()), $index);
OutBuffer::stat('+y/b-preload +y/i-[warns]+w/- import strategy "merge" unavailable due to failed identifier map resolution');
}
$repository = $this->manager->getRepository($this->getEntityFQCN());
$entitySearched = $repository->findOneBy($identity);
$this->manager->initializeObject($entitySearched);
if ($entitySearched && !$entity->isEqualTo($entitySearched)) {
$mapper = new HydratorManager(new HydratorMapping(true));
$entity = $mapper->getMappedObject($entity, $entitySearched);
$this->manager->remove($entitySearched);
$this->manager->merge($entity);
$this->manager->persist($entity);
$this->manager->flush();
$this->manager->clear();
++$this->countUpdate;
return $this;
} elseif ($entitySearched && $entity->isEqualTo($entitySearched)) {
$entity = $entitySearched;
++$this->countSkip;
return $this;
}
$this->loadAndPersistEntity($entity);
} catch (\Exception $e) {
throw $e;
}
return $this;
}
示例11: insertUpdateProcessing
public function insertUpdateProcessing(EntityManager $em, $data, $id = null)
{
$update = !is_null($id);
try {
$em->beginTransaction();
if ($update) {
$language = $em->find('Model\\Language', $id);
} else {
$language = new Language();
}
$language->setCode($data['code']);
$language->setDescription($data['description']);
$language->setFlagImageURL($data['flagimageurl']);
$menu = $em->find('Model\\Menu', $data['menuid']);
$language->setMenu($menu);
if ($update) {
$em->merge($language);
} else {
$em->persist($language);
}
$em->flush();
$em->commit();
} catch (\Exception $e) {
$em->rollback();
throw $e;
}
return $language->getId();
}
示例12: onAuthenticationSuccessResponse
/**
* Add unsigned parameters, such as:
* - databases (this list is also signed but presented here for listing to unauthenticated clients)
* - parameters, extra info you may attach to object as necessary
*
* @param AuthenticationSuccessEvent $event
*/
public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event)
{
$data = $event->getData();
$AuthUser = $event->getUser();
if (!$AuthUser instanceof AuthUser) {
throw new AccessDeniedException('AuthUser object not found');
}
if (!in_array('ROLE_USER', $AuthUser->getRoles())) {
throw new AccessDeniedException('User lacks necessary role');
}
$AuthUser->setLastToken($data['token']);
$AuthUser = $this->entityManager->merge($AuthUser);
$this->entityManager->persist($AuthUser);
$this->entityManager->flush();
$data['databases'] = $this->getDatabaseArray($event->getUser());
$data['parameters'] = $this->getParametersArray($event->getUser());
$event->setData($data);
}
示例13: merge
/**
* @param mixed $entity
* @param bool $flush
*/
public function merge($entity, $flush = null)
{
if ($entity !== null) {
$this->entityManager->merge($entity);
}
if ($flush) {
$this->entityManager->flush();
}
}
示例14: update
public function update(\Entity\Usuario $usuario)
{
try {
$this->em->merge($usuario);
$this->em->flush();
} catch (Exception $ex) {
$this->CI->log->write_log('error', $ex->getMessage() . ' - usuario_dao::update ');
}
}
示例15: merge
/**
* Efetua o merge do model atual com o banco de dados persistindo os dados editados.
*
* @param Model $model
*/
public function merge(Model $model)
{
try {
$this->manager->merge($model);
} catch (\Exception $e) {
Error::log($e);
return false;
}
return true;
}