|
|
@@ -0,0 +1,77 @@
|
|
|
+<?php
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+namespace App\Service\Doctrine;
|
|
|
+
|
|
|
+use App\Entity\Access\Access;
|
|
|
+use App\Service\ApiLegacy\ApiLegacyRequestService;
|
|
|
+use App\Service\Rest\ApiRequestService;
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
+use Doctrine\ORM\Mapping\MappingException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Validation du schéma Doctrine par comparaison aux entités en production sur la V1
|
|
|
+ *
|
|
|
+ * -- A supprimer lorsque la migration sera achevée --
|
|
|
+ *
|
|
|
+ */
|
|
|
+class SchemaValidationService
|
|
|
+{
|
|
|
+ public function __construct(
|
|
|
+ private EntityManagerInterface $entityManager, private readonly ApiRequestService $apiRequestService, private readonly ApiLegacyRequestService $apiLegacyRequestService,
|
|
|
+ )
|
|
|
+ {}
|
|
|
+
|
|
|
+ public function validateSchema() {
|
|
|
+ $schemaV1 = $this->getV1Schema();
|
|
|
+ $schemaV2 = $this->getV2Schema();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieve the V2 schema
|
|
|
+ *
|
|
|
+ * @return array<string, array>
|
|
|
+ * @throws MappingException
|
|
|
+ */
|
|
|
+ protected function getV2Schema(): array
|
|
|
+ {
|
|
|
+ $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
|
|
|
+ $schema = [];
|
|
|
+
|
|
|
+ foreach ($metadata as $entityMetadata) {
|
|
|
+ $schema[$entityMetadata->getName()] = [];
|
|
|
+
|
|
|
+ foreach ($entityMetadata->getFieldNames() as $field) {
|
|
|
+ $schema[$entityMetadata->getName()][$field] = $entityMetadata->getTypeOfField($field);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($entityMetadata->getAssociationNames() as $association) {
|
|
|
+ $schema[$entityMetadata->getName()][$association] = $entityMetadata->getAssociationMapping($association);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $schema;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retrieve the V1 schema
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ protected function getV1Schema() {
|
|
|
+ $response = $this->apiLegacyRequestService->get('/_internal/doctrine/schema');
|
|
|
+
|
|
|
+ $schema = json_decode($response->getContent(), true);
|
|
|
+
|
|
|
+ dd($schema);
|
|
|
+
|
|
|
+ return $schema;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get a list of differences between V1 and V2 doctrine schemas
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ protected function getDiff() {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|