Skip to content

Commit

Permalink
Merge pull request #46 from chihiro-adachi/doctrine-dbal
Browse files Browse the repository at this point in the history
Doctrine\DBAL
  • Loading branch information
kiy0taka authored Jun 26, 2023
2 parents 69b2eb0 + 6dc601b commit 60179f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Eccube\Service\PurchaseFlow\Processor;

use Doctrine\DBAL\LockMode;

use Eccube\Entity\ItemHolderInterface;
use Eccube\Entity\Order;
use Eccube\Entity\ProductStock;
Expand Down Expand Up @@ -83,7 +83,7 @@ private function eachProductOrderItems(ItemHolderInterface $itemHolder, callable
$productStock = $item->getProductClass()->getProductStock();
if ($productStock->getProductClassId() === null) {
// 在庫に対してロックを実行
$this->entityManager->lock($productStock, LockMode::PESSIMISTIC_WRITE);
$this->entityManager->pessimisticWriteLock($productStock);
$this->entityManager->refresh($productStock);
$productStock->setProductClassId($item->getProductClass()->getId());
}
Expand Down
13 changes: 7 additions & 6 deletions src/framework/Eccube/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Eccube\ORM;

use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException as DoctrineForeignKeyConstraintViolationException;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\ORM\Exception\ForeignKeyConstraintViolationException;
use Eccube\ORM\Exception\ORMException;
Expand Down Expand Up @@ -83,18 +84,18 @@ public function clear($entityName = null)
/**
* @throws ORMException
*/
public function lock($entity, $lockMode, $lockVersion = null)
public function pessimisticWriteLock($entity)
{
try {
$this->entityManager->lock($entity, $lockMode, $lockVersion);
$this->entityManager->lock($entity, LockMode::PESSIMISTIC_WRITE);
} catch (\Exception $e) {
throw new ORMException($e);
}
}

public function refresh($entity, ?int $lockMode = null)
public function refresh($entity)
{
$this->entityManager->refresh($entity, $lockMode);
$this->entityManager->refresh($entity);
}

/**
Expand Down Expand Up @@ -136,9 +137,9 @@ public function isRollbackOnly(): bool
return $this->entityManager->getConnection()->getNativeConnection()->isRollbackOnly();
}

public function find($className, $id, $lockMode = null, $lockVersion = null)
public function find($className, $id)
{
return $this->entityManager->find($className, $id, $lockMode, $lockVersion);
return $this->entityManager->find($className, $id);
}

public function isStateManaged($entity, $assume = null): bool
Expand Down

0 comments on commit 60179f7

Please sign in to comment.