Skip to content

Commit

Permalink
Fixed some anr creation issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanbaidan committed Mar 23, 2024
1 parent 41997df commit dbfec07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/Service/AnrInstanceRiskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,11 @@ public function createInstanceRisks(
$instanceRiskData = array_values($params['risks'])[$riskKey];
$instanceRisk->setContext($instanceRiskData['context'] ?? '');
if (!empty($instanceRiskData['riskOwner'])) {
/** @var Entity\Anr $anr */
$anr = $instance->getAnr();
$instanceRiskOwner = $this->instanceRiskOwnerService->getOrCreateInstanceRiskOwner(
$instance->getAnr(),
$anr,
$anr,
$instanceRiskData['riskOwner']
);
$instanceRisk->setInstanceRiskOwner($instanceRiskOwner);
Expand Down
14 changes: 11 additions & 3 deletions src/Service/AnrService.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ private function duplicateRolfRisks(
foreach ($sourceRolfRisks as $sourceRolfRisk) {
$newRolfRisk = (new Entity\RolfRisk())
->setAnr($newAnr)
->setCode($sourceRolfRisk->getCode)
->setCode($sourceRolfRisk->getCode())
->setLabels($sourceRolfRisk->getLabels())
->setDescriptions($sourceRolfRisk->getDescriptions())
->setCreator($this->connectedUser->getEmail());
Expand Down Expand Up @@ -1185,7 +1185,7 @@ private function duplicateObjectCategoryAndItsParents(
if ($sourceObjectCategory->getParent() !== null
&& !isset($objectCategoryOldIdsToNewObjects[$sourceObjectCategory->getParent()->getId()])
) {
$objectCategoryOldIdsToNewObjects = $this->duplicateObjectCategoryAndItsParents(
$objectCategoryOldIdsToNewObjects += $this->duplicateObjectCategoryAndItsParents(
$newAnr,
$sourceObjectCategory->getParent(),
$objectCategoryOldIdsToNewObjects
Expand All @@ -1195,7 +1195,9 @@ private function duplicateObjectCategoryAndItsParents(
$objectCategoryOldIdsToNewObjects[$sourceObjectCategory->getId()] = $this->anrObjectCategoryService->create(
$newAnr,
array_merge([
'parent' => $objectCategoryOldIdsToNewObjects[$sourceObjectCategory->getParent()->getId()] ?? null,
'parent' => $sourceObjectCategory->getParent() !== null
? $objectCategoryOldIdsToNewObjects[$sourceObjectCategory->getParent()->getId()]
: null,
'setOnlyExactPosition' => true,
'position' => $sourceObjectCategory->getPosition(),
], $sourceObjectCategory->getLabels()),
Expand Down Expand Up @@ -1426,7 +1428,10 @@ private function duplicateInstanceRisks(
if ($sourceInstanceRisk instanceof Entity\InstanceRisk
&& $sourceInstanceRisk->getInstanceRiskOwner() !== null
) {
/** @var Entity\Anr $sourceAnr */
$sourceAnr = $sourceInstance->getAnr();
$newInstanceRisk->setInstanceRiskOwner($this->instanceRiskOwnerService->getOrCreateInstanceRiskOwner(
$sourceAnr,
$newAnr,
$sourceInstanceRisk->getInstanceRiskOwner()->getName(),
));
Expand Down Expand Up @@ -1463,7 +1468,10 @@ private function duplicateOperationalInstanceRisks(
if ($sourceInstanceRiskOp instanceof Entity\InstanceRiskOp
&& $sourceInstanceRiskOp->getInstanceRiskOwner() !== null
) {
/** @var Entity\Anr $sourceAnr */
$sourceAnr = $sourceInstance->getAnr();
$instanceRiskOwner = $this->instanceRiskOwnerService->getOrCreateInstanceRiskOwner(
$sourceAnr,
$newAnr,
$sourceInstanceRiskOp->getInstanceRiskOwner()->getName(),
);
Expand Down
3 changes: 2 additions & 1 deletion src/Service/InstanceRiskOwnerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ public function create(Anr $anr, string $ownerName, bool $saveIdDb = false): Ins
}

public function getOrCreateInstanceRiskOwner(
Anr $sourceAnr,
Anr $anr,
string $ownerName
): InstanceRiskOwner {
if (!isset($this->cachedData['instanceRiskOwners'][$ownerName])) {
$instanceRiskOwner = $this->instanceRiskOwnerTable->findByAnrAndName($anr, $ownerName);
$instanceRiskOwner = $this->instanceRiskOwnerTable->findByAnrAndName($sourceAnr, $ownerName);
if ($instanceRiskOwner === null) {
$instanceRiskOwner = $this->create($anr, $ownerName);
}
Expand Down

0 comments on commit dbfec07

Please sign in to comment.