當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityManager::transactional方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\EntityManager::transactional方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::transactional方法的具體用法?PHP EntityManager::transactional怎麽用?PHP EntityManager::transactional使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\EntityManager的用法示例。


在下文中一共展示了EntityManager::transactional方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: apply

 /**
  * @param float $discount
  */
 public function apply($discount)
 {
     $this->entityManager->transactional(function () use($discount) {
         foreach ($this->items->findAll() as $item) {
             $item->applyDiscount($discount);
         }
     });
     $this->entityManager->clear();
 }
開發者ID:lzakrzewski,項目名稱:tests-with-database-examples,代碼行數:12,代碼來源:ApplyDiscountUseCase.php

示例2: deleteByKey

 public function deleteByKey($id)
 {
     $repo = $this->repository;
     $this->em->transactional(function (EntityManager $em) use($id, $repo) {
         $oneRecord = $repo->find($id);
         if ($oneRecord != null) {
             $em->remove($oneRecord);
         } else {
             throw new \Exception("Could not find matching record to delete");
         }
     });
 }
開發者ID:rmukras,項目名稱:coffee,代碼行數:12,代碼來源:Repository.php

示例3: _save

 /**
  * @param Doctrine\ORM\EntityManager $entityManager
  */
 private function _save(EntityManager $entityManager)
 {
     $entityManager->transactional(function ($em) {
         foreach ($this->queue as $entity) {
             $entityManager->persist($entity);
         }
     });
 }
開發者ID:rhapsody-project,項目名稱:setup-bundle,代碼行數:11,代碼來源:DoctrineDatabasePopulator.php

示例4: transferMoneyBackToUser

 /**
  * вернуть деньги с баланса кампании на счёт юзера
  *
  * @param Campaign $campaign
  */
 public function transferMoneyBackToUser(Campaign $campaign)
 {
     $this->em->transactional(function (EntityManager $em) use($campaign) {
         $em->getRepository('VifeedUserBundle:User')->updateBalance($campaign->getUser(), $campaign->getBalance());
         $campaign->setBalance(0);
         $em->persist($campaign);
     });
 }
開發者ID:bzis,項目名稱:zomba,代碼行數:13,代碼來源:CampaignManager.php

示例5: getAgencies

 /**
  * You may use an arbitrary SQL statement to receive Agency objects.
  * Your statement should at least return the id of the agencies.
  *
  * @param string $sql
  * @throws MissingAttributesDataBackendIOException
  * @throws DataBackendIOException
  * @throws DataBackendException
  * @return Agency[]
  */
 public function getAgencies($sql)
 {
     $agencies = array();
     $backend = $this;
     $em = $this->em;
     $this->em->transactional(function () use(&$agencies, $sql, $backend, $em) {
         $stmt = $em->getConnection()->executeQuery($sql);
         foreach ($stmt as $result) {
             if (!array_key_exists('id', $result)) {
                 throw new MissingAttributesDataBackendIOException();
             }
             $id = $result["id"];
             $agency = $em->find("malkusch\\bav\\Agency", $id);
             $agencies[] = $agency;
             $agency->getBank()->setDataBackend($backend);
         }
     });
     return $agencies;
 }
開發者ID:bmdevel,項目名稱:bav,代碼行數:29,代碼來源:DoctrineDataBackend.php

示例6: getAndClickLinkById

 /**
  *
  * @param int $id
  * @todo метод незащищен от CSRF атаки
  */
 public function getAndClickLinkById($id)
 {
     $user = $this->user->getUserObject();
     $bizAction = $this->em->getRepository('AppBundle:BizAction')->findActiveAction($id);
     $url = $bizAction->getUrl();
     $this->em->transactional(function ($em) use($user, $bizAction) {
         $f = $em->getRepository('AppBundle:UserClientActionsClicks')->findOneBy(['action' => $bizAction, 'user' => $user]);
         if (is_null($f)) {
             $f = new UserClientActionsClicks();
             $f->setUser($user);
             $f->setAction($bizAction);
             $f->setClickPrice($bizAction->getBonusClick());
             $f->clickPriceActual = true;
         } else {
             $f->incTotalCount();
         }
         $em->persist($f);
     });
     return $url;
 }
開發者ID:nxnx,項目名稱:donatservice,代碼行數:25,代碼來源:Donator.php

示例7: createFile

 /**
  * @see BackendAdapter::createFile
  */
 public function createFile(File $file, Folder $folder)
 {
     $self = $this;
     return $this->em->transactional(function (EntityManager $em) use($self, $file, $folder) {
         $fileEntityName = $self->getFileEntityName();
         $entity = new $fileEntityName();
         $entity->setFolder($self->getFolderReference($folder->getId()));
         $entity->setName($file->getName());
         $entity->setProfile($file->getProfile());
         $entity->setDateCreated($file->getDateCreated());
         $entity->setStatus($file->getStatus());
         $entity->setUuid($file->getUuid());
         $entity->setData($file->getData()->toArray());
         $resource = $file->getResource();
         if ($resource) {
             $entity->setResource($em->getReference($self->getResourceEntityName(), $resource->getId()));
         }
         $em->persist($entity);
         $em->flush($entity);
         $file->setId($entity->getId());
         $file->setFolderId($entity->getFolder()->getId());
         return $file;
     });
 }
開發者ID:kankje,項目名稱:xi-filelib,代碼行數:27,代碼來源:DoctrineOrmBackendAdapter.php

