Skip to content
Snippets Groups Projects
Commit 4203f1ef authored by Jonathan Foucher's avatar Jonathan Foucher
Browse files

Merge branch 'hotfix/666' into develop

parents 9942862d 9d3371eb
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ use App\Domain\AIPD\Model\ModeleScenarioMenace;
use App\Domain\AIPD\Repository;
use App\Domain\Registry\Repository\ConformiteTraitement\Question;
use App\Domain\User\Repository\Collectivity;
use App\Infrastructure\ORM\AIPD\Repository\ModeleMesureProtection;
use Doctrine\ORM\EntityManagerInterface;
use Gaufrette\Exception\FileNotFound;
use Gaufrette\FilesystemInterface;
......@@ -353,20 +354,34 @@ class ModeleAnalyseController extends CRUDController
public function importAction(Request $request)
{
$form = $this->createForm(ImportModeleType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$content = file_get_contents($form->getData()['file']->getPathname());
$serializer = SerializerBuilder::create()->build();
/** @var ModeleAnalyse $object */
$object = $serializer->deserialize($content, ModeleAnalyse::class, 'xml');
$object->deserialize();
$sm = [];
foreach ($object->getScenarioMenaces() as $scenarioMenace) {
foreach ($scenarioMenace->getMesuresProtections() as $mesuresProtection) {
$mesuresProtection->setIdFromString($this->guidv4());
/** @var ModeleScenarioMenace $scenarioMenace */
$mesures = [];
foreach ($scenarioMenace->getMesuresProtections() as $mesureProtection) {
// Check if this mesure already exists
$mm = $this->entityManager->find(\App\Domain\AIPD\Model\ModeleMesureProtection::class, $mesureProtection->getId());
if ($mm) {
$mesures[] = $mm;
} else {
// If not, save it now
$this->entityManager->persist($mesureProtection);
$mesures[] = $mesureProtection;
}
}
$scenarioMenace->setMesuresProtections($mesures);
$sm[] = $scenarioMenace;
}
$object->setScenarioMenaces($sm);
$object->setCreatedAt(new \DateTimeImmutable());
$object->setNom('(import) ' . $object->getNom());
$this->entityManager->persist($object);
$this->entityManager->flush();
......@@ -393,21 +408,6 @@ class ModeleAnalyseController extends CRUDController
return strtr($string, $unwanted_array);
}
public function guidv4($data = null)
{
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
$data = $data ?? random_bytes(16);
assert(16 == strlen($data));
// Set version to 0100
$data[6] = chr(ord($data[6]) & 0x0F | 0x40);
// Set bits 6-7 to 10
$data[8] = chr(ord($data[8]) & 0x3F | 0x80);
// Output the 36 character UUID.
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
private function ScenarioMenacesToDelete($object, $modeleAnalyseId)
{
$ScenarioMenacesToDelete = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment