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
5bb1dbb8
Commit
5bb1dbb8
authored
Jun 05, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
00399c56
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
61 deletions
+80
-61
Export.php
lib/Doctrine/Export.php
+69
-1
Table.php
lib/Doctrine/Table.php
+11
-60
No files found.
lib/Doctrine/Export.php
View file @
5bb1dbb8
...
...
@@ -804,8 +804,76 @@ class Doctrine_Export extends Doctrine_Connection_Module
}
$conn
->
setAttribute
(
Doctrine
::
ATTR_CREATE_TABLES
,
$old
);
}
public
function
exportTable
()
/**
* exportTable
* exports given table into database based on column and option definitions
*
* @throws Doctrine_Connection_Exception if some error other than Doctrine::ERR_ALREADY_EXISTS
* occurred during the create table operation
* @return boolean whether or not the export operation was successful
* false if table already existed in the database
*/
public
function
exportTable
(
Doctrine_Table
$table
)
{
if
(
!
Doctrine
::
isValidClassname
(
$table
->
getOption
(
'declaringClass'
)
->
getName
()))
{
throw
new
Doctrine_Export_Exception
(
'Class name not valid.'
);
}
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
;
$this
->
conn
->
export
->
createTable
(
$table
->
getOption
(
'tableName'
),
$columns
,
array_merge
(
$table
->
getOptions
(),
$options
));
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// we only want to silence table already exists errors
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
throw
$e
;
}
}
}
}
lib/Doctrine/Table.php
View file @
5bb1dbb8
...
...
@@ -308,66 +308,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
public
function
export
()
{
if
(
!
Doctrine
::
isValidClassname
(
$this
->
options
[
'declaringClass'
]
->
getName
()))
{
throw
new
Doctrine_Table_Exception
(
'Class name not valid.'
);
}
try
{
$columns
=
array
();
$primary
=
array
();
foreach
(
$this
->
columns
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
->
conn
->
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
;
$this
->
conn
->
export
->
createTable
(
$this
->
options
[
'tableName'
],
$columns
,
array_merge
(
$this
->
options
,
$options
));
}
catch
(
Doctrine_Connection_Exception
$e
)
{
// we only want to silence table already exists errors
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
throw
$e
;
}
}
$this
->
conn
->
export
->
exportTable
(
$this
);
}
/**
* exportConstraints
...
...
@@ -423,6 +364,16 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
{
return
isset
(
$this
->
options
[
$option
]);
}
/**
* getOptions
* returns all options of this table and the associated values
*
* @return array all options and their values
*/
public
function
getOptions
()
{
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