From c16a6d25a01f05f033fc45856c71e9186b9aebc4 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Tue, 24 Sep 2019 18:34:43 +0200 Subject: [PATCH 1/3] TE-3824 added transaction to read of state and process from DB --- .../OrderStateMachine/PersistenceManager.php | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php b/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php index b904a754..ad06282f 100644 --- a/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php +++ b/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php @@ -11,11 +11,14 @@ use Orm\Zed\Oms\Persistence\SpyOmsOrderItemStateQuery; use Orm\Zed\Oms\Persistence\SpyOmsOrderProcess; use Orm\Zed\Oms\Persistence\SpyOmsOrderProcessQuery; +use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait; use Spryker\Zed\Oms\Business\Exception\ProcessNotActiveException; use Spryker\Zed\Oms\OmsConfig; class PersistenceManager implements PersistenceManagerInterface { + use TransactionTrait; + /** * @var \Spryker\Zed\Oms\OmsConfig */ @@ -36,15 +39,17 @@ public function __construct(OmsConfig $omsConfig) */ public function getStateEntity($stateName) { - $stateEntity = SpyOmsOrderItemStateQuery::create()->findOneByName($stateName); + return $this->getTransactionHandler()->handleTransaction(static function () use ($stateName): SpyOmsOrderItemState { + $stateEntity = SpyOmsOrderItemStateQuery::create()->findOneByName($stateName); - if ($stateEntity === null) { - $stateEntity = new SpyOmsOrderItemState(); - $stateEntity->setName($stateName); - $stateEntity->save(); - } + if ($stateEntity === null) { + $stateEntity = new SpyOmsOrderItemState(); + $stateEntity->setName($stateName); + $stateEntity->save(); + } - return $stateEntity; + return $stateEntity; + }); } /** @@ -63,15 +68,17 @@ public function getProcessEntity($processName) )); } - $processEntity = SpyOmsOrderProcessQuery::create()->findOneByName($processName); + return $this->getTransactionHandler()->handleTransaction(static function () use ($processName): SpyOmsOrderProcess { + $processEntity = SpyOmsOrderProcessQuery::create()->findOneByName($processName); - if ($processEntity === null) { - $processEntity = new SpyOmsOrderProcess(); - $processEntity->setName($processName); - $processEntity->save(); - } + if ($processEntity === null) { + $processEntity = new SpyOmsOrderProcess(); + $processEntity->setName($processName); + $processEntity->save(); + } - return $processEntity; + return $processEntity; + }); } /** From a892cead7d8ab83ea0b13cd0969c507e5adde8d2 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Wed, 25 Sep 2019 09:46:44 +0200 Subject: [PATCH 2/3] TE-3824 added transaction to read of state and process from DB --- .../OrderStateMachine/PersistenceManager.php | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php b/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php index ad06282f..e48127bf 100644 --- a/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php +++ b/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php @@ -39,14 +39,12 @@ public function __construct(OmsConfig $omsConfig) */ public function getStateEntity($stateName) { - return $this->getTransactionHandler()->handleTransaction(static function () use ($stateName): SpyOmsOrderItemState { - $stateEntity = SpyOmsOrderItemStateQuery::create()->findOneByName($stateName); + return $this->getTransactionHandler()->handleTransaction(function () use ($stateName): SpyOmsOrderItemState { + $stateEntity = SpyOmsOrderItemStateQuery::create() + ->filterByName($stateName) + ->findOneOrCreate(); - if ($stateEntity === null) { - $stateEntity = new SpyOmsOrderItemState(); - $stateEntity->setName($stateName); - $stateEntity->save(); - } + $stateEntity->save(); return $stateEntity; }); @@ -68,14 +66,12 @@ public function getProcessEntity($processName) )); } - return $this->getTransactionHandler()->handleTransaction(static function () use ($processName): SpyOmsOrderProcess { - $processEntity = SpyOmsOrderProcessQuery::create()->findOneByName($processName); + return $this->getTransactionHandler()->handleTransaction(function () use ($processName): SpyOmsOrderProcess { + $processEntity = SpyOmsOrderProcessQuery::create() + ->filterByName($processName) + ->findOneOrCreate(); - if ($processEntity === null) { - $processEntity = new SpyOmsOrderProcess(); - $processEntity->setName($processName); - $processEntity->save(); - } + $processEntity->save(); return $processEntity; }); From 82cf4475d7f955c09ee897e0f96bd9ae12f5abd3 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Fri, 4 Oct 2019 18:04:00 +0200 Subject: [PATCH 3/3] TE-3824 added transaction to read of state and process from DB --- .../Oms/Business/OrderStateMachine/PersistenceManager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php b/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php index e48127bf..dea76a64 100644 --- a/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php +++ b/src/Spryker/Zed/Oms/Business/OrderStateMachine/PersistenceManager.php @@ -44,7 +44,9 @@ public function getStateEntity($stateName) ->filterByName($stateName) ->findOneOrCreate(); - $stateEntity->save(); + if ($stateEntity->isNew()) { + $stateEntity->save(); + } return $stateEntity; }); @@ -71,7 +73,9 @@ public function getProcessEntity($processName) ->filterByName($processName) ->findOneOrCreate(); - $processEntity->save(); + if ($processEntity->isNew()) { + $processEntity->save(); + } return $processEntity; });