本文整理匯總了PHP中Doctrine\ORM\EntityManagerInterface::transactional方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManagerInterface::transactional方法的具體用法?PHP EntityManagerInterface::transactional怎麽用?PHP EntityManagerInterface::transactional使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::transactional方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: tryDelete
/**
* @param Category $category
* @throws \Exception
*/
public function tryDelete(Category $category)
{
$this->tryValidate($category);
$this->em->transactional(function () use($category) {
$this->em->remove($category);
});
}
示例2: tryDelete
/**
* @param Article $article
* @throws \Exception
*/
public function tryDelete(Article $article)
{
$this->tryValidate($article);
$this->em->transactional(function () use($article) {
// TODO 畫像の削除処理必要
$this->em->remove($article);
});
}
示例3: execute
/** @inheritDoc */
public function execute(array $fixtures, $append = false)
{
$executor = $this;
$this->em->transactional(function (EntityManagerInterface $em) use($executor, $fixtures, $append) {
if ($append === false) {
$executor->purge();
}
foreach ($fixtures as $fixture) {
$executor->load($em, $fixture);
}
});
}
示例4: importFromCallback
/**
* Uses the provided callback to import entities.
*
* @param callable $callback
*/
protected function importFromCallback($callback)
{
$import = function (ObjectManager $objectManager) use($callback) {
$decorator = new DetachingObjectManagerDecorator($objectManager);
call_user_func($callback, $decorator);
// Flush manually to ensure that persisted entities are detached.
$decorator->flush();
};
$this->entityManager->transactional($import);
}
示例5: tryImportAndGetResultCount
/**
* インポートを試み、エラーの場合は適切なExceptionをthrowする
* @param DnsUserImportDto $dto
* @throws InvalidArgumentException
* @throws FormValidationException
* @todo メソッドが肥大化してきたので分割したい
*/
public function tryImportAndGetResultCount(DnsUserImportDto $dto)
{
if (is_null($dto)) {
throw \InvalidArgumentException('DtoオブジェクトがNullです。');
}
$filePath = $dto->getImportFile()->getRealPath();
if (!file_exists($filePath)) {
throw \InvalidArgumentException('インポートファイルが見つかりません。');
}
// 登録されているusernameデータを取得
$userNames = $this->em->getRepository(DnsUser::class)->findUserNameAll();
$file = new \SplFileObject($filePath);
$file->setFlags(\SplFileObject::READ_CSV);
$updateCount = 0;
$this->em->transactional(function () use($file, $dto, $userNames, &$updateCount) {
$idx = 0;
$updateCount = 0;
foreach ($file as $row) {
$idx++;
// ヘッダ行を無視するオプションを選択かつヘッダ行の場合スキップ
if ($dto->getIsIgnoreHeaderLine() === DnsUserImportDto::IS_IGNORE_HEADER_YES && $idx === 1) {
continue;
}
// 列數が想定通りでない場合スキップ
if (count($row) !== DnsUserImportDto::FILE_COLUMN_COUNT) {
continue;
}
list(, $userName, $password, $controlNo, $comment, $encryptType) = $row;
mb_convert_variables("UTF-8", "SJIS", $userName, $password, $controlNo, $comment, $encryptType);
if (in_array($userName, $userNames)) {
// 既存のデータは上書きしないオプション選択の場合スキップ
if ($dto->getIsUpdated() === DnsUserImportDto::IS_UPDATED_NO) {
continue;
}
$entity = $this->em->getRepository(DnsUser::class)->findOneByUserName($userName);
$passwordBackup = $entity->getPassword();
$entity->setPassword($password)->recoveryPasswordIfNull($passwordBackup);
} else {
$entity = (new DnsUser())->setUserName($userName)->setPassword($password);
}
$entity->setControlNo($controlNo)->setComment($comment)->setEncryptType(intval($encryptType));
$this->tryValidate($entity);
$this->em->persist($entity);
$updateCount++;
}
});
return $updateCount;
}
示例6: transactional
/**
* {@inheritdoc}
*/
public function transactional($func)
{
return $this->wrapped->transactional($func);
}