本文整理匯總了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();
}
示例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");
}
});
}
示例3: _save
/**
* @param Doctrine\ORM\EntityManager $entityManager
*/
private function _save(EntityManager $entityManager)
{
$entityManager->transactional(function ($em) {
foreach ($this->queue as $entity) {
$entityManager->persist($entity);
}
});
}
示例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);
});
}
示例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;
}
示例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;
}
示例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;
});
}
示例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;
}
}
示例9: executeAtomically
public function executeAtomically(callable $operation)
{
return $this->entity_manager->transactional($operation);
}
示例10: transactional
/**
* {@inheritDoc}
*
* @static
*/
public static function transactional($func)
{
return \Doctrine\ORM\EntityManager::transactional($func);
}
示例11: transactional
/**
* {@inheritdoc}
*/
public function transactional($func)
{
return $this->wrapped->transactional($func);
}
示例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);
});
}