Commit d9969901 authored by Benjamin Eberlei's avatar Benjamin Eberlei

DDC-515 - Fixed some issues with Schema Validation Command

parent 57cd2e01
...@@ -66,13 +66,15 @@ EOT ...@@ -66,13 +66,15 @@ EOT
$exit = 0; $exit = 0;
if ($errors) { if ($errors) {
foreach ($errors AS $className => $errorMessages) { foreach ($errors AS $className => $errorMessages) {
$output->write("<error>[Mapping] FAIL - The entity-class '" . $className . "' mapping is invalid:</error>\n"); $output->write("<error>[Mapping] FAIL - The entity-class '" . $className . "' mapping is invalid:</error>\n");
foreach ($errorMessages AS $errorMessage) { foreach ($errorMessages AS $errorMessage) {
$output->write('* ' . $errorMessage . "\n"); $output->write('* ' . $errorMessage . "\n");
} }
$output->write("\n"); $output->write("\n");
} }
$exit += 1; $exit += 1;
} else {
$output->write('<info>[Mapping] OK - The mapping files are correct.</info>' . "\n");
} }
if (!$validator->schemaInSyncWithMetadata()) { if (!$validator->schemaInSyncWithMetadata()) {
......
...@@ -130,47 +130,53 @@ class SchemaValidator ...@@ -130,47 +130,53 @@ class SchemaValidator
} }
} }
if ($assoc instanceof ManyToManyMapping && $assoc->isOwningSide) { if ($assoc->isOwningSide) {
foreach ($assoc->joinTable['joinColumns'] AS $joinColumn) { if ($assoc instanceof ManyToManyMapping) {
if (!isset($class->fieldNames[$joinColumn['referencedColumnName']])) { foreach ($assoc->joinTable['joinColumns'] AS $joinColumn) {
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' does not " . if (!isset($class->fieldNames[$joinColumn['referencedColumnName']])) {
"have a corresponding field with this column name on the class '" . $class->name . "'."; $ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' does not " .
break; "have a corresponding field with this column name on the class '" . $class->name . "'.";
break;
}
$fieldName = $class->fieldNames[$joinColumn['referencedColumnName']];
if (!in_array($fieldName, $class->identifier)) {
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " .
"has to be a primary key column.";
}
} }
foreach ($assoc->joinTable['inverseJoinColumns'] AS $inverseJoinColumn) {
$fieldName = $class->fieldNames[$joinColumn['referencedColumnName']]; $targetClass = $cmf->getMetadataFor($assoc->targetEntityName);
if (!in_array($fieldName, $class->identifier)) { if (!isset($targetClass->fieldNames[$inverseJoinColumn['referencedColumnName']])) {
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " . $ce[] = "The inverse referenced column name '" . $inverseJoinColumn['referencedColumnName'] . "' does not " .
"has to be a primary key column."; "have a corresponding field with this column name on the class '" . $targetClass->name . "'.";
} break;
} }
foreach ($assoc->joinTable['inverseJoinColumns'] AS $inverseJoinColumn) {
if (!isset($class->fieldNames[$inverseJoinColumn['referencedColumnName']])) { $fieldName = $targetClass->fieldNames[$inverseJoinColumn['referencedColumnName']];
$ce[] = "The referenced column name '" . $inverseJoinColumn['referencedColumnName'] . "' does not " . if (!in_array($fieldName, $targetClass->identifier)) {
"have a corresponding field with this column name on the class '" . $class->name . "'."; $ce[] = "The referenced column name '" . $inverseJoinColumn['referencedColumnName'] . "' " .
break; "has to be a primary key column.";
} }
$fieldName = $class->fieldNames[$inverseJoinColumn['referencedColumnName']];
if (!in_array($fieldName, $class->identifier)) {
$ce[] = "The referenced column name '" . $inverseJoinColumn['referencedColumnName'] . "' " .
"has to be a primary key column.";
}
}
} else if ($assoc instanceof OneToOneMapping) {
foreach ($assoc->joinColumns AS $joinColumn) {
if (!isset($class->fieldNames[$joinColumn['referencedColumnName']])) {
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' does not " .
"have a corresponding field with this column name on the class '" . $class->name . "'.";
break;
} }
} else if ($assoc instanceof OneToOneMapping) {
$fieldName = $class->fieldNames[$joinColumn['referencedColumnName']]; foreach ($assoc->joinColumns AS $joinColumn) {
if (!in_array($fieldName, $class->identifier)) { $targetClass = $cmf->getMetadataFor($assoc->targetEntityName);
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " . if (!isset($targetClass->fieldNames[$joinColumn['referencedColumnName']])) {
"has to be a primary key column."; $ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' does not " .
"have a corresponding field with this column name on the class '" . $targetClass->name . "'.";
break;
}
$fieldName = $targetClass->fieldNames[$joinColumn['referencedColumnName']];
if (!in_array($fieldName, $targetClass->identifier)) {
$ce[] = "The referenced column name '" . $joinColumn['referencedColumnName'] . "' " .
"has to be a primary key column.";
}
} }
} }
} else {
} }
if ($ce) { if ($ce) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment