Skip to content

Commit 7a6646b

Browse files
author
Ruslan Baidan
committed
FIxed the threats' codes duplication issue during the import.
1 parent 30554de commit 7a6646b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Service/AssetImportService.php

+2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public function importFromArray($monarcVersion, array $data, Anr $anr): ?Asset
212212
$this->cachedData['threats'][$threat->getUuid()] = $threat;
213213
}
214214
}
215+
unset($threatsUuidsAndCodes, $threatsUuids, $threatsCodes);
215216

216217
/*
217218
* Vulnerabilities
@@ -243,6 +244,7 @@ public function importFromArray($monarcVersion, array $data, Anr $anr): ?Asset
243244
}
244245
}
245246
$this->vulnerabilityTable->getDb()->flush();
247+
unset($vulnerabilitiesUuidsAndCodes, $vulnerabilitiesUuids, $vulnerabilitiesCodes);
246248

247249
/*
248250
* AMVs

src/Service/InstanceImportService.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -622,13 +622,19 @@ private function importAnrFromArray(
622622
if (empty($this->cachedData['threats'])) {
623623
$this->cachedData['threats'] = $this->assetImportService->getCachedDataByKey('threats');
624624
}
625+
$threatsUuidsAndCodes = $this->threatTable->findUuidsAndCodesByAnr($anr);
626+
$threatsUuids = array_column($threatsUuidsAndCodes, 'uuid');
627+
$threatsCodes = array_column($threatsUuidsAndCodes, 'code');
625628
foreach ($data['method']['threats'] as $threatUuid => $threatData) {
626629
$threat = $this->cachedData['threats'][$threatUuid] ?? null;
627630
if ($threat === null) {
628-
try {
631+
if (\in_array((string)$threatData['uuid'], $threatsUuids, true)) {
629632
$threat = $this->threatTable->findByAnrAndUuid($anr, $threatUuid);
630-
} catch (EntityNotFoundException $e) {
633+
} else {
631634
$threatData = $data['method']['threats'][$threatUuid];
635+
if (\in_array($threatData['code'], $threatsCodes, true)) {
636+
$threatData['code'] .= '-' . time();
637+
}
632638
$threat = (new Threat())
633639
->setUuid($threatData['uuid'])
634640
->setAnr($anr)
@@ -678,6 +684,7 @@ private function importAnrFromArray(
678684

679685
$this->threatTable->saveEntity($threat);
680686
}
687+
unset($threatsUuidsAndCodes, $threatsUuids, $threatsCodes);
681688
}
682689
}
683690

0 commit comments

Comments
 (0)