|
@@ -40,12 +40,12 @@ class SchemaValidationService
|
|
|
* @throws ServerExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
|
* @throws TransportExceptionInterface
|
|
* @throws TransportExceptionInterface
|
|
|
*/
|
|
*/
|
|
|
- public function validateSchema(): array
|
|
|
|
|
|
|
+ public function validateSchema(?DiffTypeEnum $filter = null): array
|
|
|
{
|
|
{
|
|
|
$schemaV1 = $this->getV1Schema();
|
|
$schemaV1 = $this->getV1Schema();
|
|
|
$schemaV2 = $this->getV2Schema();
|
|
$schemaV2 = $this->getV2Schema();
|
|
|
|
|
|
|
|
- $diff = $this->getDiff($schemaV1, $schemaV2);
|
|
|
|
|
|
|
+ $diff = $this->getDiff($schemaV1, $schemaV2, $filter);
|
|
|
|
|
|
|
|
return $diff;
|
|
return $diff;
|
|
|
}
|
|
}
|
|
@@ -62,20 +62,27 @@ class SchemaValidationService
|
|
|
$schema = [];
|
|
$schema = [];
|
|
|
|
|
|
|
|
foreach ($metadata as $entityMetadata) {
|
|
foreach ($metadata as $entityMetadata) {
|
|
|
- $schema[$entityMetadata->getTableName()] = [];
|
|
|
|
|
|
|
+ $entityClassName = $this->extractClassName($entityMetadata->getName());
|
|
|
|
|
+
|
|
|
|
|
+ $schema[$entityClassName] = [];
|
|
|
|
|
|
|
|
foreach ($entityMetadata->getFieldNames() as $field) {
|
|
foreach ($entityMetadata->getFieldNames() as $field) {
|
|
|
- $schema[$entityMetadata->getTableName()][$field] = $entityMetadata->getTypeOfField($field);
|
|
|
|
|
|
|
+ $schema[$entityClassName][$field] = $entityMetadata->getTypeOfField($field);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
foreach ($entityMetadata->getAssociationNames() as $association) {
|
|
foreach ($entityMetadata->getAssociationNames() as $association) {
|
|
|
- $schema[$entityMetadata->getTableName()][$association] = $entityMetadata->getAssociationMapping($association);
|
|
|
|
|
|
|
+ $schema[$entityClassName][$association] = $entityMetadata->getAssociationMapping($association);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $schema;
|
|
return $schema;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ protected function extractClassName(string $entity): string {
|
|
|
|
|
+ $parts = explode('\\', $entity);
|
|
|
|
|
+ return array_pop($parts);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Retrieve the V1 schema
|
|
* Retrieve the V1 schema
|
|
|
*
|
|
*
|
|
@@ -98,7 +105,7 @@ class SchemaValidationService
|
|
|
* @param array<string, array<string| array<string|int>>> $schemaV2
|
|
* @param array<string, array<string| array<string|int>>> $schemaV2
|
|
|
* @return array<string, Difference | array<Difference>>
|
|
* @return array<string, Difference | array<Difference>>
|
|
|
*/
|
|
*/
|
|
|
- protected function getDiff(array $schemaV1, array $schemaV2): array {
|
|
|
|
|
|
|
+ protected function getDiff(array $schemaV1, array $schemaV2, ?DiffTypeEnum $filter = null): array {
|
|
|
$diff = [
|
|
$diff = [
|
|
|
];
|
|
];
|
|
|
|
|
|
|
@@ -106,7 +113,9 @@ class SchemaValidationService
|
|
|
|
|
|
|
|
if (!$this->isEntityInSchema($schemaV2, $entity)) {
|
|
if (!$this->isEntityInSchema($schemaV2, $entity)) {
|
|
|
// L'entité n'existe pas en V2
|
|
// L'entité n'existe pas en V2
|
|
|
- $diff[$entity] = new Difference(DiffTypeEnum::MISSING_ENTITY, "Entity `$entity` is missing in V2");
|
|
|
|
|
|
|
+ if (!$filter || $filter === DiffTypeEnum::MISSING_ENTITY) {
|
|
|
|
|
+ $diff[$entity] = new Difference(DiffTypeEnum::MISSING_ENTITY, "Entity `$entity` is missing in V2");
|
|
|
|
|
+ }
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -116,7 +125,11 @@ class SchemaValidationService
|
|
|
|
|
|
|
|
if (!$this->isPropertyInSchema($schemaV2, $entity, $field)) {
|
|
if (!$this->isPropertyInSchema($schemaV2, $entity, $field)) {
|
|
|
// Le champ n'existe pas en V2
|
|
// Le champ n'existe pas en V2
|
|
|
- $diff[$entity][$field] = new Difference(DiffTypeEnum::MISSING_PROPERTY, "Property `$field` is missing in V2");
|
|
|
|
|
|
|
+ if ($this->isRelationField($schemaV1, $entity, $field)) {
|
|
|
|
|
+ $diff[$entity][$field] = new Difference(DiffTypeEnum::MISSING_RELATION, "Relation " . $this->getRelationTypeLabel($fieldTypeV1) . " `$field` is missing in V2");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $diff[$entity][$field] = new Difference(DiffTypeEnum::MISSING_PROPERTY, "Property `$field` is missing in V2");
|
|
|
|
|
+ }
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -140,6 +153,14 @@ class SchemaValidationService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Si filter est non null, on ne conserve que les différences du type donné
|
|
|
|
|
+ if ($filter !== null) {
|
|
|
|
|
+ $diff[$entity] = array_filter(
|
|
|
|
|
+ $diff[$entity],
|
|
|
|
|
+ function (Difference $difference) use ($filter) { return $difference->getType() === $filter; }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $diff;
|
|
return $diff;
|