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
6f7736ad
Commit
6f7736ad
authored
Sep 03, 2007
by
lsmith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- trying to fix
http://www.phpdoctrine.net/trac/changeset/2322/trunk/lib/Doctrine/Export.php
parent
9a5f3b8b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
33 deletions
+36
-33
Export.php
lib/Doctrine/Export.php
+36
-33
No files found.
lib/Doctrine/Export.php
View file @
6f7736ad
...
@@ -103,7 +103,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -103,7 +103,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
{
{
return
$this
->
conn
->
exec
(
$this
->
dropIndexSql
(
$table
,
$name
));
return
$this
->
conn
->
exec
(
$this
->
dropIndexSql
(
$table
,
$name
));
}
}
/**
/**
* dropIndexSql
* dropIndexSql
*
*
...
@@ -111,7 +111,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -111,7 +111,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
* @param string $name name of the index to be dropped
* @param string $name name of the index to be dropped
* @return string SQL that is used for dropping an index
* @return string SQL that is used for dropping an index
*/
*/
public
function
dropIndexSql
(
$table
,
$name
)
public
function
dropIndexSql
(
$table
,
$name
)
{
{
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
formatter
->
getIndexName
(
$name
));
$name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
formatter
->
getIndexName
(
$name
));
return
'DROP INDEX '
.
$name
;
return
'DROP INDEX '
.
$name
;
...
@@ -210,7 +210,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -210,7 +210,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
if
(
!
$name
)
{
if
(
!
$name
)
{
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
throw
new
Doctrine_Export_Exception
(
'no valid table name specified'
);
}
}
if
(
empty
(
$fields
))
{
if
(
empty
(
$fields
))
{
throw
new
Doctrine_Export_Exception
(
'no fields specified for table '
.
$name
);
throw
new
Doctrine_Export_Exception
(
'no fields specified for table '
.
$name
);
}
}
...
@@ -229,9 +229,9 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -229,9 +229,9 @@ class Doctrine_Export extends Doctrine_Connection_Module
}
}
$query
=
'CREATE TABLE '
.
$this
->
conn
->
quoteIdentifier
(
$name
,
true
)
.
' ('
.
$queryFields
;
$query
=
'CREATE TABLE '
.
$this
->
conn
->
quoteIdentifier
(
$name
,
true
)
.
' ('
.
$queryFields
;
$check
=
$this
->
getCheckDeclaration
(
$fields
);
$check
=
$this
->
getCheckDeclaration
(
$fields
);
if
(
!
empty
(
$check
))
{
if
(
!
empty
(
$check
))
{
$query
.=
', '
.
$check
;
$query
.=
', '
.
$check
;
}
}
...
@@ -249,7 +249,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -249,7 +249,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$sql
[]
=
$this
->
createForeignKeySql
(
$name
,
$definition
);
$sql
[]
=
$this
->
createForeignKeySql
(
$name
,
$definition
);
}
}
}
}
}
}
return
$sql
;
return
$sql
;
}
}
/**
/**
...
@@ -281,7 +281,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -281,7 +281,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
* 'comment' => 'Foo',
* 'comment' => 'Foo',
* 'charset' => 'utf8',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* 'collate' => 'utf8_unicode_ci',
* );
* );
* @return void
* @return void
*/
*/
public
function
createSequence
(
$seqName
,
$start
=
1
,
array
$options
=
array
())
public
function
createSequence
(
$seqName
,
$start
=
1
,
array
$options
=
array
())
...
@@ -631,7 +631,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -631,7 +631,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
* Text value with the default COLLATION for this field.
* Text value with the default COLLATION for this field.
* unique
* unique
* unique constraint
* unique constraint
* check
* check
* column check constraint
* column check constraint
*
*
* @return string DBMS specific SQL code portion that should be used to
* @return string DBMS specific SQL code portion that should be used to
...
@@ -652,7 +652,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -652,7 +652,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$unique
=
(
isset
(
$field
[
'unique'
])
&&
$field
[
'unique'
])
?
$unique
=
(
isset
(
$field
[
'unique'
])
&&
$field
[
'unique'
])
?
' '
.
$this
->
getUniqueFieldDeclaration
()
:
''
;
' '
.
$this
->
getUniqueFieldDeclaration
()
:
''
;
$check
=
(
isset
(
$field
[
'check'
])
&&
$field
[
'check'
])
?
$check
=
(
isset
(
$field
[
'check'
])
&&
$field
[
'check'
])
?
' '
.
$field
[
'check'
]
:
''
;
' '
.
$field
[
'check'
]
:
''
;
...
@@ -681,14 +681,14 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -681,14 +681,14 @@ class Doctrine_Export extends Doctrine_Connection_Module
$field
[
'default'
]
=
empty
(
$field
[
'notnull'
])
$field
[
'default'
]
=
empty
(
$field
[
'notnull'
])
?
null
:
$this
->
valid_default_values
[
$field
[
'type'
]];
?
null
:
$this
->
valid_default_values
[
$field
[
'type'
]];
if
(
$field
[
'default'
]
===
''
&&
if
(
$field
[
'default'
]
===
''
&&
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_PORTABILITY
)
&
Doctrine
::
PORTABILITY_EMPTY_TO_NULL
))
{
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_PORTABILITY
)
&
Doctrine
::
PORTABILITY_EMPTY_TO_NULL
))
{
$field
[
'default'
]
=
null
;
$field
[
'default'
]
=
null
;
}
}
}
}
if
(
$field
[
'type'
]
===
'boolean'
)
{
if
(
$field
[
'type'
]
===
'boolean'
)
{
$fields
[
'default'
]
=
$this
->
conn
->
convertBooleans
(
$field
[
'default'
]);
$fields
[
'default'
]
=
$this
->
conn
->
convertBooleans
(
$field
[
'default'
]);
}
}
$default
=
' DEFAULT '
.
$this
->
conn
->
quote
(
$field
[
'default'
],
$field
[
'type'
]);
$default
=
' DEFAULT '
.
$this
->
conn
->
quote
(
$field
[
'default'
],
$field
[
'type'
]);
}
}
...
@@ -721,7 +721,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -721,7 +721,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
return
implode
(
', '
,
$constraints
);
return
implode
(
', '
,
$constraints
);
}
}
/**
/**
* Obtain DBMS specific SQL code portion needed to set an index
* Obtain DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
* declaration to be used in statements like CREATE TABLE.
*
*
* @param string $name name of the index
* @param string $name name of the index
...
@@ -748,7 +748,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -748,7 +748,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$query
=
$type
.
'INDEX '
.
$name
;
$query
=
$type
.
'INDEX '
.
$name
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationList
(
$definition
[
'fields'
])
.
')'
;
$query
.=
' ('
.
$this
->
getIndexFieldDeclarationList
(
$definition
[
'fields'
])
.
')'
;
return
$query
;
return
$query
;
}
}
/**
/**
...
@@ -795,7 +795,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -795,7 +795,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
*
*
* @param array $definition an associative array with the following structure:
* @param array $definition an associative array with the following structure:
* name optional constraint name
* name optional constraint name
*
*
* local the local field(s)
* local the local field(s)
*
*
* foreign the foreign reference field(s)
* foreign the foreign reference field(s)
...
@@ -803,23 +803,23 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -803,23 +803,23 @@ class Doctrine_Export extends Doctrine_Connection_Module
* foreignTable the name of the foreign table
* foreignTable the name of the foreign table
*
*
* onDelete referential delete action
* onDelete referential delete action
*
*
* onUpdate referential update action
* onUpdate referential update action
*
*
* deferred deferred constraint checking
* deferred deferred constraint checking
*
*
* The onDelete and onUpdate keys accept the following values:
* The onDelete and onUpdate keys accept the following values:
*
*
* CASCADE: Delete or update the row from the parent table and automatically delete or
* CASCADE: Delete or update the row from the parent table and automatically delete or
* update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported.
* update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported.
* Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column
* Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column
* in the parent table or in the child table.
* in the parent table or in the child table.
*
*
* SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the
* SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the
* child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier
* child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier
* specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.
* specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.
*
*
* NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary
* NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary
* key value is not allowed to proceed if there is a related foreign key value in the referenced table.
* key value is not allowed to proceed if there is a related foreign key value in the referenced table.
*
*
* RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as
* RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as
...
@@ -918,7 +918,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -918,7 +918,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
.
') REFERENCES '
.
') REFERENCES '
.
$definition
[
'foreignTable'
]
.
'('
.
$definition
[
'foreignTable'
]
.
'('
.
implode
(
', '
,
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$definition
[
'foreign'
]))
.
')'
;
.
implode
(
', '
,
array_map
(
array
(
$this
->
conn
,
'quoteIdentifier'
),
$definition
[
'foreign'
]))
.
')'
;
return
$sql
;
return
$sql
;
}
}
/**
/**
...
@@ -955,12 +955,12 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -955,12 +955,12 @@ class Doctrine_Export extends Doctrine_Connection_Module
public
function
getCollationFieldDeclaration
(
$collation
)
public
function
getCollationFieldDeclaration
(
$collation
)
{
{
return
''
;
return
''
;
}
}
/**
/**
* exportSchema
* exportSchema
* method for exporting Doctrine_Record classes to a schema
* method for exporting Doctrine_Record classes to a schema
*
*
* if the directory parameter is given this method first iterates
* if the directory parameter is given this method first iterates
* recursively trhough the given directory in order to find any model classes
* recursively trhough the given directory in order to find any model classes
*
*
* Then it iterates through all declared classes and creates tables for the ones
* Then it iterates through all declared classes and creates tables for the ones
...
@@ -985,7 +985,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -985,7 +985,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
if
(
$e
->
getPortableCode
()
!==
Doctrine
::
ERR_ALREADY_EXISTS
)
{
$this
->
conn
->
rollback
();
$this
->
conn
->
rollback
();
throw
$e
;
throw
$e
;
}
}
}
}
}
}
$this
->
conn
->
commit
();
$this
->
conn
->
commit
();
...
@@ -1034,7 +1034,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -1034,7 +1034,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
$sql
=
array
();
$sql
=
array
();
$fks
=
array
();
$fks
=
array
();
// we iterate trhough the diff of previously declared classes
// we iterate trhough the diff of previously declared classes
// and currently declared classes
// and currently declared classes
foreach
(
$classes
as
$name
)
{
foreach
(
$classes
as
$name
)
{
$class
=
new
ReflectionClass
(
$name
);
$class
=
new
ReflectionClass
(
$name
);
...
@@ -1044,22 +1044,25 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -1044,22 +1044,25 @@ class Doctrine_Export extends Doctrine_Connection_Module
// class must have method setTableDefinition (to avoid non-Record subclasses like symfony's sfDoctrineRecord)
// class must have method setTableDefinition (to avoid non-Record subclasses like symfony's sfDoctrineRecord)
// we have to recursively iterate through the class parents just to be sure that the classes using for example
// we have to recursively iterate through the class parents just to be sure that the classes using for example
// column aggregation inheritance are properly exporterd to database
// column aggregation inheritance are properly exporterd to database
while
(
$class
->
isAbstract
()
&&
while
(
$class
->
isAbstract
()
||
!
$class
->
isSubclassOf
(
$parent
)
&&
!
$class
->
isSubclassOf
(
$parent
)
||
!
$class
->
hasMethod
(
'setTableDefinition'
)
&&
!
$class
->
hasMethod
(
'setTableDefinition'
)
||
$class
->
getMethod
(
'setTableDefinition'
)
->
getDeclaringClass
()
->
getName
()
!==
$class
->
getName
())
{
$class
->
getMethod
(
'setTableDefinition'
)
->
getDeclaringClass
()
->
getName
()
!==
$class
->
getName
())
{
$class
=
$class
->
getParent
();
$class
=
$class
->
getParentClass
();
if
(
$class
===
false
)
{
if
(
$class
===
null
)
{
break
;
break
;
}
}
}
}
if
(
$class
===
false
)
{
continue
;
}
$record
=
new
$name
();
$record
=
new
$name
();
$table
=
$record
->
getTable
();
$table
=
$record
->
getTable
();
$data
=
$table
->
getExportableFormat
();
$data
=
$table
->
getExportableFormat
();
$query
=
$this
->
conn
->
export
->
createTableSql
(
$data
[
'tableName'
],
$data
[
'columns'
],
$data
[
'options'
]);
$query
=
$this
->
conn
->
export
->
createTableSql
(
$data
[
'tableName'
],
$data
[
'columns'
],
$data
[
'options'
]);
if
(
is_array
(
$query
))
{
if
(
is_array
(
$query
))
{
...
@@ -1077,7 +1080,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -1077,7 +1080,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
* exportSql
* exportSql
* returns the sql for exporting Doctrine_Record classes to a schema
* returns the sql for exporting Doctrine_Record classes to a schema
*
*
* if the directory parameter is given this method first iterates
* if the directory parameter is given this method first iterates
* recursively trhough the given directory in order to find any model classes
* recursively trhough the given directory in order to find any model classes
*
*
* Then it iterates through all declared classes and creates tables for the ones
* Then it iterates through all declared classes and creates tables for the ones
...
@@ -1096,7 +1099,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
...
@@ -1096,7 +1099,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
foreach
((
array
)
$directory
as
$dir
)
{
foreach
((
array
)
$directory
as
$dir
)
{
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
$it
=
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$dir
),
RecursiveIteratorIterator
::
LEAVES_ONLY
);
RecursiveIteratorIterator
::
LEAVES_ONLY
);
foreach
(
$it
as
$file
)
{
foreach
(
$it
as
$file
)
{
$e
=
explode
(
'.'
,
$file
->
getFileName
());
$e
=
explode
(
'.'
,
$file
->
getFileName
());
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
if
(
end
(
$e
)
===
'php'
&&
strpos
(
$file
->
getFileName
(),
'.inc'
)
===
false
)
{
...
...
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