示例8: move

 /**
  * Move the node to the new position and change level by {$levelDiff}
  * @param Node\DoctrineNode $node
  * @param int $pos
  * @param int $levelDiff
  */
 public function move(Node\NodeInterface $node, $pos, $levelDiff, $undoMove = false)
 {
     if (!$this->locked) {
         //\Log::info('Should lock before changes');
     }
     $tableName = $this->tableName;
     $arrayHelper = $this->arrayHelper;
     $self = $this;
     // Calculate the old position to rollback to in case of some issue
     $oldPosition = $node->getLeftValue();
     if ($pos < $oldPosition) {
         $oldPosition = $node->getRightValue() + 1;
     }
     if (!$node instanceof Node\DoctrineNode) {
         throw new Exception\WrongInstance($node, 'Node\\DoctrineNode');
     }
     // Transactional because need to rollback in case of trigger failure
     $this->entityManager->transactional(function (EntityManager $entityManager) use($node, $pos, $levelDiff, $tableName, $arrayHelper, $self) {
         $left = $node->getLeftValue();
         $right = $node->getRightValue();
         $spaceUsed = $right - $left + 1;
         $moveA = null;
         $moveB = null;
         $a = null;
         $b = null;
         $min = null;
         $max = null;
         if ($pos > $left) {
             $a = $right + 1;
             $b = $pos - 1;
             $moveA = $pos - $left - $spaceUsed;
             $moveB = -$spaceUsed;
             $min = $left;
             $max = $pos - 1;
         } else {
             $a = $pos;
             $b = $left - 1;
             $moveA = $pos - $left;
             $moveB = $spaceUsed;
             $min = $pos;
             $max = $right;
         }
         //			// NB! It's important to set "level" before "left" for MySQL!
         //			$dql = "UPDATE {$className} e
         //					SET e.level = e.level + IF(e.left BETWEEN {$left} AND {$right}, {$levelDiff}, 0),
         //						e.left = e.left + IF(e.left BETWEEN {$left} AND {$right}, {$moveA}, IF(e.left BETWEEN {$a} AND {$b}, {$moveB}, 0)),
         //						e.right = e.right + IF(e.right BETWEEN {$left} AND {$right}, {$moveA}, IF(e.right BETWEEN {$a} AND {$b}, {$moveB}, 0))
         //					WHERE (e.left BETWEEN {$min} AND {$max}
         //						OR e.right BETWEEN {$min} AND {$max})";
         //
         //			$dql .= $self->getAdditionalCondition('AND');
         //
         //			$query = $entityManager->createQuery($dql);
         //			$query->execute();
         $sql = "UPDATE {$tableName}\n\t\t\t\t\tSET lvl = lvl + IF(lft BETWEEN {$left} AND {$right}, {$levelDiff}, 0),\n\t\t\t\t\t\tlft = lft + IF(lft BETWEEN {$left} AND {$right}, {$moveA}, IF(lft BETWEEN {$a} AND {$b}, {$moveB}, 0)),\n\t\t\t\t\t\trgt = rgt + IF(rgt BETWEEN {$left} AND {$right}, {$moveA}, IF(rgt BETWEEN {$a} AND {$b}, {$moveB}, 0))\n\t\t\t\t\tWHERE (lft BETWEEN {$min} AND {$max}\n\t\t\t\t\t\tOR rgt BETWEEN {$min} AND {$max})";
         $sql .= $self->getAdditionalConditionSql('AND');
         $entityManager->getConnection()->exec($sql);
         // Change node parameters locally as well
         // TODO: how to rollback these changes if nested set post move trigger fails?
         $arrayHelper->move($node, $pos, $levelDiff);
     });
     // Trigger post move event. Only after transaction is commited because
     // public schema must update it's stuff as well
     try {
         $masterNode = $node->getMasterNode();
         $eventArgs = new Event\NestedSetEventArgs($masterNode, $this->entityManager);
         $this->entityManager->getEventManager()->dispatchEvent(Event\NestedSetEvents::nestedSetPostMove, $eventArgs);
     } catch (\Exception $e) {
         //TODO: new pages should be removed
         // Should not happen
         if ($undoMove) {
             throw $e;
         }
         // Undo move
         $this->move($node, $oldPosition, -$levelDiff, true);
         throw $e;
     }
 }
開發者ID:sitesupra,項目名稱:sitesupra,代碼行數:84,代碼來源:DoctrineRepository.php

示例9: executeAtomically

 public function executeAtomically(callable $operation)
 {
     return $this->entity_manager->transactional($operation);
 }
開發者ID:loobee,項目名稱:ddd,代碼行數:4,代碼來源:DoctrineSession.php

示例10: transactional

 /**
  * {@inheritDoc}
  *
  * @static 
  */
 public static function transactional($func)
 {
     return \Doctrine\ORM\EntityManager::transactional($func);
 }
開發者ID:kodorider,項目名稱:renta,代碼行數:9,代碼來源:_ide_helper.php

示例11: transactional

 /**
  * {@inheritdoc}
  */
 public function transactional($func)
 {
     return $this->wrapped->transactional($func);
 }
開發者ID:lstrojny,項目名稱:doctrine-fun,代碼行數:7,代碼來源:EntityManagerDecorator.php

示例12: transactional

 /**
  * Transactional Doctrine wrapper.
  *
  * Instead of the EntityManager, this inserts this Mapper into the
  * function.
  *
  * @param Closure $func
  */
 public function transactional(\Closure $func)
 {
     return $this->em->transactional(function ($em) use($func) {
         return $func($this);
     });
 }
開發者ID:Mesoptier,項目名稱:gewisweb,代碼行數:14,代碼來源:Exam.php


注:本文中的Doctrine\ORM\EntityManager::transactional方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。