From dbfec075d1c0501b1e8905c86c9c863baa52a274 Mon Sep 17 00:00:00 2001 From: Ruslan Baidan Date: Sat, 23 Mar 2024 20:15:30 +0100 Subject: [PATCH] Fixed some anr creation issues. --- src/Service/AnrInstanceRiskService.php | 5 ++++- src/Service/AnrService.php | 14 +++++++++++--- src/Service/InstanceRiskOwnerService.php | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Service/AnrInstanceRiskService.php b/src/Service/AnrInstanceRiskService.php index 3a2cea17..f908924c 100644 --- a/src/Service/AnrInstanceRiskService.php +++ b/src/Service/AnrInstanceRiskService.php @@ -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); diff --git a/src/Service/AnrService.php b/src/Service/AnrService.php index bb8adc3a..75aab3ac 100755 --- a/src/Service/AnrService.php +++ b/src/Service/AnrService.php @@ -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()); @@ -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 @@ -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()), @@ -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(), )); @@ -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(), ); diff --git a/src/Service/InstanceRiskOwnerService.php b/src/Service/InstanceRiskOwnerService.php index c50b7bc7..025dd76e 100644 --- a/src/Service/InstanceRiskOwnerService.php +++ b/src/Service/InstanceRiskOwnerService.php @@ -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); }