Skip to content

Commit

Permalink
Merge pull request #6070 from spryker/bugfix/te-3824-add-transaction-…
Browse files Browse the repository at this point in the history
…stte-process-read

TE-3824 Added transaction and caching to the PersistenceManager::getStateEntity
  • Loading branch information
Spryker Release Bot authored Jan 25, 2021
2 parents 834c673 + 3c25e30 commit 740bd12
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -36,15 +39,17 @@ public function __construct(OmsConfig $omsConfig)
*/
protected function getStateEntity($stateName)
{
$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();
}
if ($stateEntity->isNew()) {
$stateEntity->save();
}

return $stateEntity;
return $stateEntity;
});
}

/**
Expand All @@ -63,15 +68,17 @@ public function getProcessEntity($processName)
));
}

$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();
}
if ($processEntity->isNew()) {
$processEntity->save();
}

return $processEntity;
return $processEntity;
});
}

/**
Expand Down

0 comments on commit 740bd12

Please sign in to comment.