Commit fdd1954a authored by jwage's avatar jwage

[2.0][DDC-72] Fixes issue with converting D1 column aliases to D2 field names

parent fa404678
...@@ -150,13 +150,19 @@ class ConvertDoctrine1Schema ...@@ -150,13 +150,19 @@ class ConvertDoctrine1Schema
$column = array(); $column = array();
$column['type'] = $string; $column['type'] = $string;
} }
if ( ! isset($column['name'])) {
$column['name'] = $name;
}
// check if a column alias was used (column_name as field_name)
if (preg_match("/(\w+)\sas\s(\w+)/i", $column['name'], $matches)) {
$name = $matches[1];
$column['name'] = $name;
$column['alias'] = $matches[2];
}
if (preg_match("/([a-zA-Z]+)\(([0-9]+)\)/", $column['type'], $matches)) { if (preg_match("/([a-zA-Z]+)\(([0-9]+)\)/", $column['type'], $matches)) {
$column['type'] = $matches[1]; $column['type'] = $matches[1];
$column['length'] = $matches[2]; $column['length'] = $matches[2];
} }
if ( ! isset($column['name'])) {
$column['name'] = $name;
}
$column['type'] = strtolower($column['type']); $column['type'] = strtolower($column['type']);
// check if legacy column type (1.x) needs to be mapped to a 2.0 one // check if legacy column type (1.x) needs to be mapped to a 2.0 one
if (isset($this->_legacyTypeMap[$column['type']])) { if (isset($this->_legacyTypeMap[$column['type']])) {
......
...@@ -106,10 +106,14 @@ class YamlExporter extends AbstractExporter ...@@ -106,10 +106,14 @@ class YamlExporter extends AbstractExporter
unset($fieldMapping['length']); unset($fieldMapping['length']);
} }
unset($fieldMapping['fieldName']); $fieldMapping['column'] = $fieldMapping['columnName'];
unset(
$fieldMapping['columnName'],
$fieldMapping['fieldName']
);
if ($fieldMapping['columnName'] == $name) { if ($fieldMapping['column'] == $name) {
unset($fieldMapping['columnName']); unset($fieldMapping['column']);
} }
if (isset($fieldMapping['id']) && $fieldMapping['id']) { if (isset($fieldMapping['id']) && $fieldMapping['id']) {
......
...@@ -57,8 +57,10 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase ...@@ -57,8 +57,10 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('Profile', $metadatas['Profile']->name); $this->assertEquals('Profile', $metadatas['Profile']->name);
$this->assertEquals('User', $metadatas['User']->name); $this->assertEquals('User', $metadatas['User']->name);
$this->assertEquals(4, count($metadatas['Profile']->fieldMappings)); $this->assertEquals(4, count($metadatas['Profile']->fieldMappings));
$this->assertEquals(4, count($metadatas['User']->fieldMappings)); $this->assertEquals(5, count($metadatas['User']->fieldMappings));
$this->assertEquals('text', $metadatas['User']->fieldMappings['clob']['type']); $this->assertEquals('text', $metadatas['User']->fieldMappings['clob']['type']);
$this->assertEquals('test_alias', $metadatas['User']->fieldMappings['theAlias']['columnName']);
$this->assertEquals('theAlias', $metadatas['User']->fieldMappings['theAlias']['fieldName']);
$this->assertEquals('Profile', $metadatas['Profile']->associationMappings['User']->sourceEntityName); $this->assertEquals('Profile', $metadatas['Profile']->associationMappings['User']->sourceEntityName);
$this->assertEquals('User', $metadatas['Profile']->associationMappings['User']->targetEntityName); $this->assertEquals('User', $metadatas['Profile']->associationMappings['User']->targetEntityName);
......
...@@ -9,6 +9,8 @@ User: ...@@ -9,6 +9,8 @@ User:
password: password:
type: string(255) type: string(255)
clob: clob clob: clob
test_alias as theAlias:
type: string(255)
indexes: indexes:
username: username:
fields: [username] fields: [username]
......
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