SchemaValidationService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Service\Doctrine;
  4. use App\Entity\Access\Access;
  5. use App\Service\ApiLegacy\ApiLegacyRequestService;
  6. use App\Service\Rest\ApiRequestService;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Doctrine\ORM\Mapping\MappingException;
  9. /**
  10. * Validation du schéma Doctrine par comparaison aux entités en production sur la V1
  11. *
  12. * -- A supprimer lorsque la migration sera achevée --
  13. *
  14. */
  15. class SchemaValidationService
  16. {
  17. public function __construct(
  18. private EntityManagerInterface $entityManager, private readonly ApiRequestService $apiRequestService, private readonly ApiLegacyRequestService $apiLegacyRequestService,
  19. )
  20. {}
  21. public function validateSchema() {
  22. $schemaV1 = $this->getV1Schema();
  23. $schemaV2 = $this->getV2Schema();
  24. }
  25. /**
  26. * Retrieve the V2 schema
  27. *
  28. * @return array<string, array>
  29. * @throws MappingException
  30. */
  31. protected function getV2Schema(): array
  32. {
  33. $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
  34. $schema = [];
  35. foreach ($metadata as $entityMetadata) {
  36. $schema[$entityMetadata->getName()] = [];
  37. foreach ($entityMetadata->getFieldNames() as $field) {
  38. $schema[$entityMetadata->getName()][$field] = $entityMetadata->getTypeOfField($field);
  39. }
  40. foreach ($entityMetadata->getAssociationNames() as $association) {
  41. $schema[$entityMetadata->getName()][$association] = $entityMetadata->getAssociationMapping($association);
  42. }
  43. }
  44. return $schema;
  45. }
  46. /**
  47. * Retrieve the V1 schema
  48. * @return void
  49. */
  50. protected function getV1Schema() {
  51. $response = $this->apiLegacyRequestService->get('/_internal/doctrine/schema');
  52. $schema = json_decode($response->getContent(), true);
  53. dd($schema);
  54. return $schema;
  55. }
  56. /**
  57. * Get a list of differences between V1 and V2 doctrine schemas
  58. * @return void
  59. */
  60. protected function getDiff() {
  61. }
  62. }