Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
2a663bee
Commit
2a663bee
authored
Nov 11, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-64] Fixing issue with converting D1 schema clob to D2
parent
d047f0e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
17 deletions
+34
-17
ConvertDoctrine1Schema.php
lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php
+31
-16
ConvertDoctrine1SchemaTest.php
...s/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php
+2
-1
schema.yml
tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml
+1
-0
No files found.
lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php
View file @
2a663bee
...
...
@@ -21,7 +21,8 @@
namespace
Doctrine\ORM\Tools
;
use
Doctrine\ORM\Mapping\ClassMetadataInfo
,
use
Doctrine\Common\DoctrineException
,
Doctrine\ORM\Mapping\ClassMetadataInfo
,
Doctrine\ORM\Tools\Export\Driver\AbstractExporter
,
Doctrine\Common\Util\Inflector
;
...
...
@@ -45,6 +46,11 @@ if ( ! class_exists('sfYaml', false)) {
*/
class
ConvertDoctrine1Schema
{
private
$_legacyTypeMap
=
array
(
// TODO: This list may need to be updated
'clob'
=>
'text'
);
/**
* Constructor passes the directory or array of directories
* to convert the Doctrine 1 schema files from
...
...
@@ -78,26 +84,26 @@ class ConvertDoctrine1Schema
}
$metadatas
=
array
();
foreach
(
$schema
as
$
name
=>
$model
)
{
$metadatas
[]
=
$this
->
_convertToClassMetadataInfo
(
$
name
,
$model
);
foreach
(
$schema
as
$
className
=>
$mappingInformation
)
{
$metadatas
[]
=
$this
->
_convertToClassMetadataInfo
(
$
className
,
$mappingInformation
);
}
return
$metadatas
;
}
private
function
_convertToClassMetadataInfo
(
$
modelName
,
$model
)
private
function
_convertToClassMetadataInfo
(
$
className
,
$mappingInformation
)
{
$metadata
=
new
ClassMetadataInfo
(
$
model
Name
);
$metadata
=
new
ClassMetadataInfo
(
$
class
Name
);
$this
->
_convertTableName
(
$
modelName
,
$model
,
$metadata
);
$this
->
_convertColumns
(
$
modelName
,
$model
,
$metadata
);
$this
->
_convertIndexes
(
$
modelName
,
$model
,
$metadata
);
$this
->
_convertRelations
(
$
modelName
,
$model
,
$metadata
);
$this
->
_convertTableName
(
$
className
,
$mappingInformation
,
$metadata
);
$this
->
_convertColumns
(
$
className
,
$mappingInformation
,
$metadata
);
$this
->
_convertIndexes
(
$
className
,
$mappingInformation
,
$metadata
);
$this
->
_convertRelations
(
$
className
,
$mappingInformation
,
$metadata
);
return
$metadata
;
}
private
function
_convertTableName
(
$
model
Name
,
array
$model
,
ClassMetadataInfo
$metadata
)
private
function
_convertTableName
(
$
class
Name
,
array
$model
,
ClassMetadataInfo
$metadata
)
{
if
(
isset
(
$model
[
'tableName'
])
&&
$model
[
'tableName'
])
{
$e
=
explode
(
'.'
,
$model
[
'tableName'
]);
...
...
@@ -110,13 +116,13 @@ class ConvertDoctrine1Schema
}
}
private
function
_convertColumns
(
$
model
Name
,
array
$model
,
ClassMetadataInfo
$metadata
)
private
function
_convertColumns
(
$
class
Name
,
array
$model
,
ClassMetadataInfo
$metadata
)
{
$id
=
false
;
if
(
isset
(
$model
[
'columns'
])
&&
$model
[
'columns'
])
{
foreach
(
$model
[
'columns'
]
as
$name
=>
$column
)
{
$fieldMapping
=
$this
->
_convertColumn
(
$
model
Name
,
$name
,
$column
,
$metadata
);
$fieldMapping
=
$this
->
_convertColumn
(
$
class
Name
,
$name
,
$column
,
$metadata
);
if
(
isset
(
$fieldMapping
[
'id'
])
&&
$fieldMapping
[
'id'
])
{
$id
=
true
;
...
...
@@ -136,7 +142,7 @@ class ConvertDoctrine1Schema
}
}
private
function
_convertColumn
(
$
model
Name
,
$name
,
$column
,
ClassMetadataInfo
$metadata
)
private
function
_convertColumn
(
$
class
Name
,
$name
,
$column
,
ClassMetadataInfo
$metadata
)
{
if
(
is_string
(
$column
))
{
$string
=
$column
;
...
...
@@ -150,6 +156,15 @@ class ConvertDoctrine1Schema
if
(
!
isset
(
$column
[
'name'
]))
{
$column
[
'name'
]
=
$name
;
}
$column
[
'type'
]
=
strtolower
(
$column
[
'type'
]);
// check if legacy column type (1.x) needs to be mapped to a 2.0 one
if
(
isset
(
$this
->
_legacyTypeMap
[
$column
[
'type'
]]))
{
$column
[
'type'
]
=
$this
->
_legacyTypeMap
[
$column
[
'type'
]];
}
if
(
!
\Doctrine\DBAL\Types\Type
::
hasType
(
$column
[
'type'
]))
{
throw
DoctrineException
::
couldNotMapDoctrine1Type
(
$column
[
'type'
]);
}
$fieldMapping
=
array
();
if
(
isset
(
$column
[
'primary'
]))
{
$fieldMapping
[
'id'
]
=
true
;
...
...
@@ -187,7 +202,7 @@ class ConvertDoctrine1Schema
return
$fieldMapping
;
}
private
function
_convertIndexes
(
$
model
Name
,
array
$model
,
ClassMetadataInfo
$metadata
)
private
function
_convertIndexes
(
$
class
Name
,
array
$model
,
ClassMetadataInfo
$metadata
)
{
if
(
isset
(
$model
[
'indexes'
])
&&
$model
[
'indexes'
])
{
foreach
(
$model
[
'indexes'
]
as
$name
=>
$index
)
{
...
...
@@ -202,7 +217,7 @@ class ConvertDoctrine1Schema
}
}
private
function
_convertRelations
(
$
model
Name
,
array
$model
,
ClassMetadataInfo
$metadata
)
private
function
_convertRelations
(
$
class
Name
,
array
$model
,
ClassMetadataInfo
$metadata
)
{
if
(
isset
(
$model
[
'relations'
])
&&
$model
[
'relations'
])
{
foreach
(
$model
[
'relations'
]
as
$name
=>
$relation
)
{
...
...
@@ -219,7 +234,7 @@ class ConvertDoctrine1Schema
$relation
[
'foreign'
]
=
'id'
;
}
if
(
!
isset
(
$relation
[
'foreignAlias'
]))
{
$relation
[
'foreignAlias'
]
=
$
model
Name
;
$relation
[
'foreignAlias'
]
=
$
class
Name
;
}
if
(
isset
(
$relation
[
'refClass'
]))
{
...
...
tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php
View file @
2a663bee
...
...
@@ -57,7 +57,8 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
$this
->
assertEquals
(
'Profile'
,
$metadatas
[
'Profile'
]
->
name
);
$this
->
assertEquals
(
'User'
,
$metadatas
[
'User'
]
->
name
);
$this
->
assertEquals
(
4
,
count
(
$metadatas
[
'Profile'
]
->
fieldMappings
));
$this
->
assertEquals
(
3
,
count
(
$metadatas
[
'User'
]
->
fieldMappings
));
$this
->
assertEquals
(
4
,
count
(
$metadatas
[
'User'
]
->
fieldMappings
));
$this
->
assertEquals
(
'text'
,
$metadatas
[
'User'
]
->
fieldMappings
[
'clob'
][
'type'
]);
$this
->
assertEquals
(
'Profile'
,
$metadatas
[
'Profile'
]
->
associationMappings
[
'User'
]
->
sourceEntityName
);
$this
->
assertEquals
(
'User'
,
$metadatas
[
'Profile'
]
->
associationMappings
[
'User'
]
->
targetEntityName
);
...
...
tests/Doctrine/Tests/ORM/Tools/doctrine1schema/schema.yml
View file @
2a663bee
...
...
@@ -8,6 +8,7 @@ User:
unique
:
true
password
:
type
:
string(255)
clob
:
clob
indexes
:
username
:
fields
:
[
username
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment