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
84eaea70
Commit
84eaea70
authored
Jun 05, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
5bb1dbb8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
49 deletions
+61
-49
Export.php
lib/Doctrine/Export.php
+2
-48
Table.php
lib/Doctrine/Table.php
+59
-1
No files found.
lib/Doctrine/Export.php
View file @
84eaea70
...
...
@@ -820,55 +820,9 @@ class Doctrine_Export extends Doctrine_Connection_Module
}
try
{
$columns
=
array
();
$primary
=
array
();
foreach
(
$table
->
getColumns
()
as
$name
=>
$column
)
{
$definition
=
$column
[
2
];
$definition
[
'type'
]
=
$column
[
0
];
$definition
[
'length'
]
=
$column
[
1
];
switch
(
$definition
[
'type'
])
{
case
'enum'
:
if
(
isset
(
$definition
[
'default'
]))
{
$definition
[
'default'
]
=
$table
->
enumIndex
(
$name
,
$definition
[
'default'
]);
}
break
;
case
'boolean'
:
if
(
isset
(
$definition
[
'default'
]))
{
$definition
[
'default'
]
=
$table
->
getConnection
()
->
convertBooleans
(
$definition
[
'default'
]);
}
break
;
}
$columns
[
$name
]
=
$definition
;
if
(
isset
(
$definition
[
'primary'
])
&&
$definition
[
'primary'
])
{
$primary
[]
=
$name
;
}
}
if
(
$table
->
getAttribute
(
Doctrine
::
ATTR_EXPORT
)
&
Doctrine
::
EXPORT_CONSTRAINTS
)
{
foreach
(
$table
->
getRelations
()
as
$name
=>
$relation
)
{
$fk
=
$relation
->
toArray
();
$fk
[
'foreignTable'
]
=
$relation
->
getTable
()
->
getTableName
();
if
(
$relation
->
getTable
()
===
$this
&&
in_array
(
$relation
->
getLocal
(),
$primary
))
{
continue
;
}
if
(
$relation
->
hasConstraint
())
{
$options
[
'foreignKeys'
][]
=
$fk
;
}
elseif
(
$relation
instanceof
Doctrine_Relation_LocalKey
)
{
$options
[
'foreignKeys'
][]
=
$fk
;
}
}
}
$options
[
'primary'
]
=
$primary
;
$data
=
$table
->
getExportableFormat
();
$this
->
conn
->
export
->
createTable
(
$
table
->
getOption
(
'tableName'
),
$columns
,
array_merge
(
$table
->
getOptions
(),
$options
)
);
$this
->
conn
->
export
->
createTable
(
$
data
[
0
],
$data
[
1
],
$data
[
2
]
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// we only want to silence table already exists errors
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
...
...
lib/Doctrine/Table.php
View file @
84eaea70
...
...
@@ -310,6 +310,64 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{
$this
->
conn
->
export
->
exportTable
(
$this
);
}
/**
* getExportableFormat
* returns exportable presentation of this object
*
* @return array
*/
public
function
getExportableFormat
()
{
$columns
=
array
();
$primary
=
array
();
foreach
(
$this
->
getColumns
()
as
$name
=>
$column
)
{
$definition
=
$column
[
2
];
$definition
[
'type'
]
=
$column
[
0
];
$definition
[
'length'
]
=
$column
[
1
];
switch
(
$definition
[
'type'
])
{
case
'enum'
:
if
(
isset
(
$definition
[
'default'
]))
{
$definition
[
'default'
]
=
$this
->
enumIndex
(
$name
,
$definition
[
'default'
]);
}
break
;
case
'boolean'
:
if
(
isset
(
$definition
[
'default'
]))
{
$definition
[
'default'
]
=
$this
->
getConnection
()
->
convertBooleans
(
$definition
[
'default'
]);
}
break
;
}
$columns
[
$name
]
=
$definition
;
if
(
isset
(
$definition
[
'primary'
])
&&
$definition
[
'primary'
])
{
$primary
[]
=
$name
;
}
}
if
(
$this
->
getAttribute
(
Doctrine
::
ATTR_EXPORT
)
&
Doctrine
::
EXPORT_CONSTRAINTS
)
{
foreach
(
$this
->
getRelations
()
as
$name
=>
$relation
)
{
$fk
=
$relation
->
toArray
();
$fk
[
'foreignTable'
]
=
$relation
->
getTable
()
->
getTableName
();
if
(
$relation
->
getTable
()
===
$this
&&
in_array
(
$relation
->
getLocal
(),
$primary
))
{
continue
;
}
if
(
$relation
->
hasConstraint
())
{
$options
[
'foreignKeys'
][]
=
$fk
;
}
elseif
(
$relation
instanceof
Doctrine_Relation_LocalKey
)
{
$options
[
'foreignKeys'
][]
=
$fk
;
}
}
}
$options
[
'primary'
]
=
$primary
;
return
array
(
$this
->
getOption
(
'tableName'
),
$columns
,
array_merge
(
$this
->
getOptions
(),
$options
));
}
/**
* exportConstraints
* exports the constraints of this table into database based on option definitions
...
...
@@ -372,7 +430,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public
function
getOptions
()
{
return
$this
->
options
;
return
$this
->
options
;
}
/**
* addForeignKey
...
...
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